File
Blob: src/worker/dispatch/workflows/execution.ts
| 1 | import { UnixTimestampMs, type UnixTimestampMs as UnixTimestampMsType } from "@/contracts"; |
| 2 | import { type AcceptedRunSnapshot, type ExecuteRunWork } from "@/worker/contracts"; |
| 3 | import { type RunExecutionOutcome } from "@/worker/dispatch/shared/run-execution-context"; |
| 4 | import type { ProjectExecutionMaterial } from "@/worker/durable/project-do/types"; |
| 5 | import type { WorkflowRunTerminalStatus } from "./types"; |
| 6 | |
| 7 | const WORKFLOW_SESSION_PREFIX = "run"; |
| 8 | |
| 9 | export const getWorkflowExecutionSessionId = (runId: string): string => `${WORKFLOW_SESSION_PREFIX}-${runId}`; |
| 10 | |
| 11 | export const toWorkflowClaim = (snapshot: AcceptedRunSnapshot): ExecuteRunWork => ({ |
| 12 | kind: "execute", |
| 13 | snapshot, |
| 14 | }); |
| 15 | |
| 16 | export const toExecutionMaterial = (snapshot: AcceptedRunSnapshot): ProjectExecutionMaterial => ({ |
| 17 | projectId: snapshot.projectId, |
| 18 | encryptedRepoToken: null, |
| 19 | }); |
| 20 | |
| 21 | export const toWorkflowStartedAt = (value: number): UnixTimestampMsType => UnixTimestampMs.assertDecode(value); |
| 22 | |
| 23 | export const toWorkflowTerminalStatus = (outcome: RunExecutionOutcome): WorkflowRunTerminalStatus => |
| 24 | outcome.kind === "ownership_lost" ? "failed" : outcome.kind; |