Skip to content
File

Blob: src/worker/dispatch/workflows/execution.ts

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