feat: cancel deployment by chronark · Pull Request #5274 · unkeyed/unkey
Database Schema & Models
pkg/db/schema.sql, pkg/db/models_generated.go, web/internal/db/src/schema/deployments.ts
Added invocation_id varchar column to deployments table and introduced DeploymentsStatusCancelled enum value alongside existing deployment statuses.
Generated SQL Queries pkg/db/deployment_find_by_id.sql_generated.go, pkg/db/deployment_find_by_k8s_name.sql_generated.go, pkg/db/deployment_list_by_environment_id_and_status.sql_generated.go, pkg/db/deployment_topology_list_by_versions.sql_generated.go, pkg/db/deployment_topology_list_desired.sql_generated.go
Updated SELECT statements and row scanning to include invocation_id column in all deployment query results; added InvocationID field population across multiple generated query handlers.
Deployment Update Generated Code pkg/db/queries/deployment_update_invocation_id.sql, pkg/db/deployment_update_invocation_id.sql_generated.go, pkg/db/querier_generated.go, pkg/db/BUILD.bazel
New SQL query and generated Go code to update deployments' invocation_id and updated_at fields; added UpdateDeploymentInvocationID method to Querier interface and generated implementation.
Restate Admin Client pkg/restate/admin/client.go
Added KillInvocation method to terminate Restate invocations; refactored invocation termination logic into shared terminateInvocation helper supporting both cancel and kill modes; broadened success conditions to accept any 2xx status.
Control Service Protocol svc/ctrl/proto/ctrl/v1/deployment.proto
Added DEPLOYMENT_STATUS_CANCELLED enum value, introduced CancelDeploymentRequest and CancelDeploymentResponse messages, and added CancelDeployment RPC to DeployService.
Deployment Service Core svc/ctrl/services/deployment/service.go, svc/ctrl/services/deployment/cancel_deployment.go, svc/ctrl/services/deployment/create_deployment.go, svc/ctrl/services/deployment/get_deployment.go
Added RestateAdmin client field to Service config and initialization; implemented new CancelDeployment handler with status validation and invocation termination; updated deployment creation to persist invocation IDs to database; extended status conversion to handle cancelled state.
Deployment Build Configuration svc/ctrl/services/deployment/BUILD.bazel, svc/ctrl/api/run.go
Added cancel_deployment.go source file and //pkg/restate/admin dependency; wired RestateAdmin client into deployment service configuration.
Worker Workflows svc/ctrl/worker/deploy/deploy_handler.go, svc/ctrl/worker/githubwebhook/handle_push.go
Inserted two 30-second delays in Deploy workflow; modified webhook handler to capture and persist deployment invocation IDs from Restate workflow responses.
Control API svc/api/routes/v2_deploy_get_deployment/handler.go, svc/api/openapi/..., svc/api/internal/testutil/mock_deployment_client.go
Added handling for DeploymentsStatusCancelled status in response mapping; added CANCELLED to OpenAPI deployment status enums; extended mock deployment client with CancelDeployment method and tracking fields.
Logging Utilities svc/frontline/services/router/BUILD.bazel, svc/frontline/services/router/service.go
Added //pkg/logger dependency and implemented error logging with environment context in sentinel lookup failures.
Frontend Cancel Dialog Component web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/components/table/components/actions/cancel-dialog.tsx
New React component rendering a confirmation dialog for deployment cancellation; integrates TRPC mutation, handles success/error states, and manages loading feedback via toast notifications.
Frontend Action Menu & Filters web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/components/table/components/actions/deployment-list-table-action.popover.constants.tsx, web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/filters.schema.ts
Added cancel action to deployment menu with conditional enablement based on deployment status; expanded DEPLOYMENT_STATUSES and GROUPED_DEPLOYMENT_STATUSES to include cancelled; updated filter color mapping and status expansion logic.
Frontend Status Display web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/components/table/components/deployment-status-badge.tsx, web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/components/deployment-status-badge.tsx
Added cancelled status badge configuration with Ban icon and gray styling to deployment status badge components; updated status type unions to include cancelled.
Frontend Deployment List & Details web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/components/table/deployments-list.tsx, web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/components/table/components/domain_list.tsx, web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/components/table/utils/get-row-class.ts
Refactored terminal state logic to treat cancelled and failed as equivalent for resource display suppression and placeholder rendering; unified styling for both terminal statuses.
Frontend Deployment Progress web/apps/dashboard/app/(app)/[workspaceSlug]/projects/[projectId]/(overview)/deployments/[deploymentId]/(deployment-progress)/deployment-progress.tsx
Introduced isCancelled flag to distinguish cancelled from failed deployments; updated step descriptions and final messaging to reflect cancellation context; refined error banner styling and text based on actual failure versus cancellation.
Frontend TRPC Mutation & Router web/apps/dashboard/lib/trpc/routers/deploy/deployment/cancel.ts, web/apps/dashboard/lib/trpc/routers/index.ts
New cancel mutation procedure validating deployment access, checking cancellable statuses, invoking control service gRPC, applying rate limiting, and returning status; exposed cancel endpoint in deployment router.
Frontend Schema web/apps/dashboard/lib/collections/deploy/deployments.ts
Extended Deployment schema to include cancelled status value in the status enum.