File
Blob: src/worker/dispatch/workflows/steps/finalize.ts
| 1 | import { type UnixTimestampMs as UnixTimestampMsType } from "@/contracts"; |
| 2 | import { type AcceptedRunSnapshot, type PositiveInteger } from "@/worker/contracts"; |
| 3 | import { createRunExecutionContext, type RunExecutionOutcome } from "@/worker/dispatch/shared/run-execution-context"; |
| 4 | import { finalizeExecution, RunLease } from "@/worker/dispatch/shared"; |
| 5 | import { toExecutionMaterial, toWorkflowClaim } from "../execution"; |
| 6 | |
| 7 | export const finalizeWorkflowRun = async ( |
| 8 | env: Env, |
| 9 | snapshot: AcceptedRunSnapshot, |
| 10 | startedAt: UnixTimestampMsType, |
| 11 | outcome: RunExecutionOutcome, |
| 12 | position: PositiveInteger | null = null, |
| 13 | ): Promise<void> => { |
| 14 | const context = createRunExecutionContext(env, toExecutionMaterial(snapshot), toWorkflowClaim(snapshot), { |
| 15 | startedAt, |
| 16 | }); |
| 17 | const lease = new RunLease(context); |
| 18 | |
| 19 | if (position !== null) { |
| 20 | context.state.currentStepPosition = position; |
| 21 | } |
| 22 | |
| 23 | try { |
| 24 | await finalizeExecution(context, lease, outcome); |
| 25 | } finally { |
| 26 | context.runtime.dispose(); |
| 27 | } |
| 28 | }; |