@shipfox/api-workflows 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +311 -0
- package/LICENSE +21 -0
- package/dist/core/agent-tool-capability-warning.d.ts +7 -0
- package/dist/core/agent-tool-capability-warning.d.ts.map +1 -0
- package/dist/core/agent-tool-capability-warning.js +149 -0
- package/dist/core/agent-tool-capability-warning.js.map +1 -0
- package/dist/core/agent-tools.d.ts +51 -0
- package/dist/core/agent-tools.d.ts.map +1 -0
- package/dist/core/agent-tools.js +296 -0
- package/dist/core/agent-tools.js.map +1 -0
- package/dist/core/checkout.d.ts +29 -0
- package/dist/core/checkout.d.ts.map +1 -0
- package/dist/core/checkout.js +42 -0
- package/dist/core/checkout.js.map +1 -0
- package/dist/core/condition-trace.d.ts +13 -0
- package/dist/core/condition-trace.d.ts.map +1 -0
- package/dist/core/condition-trace.js +51 -0
- package/dist/core/condition-trace.js.map +1 -0
- package/dist/core/entities/index.d.ts +5 -0
- package/dist/core/entities/index.d.ts.map +1 -0
- package/dist/core/entities/index.js +3 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/job-execution.d.ts +30 -0
- package/dist/core/entities/job-execution.d.ts.map +1 -0
- package/dist/core/entities/job-execution.js +3 -0
- package/dist/core/entities/job-execution.js.map +1 -0
- package/dist/core/entities/job-listener-event.d.ts +15 -0
- package/dist/core/entities/job-listener-event.d.ts.map +1 -0
- package/dist/core/entities/job-listener-event.js +3 -0
- package/dist/core/entities/job-listener-event.js.map +1 -0
- package/dist/core/entities/job.d.ts +54 -0
- package/dist/core/entities/job.d.ts.map +1 -0
- package/dist/core/entities/job.js +29 -0
- package/dist/core/entities/job.js.map +1 -0
- package/dist/core/entities/step.d.ts +86 -0
- package/dist/core/entities/step.d.ts.map +1 -0
- package/dist/core/entities/step.js +12 -0
- package/dist/core/entities/step.js.map +1 -0
- package/dist/core/entities/workflow-run-attempt.d.ts +20 -0
- package/dist/core/entities/workflow-run-attempt.d.ts.map +1 -0
- package/dist/core/entities/workflow-run-attempt.js +3 -0
- package/dist/core/entities/workflow-run-attempt.js.map +1 -0
- package/dist/core/entities/workflow-run.d.ts +66 -0
- package/dist/core/entities/workflow-run.d.ts.map +1 -0
- package/dist/core/entities/workflow-run.js +10 -0
- package/dist/core/entities/workflow-run.js.map +1 -0
- package/dist/core/errors.d.ts +85 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +134 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +9 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/job-execution-outcome.d.ts +29 -0
- package/dist/core/job-execution-outcome.d.ts.map +1 -0
- package/dist/core/job-execution-outcome.js +31 -0
- package/dist/core/job-execution-outcome.js.map +1 -0
- package/dist/core/job-execution.d.ts +37 -0
- package/dist/core/job-execution.d.ts.map +1 -0
- package/dist/core/job-execution.js +425 -0
- package/dist/core/job-execution.js.map +1 -0
- package/dist/core/job-transition/decide-job-activation.d.ts +29 -0
- package/dist/core/job-transition/decide-job-activation.d.ts.map +1 -0
- package/dist/core/job-transition/decide-job-activation.js +51 -0
- package/dist/core/job-transition/decide-job-activation.js.map +1 -0
- package/dist/core/job-transition/derive-job-execution-outputs.d.ts +18 -0
- package/dist/core/job-transition/derive-job-execution-outputs.d.ts.map +1 -0
- package/dist/core/job-transition/derive-job-execution-outputs.js +23 -0
- package/dist/core/job-transition/derive-job-execution-outputs.js.map +1 -0
- package/dist/core/job-transition/derive-job-success.d.ts +16 -0
- package/dist/core/job-transition/derive-job-success.d.ts.map +1 -0
- package/dist/core/job-transition/derive-job-success.js +47 -0
- package/dist/core/job-transition/derive-job-success.js.map +1 -0
- package/dist/core/job-transition/index.d.ts +5 -0
- package/dist/core/job-transition/index.d.ts.map +1 -0
- package/dist/core/job-transition/index.js +6 -0
- package/dist/core/job-transition/index.js.map +1 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.d.ts +4 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.d.ts.map +1 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.js +8 -0
- package/dist/core/job-transition/runtime-completion-status-for-job.js.map +1 -0
- package/dist/core/listener-execution-materialization.d.ts +30 -0
- package/dist/core/listener-execution-materialization.d.ts.map +1 -0
- package/dist/core/listener-execution-materialization.js +87 -0
- package/dist/core/listener-execution-materialization.js.map +1 -0
- package/dist/core/run-workflow.d.ts +11 -0
- package/dist/core/run-workflow.d.ts.map +1 -0
- package/dist/core/run-workflow.js +28 -0
- package/dist/core/run-workflow.js.map +1 -0
- package/dist/core/source-control.d.ts +5 -0
- package/dist/core/source-control.d.ts.map +1 -0
- package/dist/core/source-control.js +19 -0
- package/dist/core/source-control.js.map +1 -0
- package/dist/core/step-config/agent.d.ts +49 -0
- package/dist/core/step-config/agent.d.ts.map +1 -0
- package/dist/core/step-config/agent.js +337 -0
- package/dist/core/step-config/agent.js.map +1 -0
- package/dist/core/step-config/assemble-run-context.d.ts +94 -0
- package/dist/core/step-config/assemble-run-context.d.ts.map +1 -0
- package/dist/core/step-config/assemble-run-context.js +393 -0
- package/dist/core/step-config/assemble-run-context.js.map +1 -0
- package/dist/core/step-config/complete-step-dispatch-config.d.ts +13 -0
- package/dist/core/step-config/complete-step-dispatch-config.d.ts.map +1 -0
- package/dist/core/step-config/complete-step-dispatch-config.js +38 -0
- package/dist/core/step-config/complete-step-dispatch-config.js.map +1 -0
- package/dist/core/step-config/fields.d.ts +38 -0
- package/dist/core/step-config/fields.d.ts.map +1 -0
- package/dist/core/step-config/fields.js +72 -0
- package/dist/core/step-config/fields.js.map +1 -0
- package/dist/core/step-config/index.d.ts +8 -0
- package/dist/core/step-config/index.d.ts.map +1 -0
- package/dist/core/step-config/index.js +7 -0
- package/dist/core/step-config/index.js.map +1 -0
- package/dist/core/step-config/materialize-job-execution-steps.d.ts +35 -0
- package/dist/core/step-config/materialize-job-execution-steps.d.ts.map +1 -0
- package/dist/core/step-config/materialize-job-execution-steps.js +92 -0
- package/dist/core/step-config/materialize-job-execution-steps.js.map +1 -0
- package/dist/core/step-config/materialize-workflow-model.d.ts +42 -0
- package/dist/core/step-config/materialize-workflow-model.d.ts.map +1 -0
- package/dist/core/step-config/materialize-workflow-model.js +96 -0
- package/dist/core/step-config/materialize-workflow-model.js.map +1 -0
- package/dist/core/step-config/resolve-job-execution-name.d.ts +18 -0
- package/dist/core/step-config/resolve-job-execution-name.d.ts.map +1 -0
- package/dist/core/step-config/resolve-job-execution-name.js +36 -0
- package/dist/core/step-config/resolve-job-execution-name.js.map +1 -0
- package/dist/core/step-config/resolve-step-config.d.ts +33 -0
- package/dist/core/step-config/resolve-step-config.d.ts.map +1 -0
- package/dist/core/step-config/resolve-step-config.js +164 -0
- package/dist/core/step-config/resolve-step-config.js.map +1 -0
- package/dist/core/step-config/run.d.ts +39 -0
- package/dist/core/step-config/run.d.ts.map +1 -0
- package/dist/core/step-config/run.js +360 -0
- package/dist/core/step-config/run.js.map +1 -0
- package/dist/core/step-config/workflow-evaluation-context.d.ts +6 -0
- package/dist/core/step-config/workflow-evaluation-context.d.ts.map +1 -0
- package/dist/core/step-config/workflow-evaluation-context.js +3 -0
- package/dist/core/step-config/workflow-evaluation-context.js.map +1 -0
- package/dist/core/step-transition/apply-step-transition.d.ts +26 -0
- package/dist/core/step-transition/apply-step-transition.d.ts.map +1 -0
- package/dist/core/step-transition/apply-step-transition.js +141 -0
- package/dist/core/step-transition/apply-step-transition.js.map +1 -0
- package/dist/core/step-transition/decide-step-transition.d.ts +71 -0
- package/dist/core/step-transition/decide-step-transition.d.ts.map +1 -0
- package/dist/core/step-transition/decide-step-transition.js +110 -0
- package/dist/core/step-transition/decide-step-transition.js.map +1 -0
- package/dist/core/step-transition/evaluate-gate.d.ts +28 -0
- package/dist/core/step-transition/evaluate-gate.d.ts.map +1 -0
- package/dist/core/step-transition/evaluate-gate.js +159 -0
- package/dist/core/step-transition/evaluate-gate.js.map +1 -0
- package/dist/core/step-transition/read-step-outputs.d.ts +3 -0
- package/dist/core/step-transition/read-step-outputs.d.ts.map +1 -0
- package/dist/core/step-transition/read-step-outputs.js +24 -0
- package/dist/core/step-transition/read-step-outputs.js.map +1 -0
- package/dist/core/workflow-run-creation.d.ts +43 -0
- package/dist/core/workflow-run-creation.d.ts.map +1 -0
- package/dist/core/workflow-run-creation.js +80 -0
- package/dist/core/workflow-run-creation.js.map +1 -0
- package/dist/core/workflow-scheduling/index.d.ts +5 -0
- package/dist/core/workflow-scheduling/index.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/index.js +4 -0
- package/dist/core/workflow-scheduling/index.js.map +1 -0
- package/dist/core/workflow-scheduling/run-progress.d.ts +20 -0
- package/dist/core/workflow-scheduling/run-progress.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/run-progress.js +40 -0
- package/dist/core/workflow-scheduling/run-progress.js.map +1 -0
- package/dist/core/workflow-scheduling/runtime-dag.d.ts +10 -0
- package/dist/core/workflow-scheduling/runtime-dag.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/runtime-dag.js +3 -0
- package/dist/core/workflow-scheduling/runtime-dag.js.map +1 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.d.ts +16 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.js +3 -0
- package/dist/core/workflow-scheduling/runtime-scheduling-command.js.map +1 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.d.ts +9 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.d.ts.map +1 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.js +72 -0
- package/dist/core/workflow-scheduling/schedule-runtime-dag.js.map +1 -0
- package/dist/db/db.d.ts +4959 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +37 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/index.d.ts +9 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/job-listener-events.d.ts +18 -0
- package/dist/db/job-listener-events.d.ts.map +1 -0
- package/dist/db/job-listener-events.js +59 -0
- package/dist/db/job-listener-events.js.map +1 -0
- package/dist/db/job-listeners.d.ts +55 -0
- package/dist/db/job-listeners.d.ts.map +1 -0
- package/dist/db/job-listeners.js +358 -0
- package/dist/db/job-listeners.js.map +1 -0
- package/dist/db/outbox-writes.d.ts +12 -0
- package/dist/db/outbox-writes.d.ts.map +1 -0
- package/dist/db/outbox-writes.js +20 -0
- package/dist/db/outbox-writes.js.map +1 -0
- package/dist/db/runner-lease-table.d.ts +469 -0
- package/dist/db/runner-lease-table.d.ts.map +1 -0
- package/dist/db/runner-lease-table.js +42 -0
- package/dist/db/runner-lease-table.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/job-executions.d.ts +311 -0
- package/dist/db/schema/job-executions.d.ts.map +1 -0
- package/dist/db/schema/job-executions.js +76 -0
- package/dist/db/schema/job-executions.js.map +1 -0
- package/dist/db/schema/job-listener-events.d.ts +200 -0
- package/dist/db/schema/job-listener-events.d.ts.map +1 -0
- package/dist/db/schema/job-listener-events.js +50 -0
- package/dist/db/schema/job-listener-events.js.map +1 -0
- package/dist/db/schema/jobs.d.ts +542 -0
- package/dist/db/schema/jobs.d.ts.map +1 -0
- package/dist/db/schema/jobs.js +121 -0
- package/dist/db/schema/jobs.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/step-attempts.d.ts +330 -0
- package/dist/db/schema/step-attempts.d.ts.map +1 -0
- package/dist/db/schema/step-attempts.js +80 -0
- package/dist/db/schema/step-attempts.js.map +1 -0
- package/dist/db/schema/steps.d.ts +352 -0
- package/dist/db/schema/steps.d.ts.map +1 -0
- package/dist/db/schema/steps.js +80 -0
- package/dist/db/schema/steps.js.map +1 -0
- package/dist/db/schema/workflow-run-attempts.d.ts +239 -0
- package/dist/db/schema/workflow-run-attempts.d.ts.map +1 -0
- package/dist/db/schema/workflow-run-attempts.js +53 -0
- package/dist/db/schema/workflow-run-attempts.js.map +1 -0
- package/dist/db/schema/workflow-runs.d.ts +360 -0
- package/dist/db/schema/workflow-runs.d.ts.map +1 -0
- package/dist/db/schema/workflow-runs.js +85 -0
- package/dist/db/schema/workflow-runs.js.map +1 -0
- package/dist/db/workflow-runs/job-executions.d.ts +49 -0
- package/dist/db/workflow-runs/job-executions.d.ts.map +1 -0
- package/dist/db/workflow-runs/job-executions.js +271 -0
- package/dist/db/workflow-runs/job-executions.js.map +1 -0
- package/dist/db/workflow-runs/jobs.d.ts +60 -0
- package/dist/db/workflow-runs/jobs.d.ts.map +1 -0
- package/dist/db/workflow-runs/jobs.js +288 -0
- package/dist/db/workflow-runs/jobs.js.map +1 -0
- package/dist/db/workflow-runs/outbox.d.ts +20 -0
- package/dist/db/workflow-runs/outbox.d.ts.map +1 -0
- package/dist/db/workflow-runs/outbox.js +68 -0
- package/dist/db/workflow-runs/outbox.js.map +1 -0
- package/dist/db/workflow-runs/queries.d.ts +71 -0
- package/dist/db/workflow-runs/queries.d.ts.map +1 -0
- package/dist/db/workflow-runs/queries.js +253 -0
- package/dist/db/workflow-runs/queries.js.map +1 -0
- package/dist/db/workflow-runs/run-create.d.ts +32 -0
- package/dist/db/workflow-runs/run-create.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-create.js +288 -0
- package/dist/db/workflow-runs/run-create.js.map +1 -0
- package/dist/db/workflow-runs/run-graph.d.ts +27 -0
- package/dist/db/workflow-runs/run-graph.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-graph.js +63 -0
- package/dist/db/workflow-runs/run-graph.js.map +1 -0
- package/dist/db/workflow-runs/run-rerun.d.ts +8 -0
- package/dist/db/workflow-runs/run-rerun.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-rerun.js +207 -0
- package/dist/db/workflow-runs/run-rerun.js.map +1 -0
- package/dist/db/workflow-runs/run-status.d.ts +24 -0
- package/dist/db/workflow-runs/run-status.d.ts.map +1 -0
- package/dist/db/workflow-runs/run-status.js +249 -0
- package/dist/db/workflow-runs/run-status.js.map +1 -0
- package/dist/db/workflow-runs/runs.d.ts +7 -0
- package/dist/db/workflow-runs/runs.d.ts.map +1 -0
- package/dist/db/workflow-runs/runs.js +5 -0
- package/dist/db/workflow-runs/runs.js.map +1 -0
- package/dist/db/workflow-runs/shared.d.ts +24 -0
- package/dist/db/workflow-runs/shared.d.ts.map +1 -0
- package/dist/db/workflow-runs/shared.js +50 -0
- package/dist/db/workflow-runs/shared.js.map +1 -0
- package/dist/db/workflow-runs/steps.d.ts +83 -0
- package/dist/db/workflow-runs/steps.d.ts.map +1 -0
- package/dist/db/workflow-runs/steps.js +246 -0
- package/dist/db/workflow-runs/steps.js.map +1 -0
- package/dist/db/workflow-runs.d.ts +12 -0
- package/dist/db/workflow-runs.d.ts.map +1 -0
- package/dist/db/workflow-runs.js +8 -0
- package/dist/db/workflow-runs.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +3 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +20 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +127 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +30 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/dto/checkout-token.d.ts +6 -0
- package/dist/presentation/dto/checkout-token.d.ts.map +1 -0
- package/dist/presentation/dto/checkout-token.js +74 -0
- package/dist/presentation/dto/checkout-token.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +4 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +5 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/job.d.ts +6 -0
- package/dist/presentation/dto/job.d.ts.map +1 -0
- package/dist/presentation/dto/job.js +59 -0
- package/dist/presentation/dto/job.js.map +1 -0
- package/dist/presentation/dto/step.d.ts +6 -0
- package/dist/presentation/dto/step.d.ts.map +1 -0
- package/dist/presentation/dto/step.js +162 -0
- package/dist/presentation/dto/step.js.map +1 -0
- package/dist/presentation/dto/workflow-run.d.ts +6 -0
- package/dist/presentation/dto/workflow-run.d.ts.map +1 -0
- package/dist/presentation/dto/workflow-run.js +35 -0
- package/dist/presentation/dto/workflow-run.js.map +1 -0
- package/dist/presentation/index.d.ts +3 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +4 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/agent-runtime-config.d.ts +2 -0
- package/dist/presentation/routes/agent-runtime-config.d.ts.map +1 -0
- package/dist/presentation/routes/agent-runtime-config.js +71 -0
- package/dist/presentation/routes/agent-runtime-config.js.map +1 -0
- package/dist/presentation/routes/cancel-run.d.ts +2 -0
- package/dist/presentation/routes/cancel-run.d.ts.map +1 -0
- package/dist/presentation/routes/cancel-run.js +46 -0
- package/dist/presentation/routes/cancel-run.js.map +1 -0
- package/dist/presentation/routes/checkout-token.d.ts +2 -0
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -0
- package/dist/presentation/routes/checkout-token.js +64 -0
- package/dist/presentation/routes/checkout-token.js.map +1 -0
- package/dist/presentation/routes/get-run-aggregates.d.ts +2 -0
- package/dist/presentation/routes/get-run-aggregates.d.ts.map +1 -0
- package/dist/presentation/routes/get-run-aggregates.js +60 -0
- package/dist/presentation/routes/get-run-aggregates.js.map +1 -0
- package/dist/presentation/routes/get-run.d.ts +2 -0
- package/dist/presentation/routes/get-run.d.ts.map +1 -0
- package/dist/presentation/routes/get-run.js +60 -0
- package/dist/presentation/routes/get-run.js.map +1 -0
- package/dist/presentation/routes/get-step-secrets.d.ts +2 -0
- package/dist/presentation/routes/get-step-secrets.d.ts.map +1 -0
- package/dist/presentation/routes/get-step-secrets.js +115 -0
- package/dist/presentation/routes/get-step-secrets.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +4 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +41 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/leased-step.d.ts +14 -0
- package/dist/presentation/routes/leased-step.d.ts.map +1 -0
- package/dist/presentation/routes/leased-step.js +50 -0
- package/dist/presentation/routes/leased-step.js.map +1 -0
- package/dist/presentation/routes/list-run-attempts.d.ts +2 -0
- package/dist/presentation/routes/list-run-attempts.d.ts.map +1 -0
- package/dist/presentation/routes/list-run-attempts.js +35 -0
- package/dist/presentation/routes/list-run-attempts.js.map +1 -0
- package/dist/presentation/routes/list-runs.d.ts +2 -0
- package/dist/presentation/routes/list-runs.d.ts.map +1 -0
- package/dist/presentation/routes/list-runs.js +70 -0
- package/dist/presentation/routes/list-runs.js.map +1 -0
- package/dist/presentation/routes/next-step.d.ts +2 -0
- package/dist/presentation/routes/next-step.d.ts.map +1 -0
- package/dist/presentation/routes/next-step.js +65 -0
- package/dist/presentation/routes/next-step.js.map +1 -0
- package/dist/presentation/routes/report-step.d.ts +2 -0
- package/dist/presentation/routes/report-step.d.ts.map +1 -0
- package/dist/presentation/routes/report-step.js +73 -0
- package/dist/presentation/routes/report-step.js.map +1 -0
- package/dist/presentation/routes/require-accessible-run.d.ts +7 -0
- package/dist/presentation/routes/require-accessible-run.d.ts.map +1 -0
- package/dist/presentation/routes/require-accessible-run.js +25 -0
- package/dist/presentation/routes/require-accessible-run.js.map +1 -0
- package/dist/presentation/routes/rerun-run.d.ts +2 -0
- package/dist/presentation/routes/rerun-run.d.ts.map +1 -0
- package/dist/presentation/routes/rerun-run.js +56 -0
- package/dist/presentation/routes/rerun-run.js.map +1 -0
- package/dist/presentation/subscribers/index.d.ts +8 -0
- package/dist/presentation/subscribers/index.d.ts.map +1 -0
- package/dist/presentation/subscribers/index.js +9 -0
- package/dist/presentation/subscribers/index.js.map +1 -0
- package/dist/presentation/subscribers/on-job-event-delivered.d.ts +3 -0
- package/dist/presentation/subscribers/on-job-event-delivered.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-event-delivered.js +24 -0
- package/dist/presentation/subscribers/on-job-event-delivered.js.map +1 -0
- package/dist/presentation/subscribers/on-job-steps-settled.d.ts +3 -0
- package/dist/presentation/subscribers/on-job-steps-settled.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-job-steps-settled.js +36 -0
- package/dist/presentation/subscribers/on-job-steps-settled.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js +20 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.js +35 -0
- package/dist/presentation/subscribers/on-runner-job-lease-expired.js.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-queued.d.ts +3 -0
- package/dist/presentation/subscribers/on-runner-job-queued.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-runner-job-queued.js +20 -0
- package/dist/presentation/subscribers/on-runner-job-queued.js.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.js +35 -0
- package/dist/presentation/subscribers/on-workflow-run-attempt-created.js.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.js +25 -0
- package/dist/presentation/subscribers/on-workflow-run-cancelled.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +23 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +26 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/orchestration-activities.d.ts +130 -0
- package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -0
- package/dist/temporal/activities/orchestration-activities.js +188 -0
- package/dist/temporal/activities/orchestration-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +7 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +8 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/index.d.ts +3 -0
- package/dist/temporal/index.d.ts.map +1 -0
- package/dist/temporal/index.js +4 -0
- package/dist/temporal/index.js.map +1 -0
- package/dist/temporal/workflow-not-found.d.ts +2 -0
- package/dist/temporal/workflow-not-found.d.ts.map +1 -0
- package/dist/temporal/workflow-not-found.js +10 -0
- package/dist/temporal/workflow-not-found.js.map +1 -0
- package/dist/temporal/workflows/deadline.d.ts +3 -0
- package/dist/temporal/workflows/deadline.d.ts.map +1 -0
- package/dist/temporal/workflows/deadline.js +8 -0
- package/dist/temporal/workflows/deadline.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +4 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +5 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts +27 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/job-execution-orchestration.js +265 -0
- package/dist/temporal/workflows/job-execution-orchestration.js.map +1 -0
- package/dist/temporal/workflows/job-listener-orchestration.d.ts +40 -0
- package/dist/temporal/workflows/job-listener-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/job-listener-orchestration.js +332 -0
- package/dist/temporal/workflows/job-listener-orchestration.js.map +1 -0
- package/dist/temporal/workflows/run-orchestration.d.ts +8 -0
- package/dist/temporal/workflows/run-orchestration.d.ts.map +1 -0
- package/dist/temporal/workflows/run-orchestration.js +243 -0
- package/dist/temporal/workflows/run-orchestration.js.map +1 -0
- package/dist/temporal/workflows/test-env.d.ts +114 -0
- package/dist/temporal/workflows/test-env.d.ts.map +1 -0
- package/dist/temporal/workflows/test-env.js +323 -0
- package/dist/temporal/workflows/test-env.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +211 -0
- package/drizzle/0001_agent_tool_materialization.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +1613 -0
- package/drizzle/meta/_journal.json +20 -0
- package/drizzle.config.ts +7 -0
- package/package.json +91 -0
- package/src/core/README.md +79 -0
- package/src/core/agent-tool-capability-warning.test.ts +280 -0
- package/src/core/agent-tool-capability-warning.ts +200 -0
- package/src/core/agent-tools.ts +422 -0
- package/src/core/checkout.test.ts +112 -0
- package/src/core/checkout.ts +63 -0
- package/src/core/condition-trace.ts +64 -0
- package/src/core/entities/index.ts +9 -0
- package/src/core/entities/job-execution.ts +32 -0
- package/src/core/entities/job-listener-event.ts +15 -0
- package/src/core/entities/job.ts +91 -0
- package/src/core/entities/step.ts +126 -0
- package/src/core/entities/workflow-run-attempt.ts +21 -0
- package/src/core/entities/workflow-run.ts +94 -0
- package/src/core/errors.test.ts +45 -0
- package/src/core/errors.ts +209 -0
- package/src/core/index.ts +54 -0
- package/src/core/job-execution-outcome.ts +64 -0
- package/src/core/job-execution.test.ts +1560 -0
- package/src/core/job-execution.ts +581 -0
- package/src/core/job-transition/decide-job-activation.test.ts +196 -0
- package/src/core/job-transition/decide-job-activation.ts +79 -0
- package/src/core/job-transition/derive-job-execution-outputs.ts +41 -0
- package/src/core/job-transition/derive-job-success.test.ts +133 -0
- package/src/core/job-transition/derive-job-success.ts +67 -0
- package/src/core/job-transition/index.ts +11 -0
- package/src/core/job-transition/runtime-completion-status-for-job.ts +14 -0
- package/src/core/listener-execution-materialization.test.ts +49 -0
- package/src/core/listener-execution-materialization.ts +162 -0
- package/src/core/run-workflow.test.ts +229 -0
- package/src/core/run-workflow.ts +41 -0
- package/src/core/source-control.test.ts +17 -0
- package/src/core/source-control.ts +22 -0
- package/src/core/step-config/agent.ts +459 -0
- package/src/core/step-config/assemble-run-context.test.ts +1021 -0
- package/src/core/step-config/assemble-run-context.ts +535 -0
- package/src/core/step-config/complete-step-dispatch-config.test.ts +354 -0
- package/src/core/step-config/complete-step-dispatch-config.ts +40 -0
- package/src/core/step-config/fields.ts +111 -0
- package/src/core/step-config/index.ts +41 -0
- package/src/core/step-config/materialize-job-execution-steps.test.ts +494 -0
- package/src/core/step-config/materialize-job-execution-steps.ts +136 -0
- package/src/core/step-config/materialize-workflow-model.test.ts +1214 -0
- package/src/core/step-config/materialize-workflow-model.ts +140 -0
- package/src/core/step-config/resolve-job-execution-name.test.ts +94 -0
- package/src/core/step-config/resolve-job-execution-name.ts +51 -0
- package/src/core/step-config/resolve-step-config.ts +199 -0
- package/src/core/step-config/run.ts +467 -0
- package/src/core/step-config/workflow-evaluation-context.ts +6 -0
- package/src/core/step-transition/apply-step-transition.ts +163 -0
- package/src/core/step-transition/decide-step-transition.test.ts +307 -0
- package/src/core/step-transition/decide-step-transition.ts +200 -0
- package/src/core/step-transition/evaluate-gate.test.ts +317 -0
- package/src/core/step-transition/evaluate-gate.ts +168 -0
- package/src/core/step-transition/read-step-outputs.ts +27 -0
- package/src/core/workflow-run-creation.test.ts +155 -0
- package/src/core/workflow-run-creation.ts +131 -0
- package/src/core/workflow-scheduling/index.ts +15 -0
- package/src/core/workflow-scheduling/run-progress.test.ts +46 -0
- package/src/core/workflow-scheduling/run-progress.ts +68 -0
- package/src/core/workflow-scheduling/runtime-dag.ts +10 -0
- package/src/core/workflow-scheduling/runtime-scheduling-command.ts +20 -0
- package/src/core/workflow-scheduling/schedule-runtime-dag.test.ts +197 -0
- package/src/core/workflow-scheduling/schedule-runtime-dag.ts +115 -0
- package/src/db/db.ts +40 -0
- package/src/db/index.ts +86 -0
- package/src/db/job-listener-events.test.ts +113 -0
- package/src/db/job-listener-events.ts +73 -0
- package/src/db/job-listeners.test.ts +865 -0
- package/src/db/job-listeners.ts +564 -0
- package/src/db/outbox-writes.ts +40 -0
- package/src/db/rerun-listener.test.ts +64 -0
- package/src/db/run-timeout.test.ts +102 -0
- package/src/db/runner-lease-table.ts +39 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/job-executions.ts +85 -0
- package/src/db/schema/job-listener-events.ts +58 -0
- package/src/db/schema/jobs.ts +136 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/step-attempts.ts +99 -0
- package/src/db/schema/steps.ts +99 -0
- package/src/db/schema/workflow-run-attempts.ts +59 -0
- package/src/db/schema/workflow-runs.ts +112 -0
- package/src/db/workflow-runs/job-executions.test.ts +99 -0
- package/src/db/workflow-runs/job-executions.ts +421 -0
- package/src/db/workflow-runs/job-status.test.ts +532 -0
- package/src/db/workflow-runs/jobs.test.ts +194 -0
- package/src/db/workflow-runs/jobs.ts +418 -0
- package/src/db/workflow-runs/outbox.ts +109 -0
- package/src/db/workflow-runs/queries.test.ts +256 -0
- package/src/db/workflow-runs/queries.ts +437 -0
- package/src/db/workflow-runs/run-create.test.ts +1281 -0
- package/src/db/workflow-runs/run-create.ts +373 -0
- package/src/db/workflow-runs/run-graph.ts +95 -0
- package/src/db/workflow-runs/run-rerun.test.ts +625 -0
- package/src/db/workflow-runs/run-rerun.ts +266 -0
- package/src/db/workflow-runs/run-status.test.ts +425 -0
- package/src/db/workflow-runs/run-status.ts +391 -0
- package/src/db/workflow-runs/runs.ts +17 -0
- package/src/db/workflow-runs/shared.ts +84 -0
- package/src/db/workflow-runs/steps.test.ts +191 -0
- package/src/db/workflow-runs/steps.ts +476 -0
- package/src/db/workflow-runs.ts +111 -0
- package/src/index.ts +99 -0
- package/src/metrics/index.ts +1 -0
- package/src/metrics/instance.ts +160 -0
- package/src/metrics/service.ts +30 -0
- package/src/presentation/dto/checkout-token.test.ts +107 -0
- package/src/presentation/dto/checkout-token.ts +85 -0
- package/src/presentation/dto/index.ts +3 -0
- package/src/presentation/dto/job.test.ts +108 -0
- package/src/presentation/dto/job.ts +64 -0
- package/src/presentation/dto/step.test.ts +307 -0
- package/src/presentation/dto/step.ts +145 -0
- package/src/presentation/dto/workflow-run.ts +38 -0
- package/src/presentation/index.ts +10 -0
- package/src/presentation/routes/agent-runtime-config.test.ts +478 -0
- package/src/presentation/routes/agent-runtime-config.ts +81 -0
- package/src/presentation/routes/cancel-run.test.ts +156 -0
- package/src/presentation/routes/cancel-run.ts +37 -0
- package/src/presentation/routes/checkout-token.test.ts +366 -0
- package/src/presentation/routes/checkout-token.ts +61 -0
- package/src/presentation/routes/get-run-aggregates.test.ts +114 -0
- package/src/presentation/routes/get-run-aggregates.ts +69 -0
- package/src/presentation/routes/get-run.test.ts +604 -0
- package/src/presentation/routes/get-run.ts +66 -0
- package/src/presentation/routes/get-step-secrets.test.ts +260 -0
- package/src/presentation/routes/get-step-secrets.ts +117 -0
- package/src/presentation/routes/index.test.ts +71 -0
- package/src/presentation/routes/index.ts +42 -0
- package/src/presentation/routes/leased-step.ts +54 -0
- package/src/presentation/routes/list-run-attempts.test.ts +163 -0
- package/src/presentation/routes/list-run-attempts.ts +27 -0
- package/src/presentation/routes/list-runs.test.ts +244 -0
- package/src/presentation/routes/list-runs.ts +83 -0
- package/src/presentation/routes/next-step.test.ts +366 -0
- package/src/presentation/routes/next-step.ts +62 -0
- package/src/presentation/routes/report-step.test.ts +374 -0
- package/src/presentation/routes/report-step.ts +61 -0
- package/src/presentation/routes/require-accessible-run.ts +27 -0
- package/src/presentation/routes/rerun-run.test.ts +202 -0
- package/src/presentation/routes/rerun-run.ts +48 -0
- package/src/presentation/subscribers/index.ts +7 -0
- package/src/presentation/subscribers/on-job-event-delivered.test.ts +71 -0
- package/src/presentation/subscribers/on-job-event-delivered.ts +30 -0
- package/src/presentation/subscribers/on-job-steps-settled.test.ts +75 -0
- package/src/presentation/subscribers/on-job-steps-settled.ts +42 -0
- package/src/presentation/subscribers/on-runner-job-claimed.test.ts +57 -0
- package/src/presentation/subscribers/on-runner-job-claimed.ts +23 -0
- package/src/presentation/subscribers/on-runner-job-lease-expired.test.ts +73 -0
- package/src/presentation/subscribers/on-runner-job-lease-expired.ts +36 -0
- package/src/presentation/subscribers/on-runner-job-queued.test.ts +57 -0
- package/src/presentation/subscribers/on-runner-job-queued.ts +23 -0
- package/src/presentation/subscribers/on-workflow-run-attempt-created.test.ts +69 -0
- package/src/presentation/subscribers/on-workflow-run-attempt-created.ts +40 -0
- package/src/presentation/subscribers/on-workflow-run-cancelled.test.ts +59 -0
- package/src/presentation/subscribers/on-workflow-run-cancelled.ts +29 -0
- package/src/temporal/activities/index.ts +45 -0
- package/src/temporal/activities/orchestration-activities.test.ts +115 -0
- package/src/temporal/activities/orchestration-activities.ts +305 -0
- package/src/temporal/constants.ts +6 -0
- package/src/temporal/index.ts +6 -0
- package/src/temporal/workflow-not-found.ts +9 -0
- package/src/temporal/workflows/deadline.ts +7 -0
- package/src/temporal/workflows/index.ts +11 -0
- package/src/temporal/workflows/job-execution-orchestration-timeout.test.ts +165 -0
- package/src/temporal/workflows/job-execution-orchestration.test.ts +311 -0
- package/src/temporal/workflows/job-execution-orchestration.ts +314 -0
- package/src/temporal/workflows/job-listener-orchestration-continuation.test.ts +93 -0
- package/src/temporal/workflows/job-listener-orchestration.test.ts +406 -0
- package/src/temporal/workflows/job-listener-orchestration.ts +490 -0
- package/src/temporal/workflows/run-orchestration.test.ts +409 -0
- package/src/temporal/workflows/run-orchestration.ts +283 -0
- package/src/temporal/workflows/test-env.ts +409 -0
- package/test/env.ts +11 -0
- package/test/factories/job.ts +83 -0
- package/test/factories/project.ts +16 -0
- package/test/factories/workflow-model.test.ts +26 -0
- package/test/factories/workflow-model.ts +268 -0
- package/test/factories/workflow-run.ts +58 -0
- package/test/fixtures/active-lease-token.ts +85 -0
- package/test/fixtures/job-with-steps.ts +42 -0
- package/test/fixtures/lease-token.ts +44 -0
- package/test/fixtures/strip-setup-step.ts +23 -0
- package/test/globalSetup.ts +54 -0
- package/test/helpers/workflow-runs.ts +210 -0
- package/test/index.ts +3 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {WorkflowModel} from '@shipfox/api-definitions';
|
|
2
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
3
|
+
import {sql} from 'drizzle-orm';
|
|
4
|
+
import {check, integer, jsonb, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
5
|
+
import type {AgentToolMaterializationSnapshot} from '#core/agent-tools.js';
|
|
6
|
+
import type {WorkflowRunAttempt} from '#core/entities/workflow-run-attempt.js';
|
|
7
|
+
import {pgTable} from './common.js';
|
|
8
|
+
import {workflowRunRerunModeEnum, workflowRunStatusEnum, workflowRuns} from './workflow-runs.js';
|
|
9
|
+
|
|
10
|
+
export const workflowRunAttempts = pgTable(
|
|
11
|
+
'workflow_run_attempts',
|
|
12
|
+
{
|
|
13
|
+
id: uuidv7PrimaryKey(),
|
|
14
|
+
workflowRunId: uuid('workflow_run_id')
|
|
15
|
+
.notNull()
|
|
16
|
+
.references(() => workflowRuns.id, {onDelete: 'cascade'}),
|
|
17
|
+
attempt: integer('attempt').notNull(),
|
|
18
|
+
status: workflowRunStatusEnum('status').notNull().default('pending'),
|
|
19
|
+
rerunMode: workflowRunRerunModeEnum('rerun_mode'),
|
|
20
|
+
rerunByUserId: uuid('rerun_by_user_id'),
|
|
21
|
+
model: jsonb('model').$type<WorkflowModel>(),
|
|
22
|
+
agentToolMaterialization: jsonb(
|
|
23
|
+
'agent_tool_materialization',
|
|
24
|
+
).$type<AgentToolMaterializationSnapshot>(),
|
|
25
|
+
version: integer('version').notNull().default(1),
|
|
26
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
27
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
28
|
+
startedAt: timestamp('started_at', {withTimezone: true}),
|
|
29
|
+
finishedAt: timestamp('finished_at', {withTimezone: true}),
|
|
30
|
+
},
|
|
31
|
+
(table) => [
|
|
32
|
+
uniqueIndex('workflows_wra_workflow_run_attempt_unique').on(table.workflowRunId, table.attempt),
|
|
33
|
+
check('workflows_wra_attempt_positive_ck', sql`${table.attempt} > 0`),
|
|
34
|
+
uniqueIndex('workflows_wra_one_active_attempt_unique')
|
|
35
|
+
.on(table.workflowRunId)
|
|
36
|
+
.where(sql`${table.status} in ('pending', 'running')`),
|
|
37
|
+
],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export type WorkflowRunAttemptDb = typeof workflowRunAttempts.$inferSelect;
|
|
41
|
+
export type WorkflowRunAttemptCreateDb = typeof workflowRunAttempts.$inferInsert;
|
|
42
|
+
|
|
43
|
+
export function toWorkflowRunAttempt(row: WorkflowRunAttemptDb): WorkflowRunAttempt {
|
|
44
|
+
return {
|
|
45
|
+
id: row.id,
|
|
46
|
+
workflowRunId: row.workflowRunId,
|
|
47
|
+
attempt: row.attempt,
|
|
48
|
+
status: row.status,
|
|
49
|
+
rerunMode: row.rerunMode ?? null,
|
|
50
|
+
rerunByUserId: row.rerunByUserId,
|
|
51
|
+
model: row.model ?? null,
|
|
52
|
+
agentToolMaterialization: row.agentToolMaterialization ?? null,
|
|
53
|
+
version: row.version,
|
|
54
|
+
createdAt: row.createdAt,
|
|
55
|
+
updatedAt: row.updatedAt,
|
|
56
|
+
startedAt: row.startedAt,
|
|
57
|
+
finishedAt: row.finishedAt,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {DEFAULT_RUN_TIMEOUT_MS} from '@shipfox/api-definitions';
|
|
2
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
3
|
+
import {sql} from 'drizzle-orm';
|
|
4
|
+
import {
|
|
5
|
+
bigint,
|
|
6
|
+
check,
|
|
7
|
+
index,
|
|
8
|
+
integer,
|
|
9
|
+
jsonb,
|
|
10
|
+
pgEnum,
|
|
11
|
+
text,
|
|
12
|
+
timestamp,
|
|
13
|
+
uniqueIndex,
|
|
14
|
+
uuid,
|
|
15
|
+
} from 'drizzle-orm/pg-core';
|
|
16
|
+
import type {
|
|
17
|
+
TriggerPayload,
|
|
18
|
+
WorkflowRun,
|
|
19
|
+
WorkflowSourceSnapshot,
|
|
20
|
+
} from '#core/entities/workflow-run.js';
|
|
21
|
+
import {pgTable} from './common.js';
|
|
22
|
+
|
|
23
|
+
export const workflowRunStatusEnum = pgEnum('workflows_run_status', [
|
|
24
|
+
'pending',
|
|
25
|
+
'running',
|
|
26
|
+
'succeeded',
|
|
27
|
+
'failed',
|
|
28
|
+
'cancelled',
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
export const workflowRunRerunModeEnum = pgEnum('workflows_rerun_mode', ['all', 'failed']);
|
|
32
|
+
|
|
33
|
+
export const workflowRuns = pgTable(
|
|
34
|
+
'workflow_runs',
|
|
35
|
+
{
|
|
36
|
+
id: uuidv7PrimaryKey(),
|
|
37
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
38
|
+
projectId: uuid('project_id').notNull(),
|
|
39
|
+
definitionId: uuid('definition_id').notNull(),
|
|
40
|
+
name: text('name').notNull(),
|
|
41
|
+
status: workflowRunStatusEnum('status').notNull().default('pending'),
|
|
42
|
+
currentAttempt: integer('current_attempt').notNull().default(1),
|
|
43
|
+
triggerProvider: text('trigger_provider'),
|
|
44
|
+
triggerSource: text('trigger_source').notNull(),
|
|
45
|
+
triggerEvent: text('trigger_event').notNull(),
|
|
46
|
+
triggerPayload: jsonb('trigger_payload').notNull().$type<TriggerPayload>(),
|
|
47
|
+
inputs: jsonb('inputs').$type<Record<string, unknown>>(),
|
|
48
|
+
sourceSnapshot: jsonb('source_snapshot').$type<WorkflowSourceSnapshot>(),
|
|
49
|
+
triggerIdempotencyKey: text('trigger_idempotency_key'),
|
|
50
|
+
timeoutMs: bigint('timeout_ms', {mode: 'number'}).notNull().default(DEFAULT_RUN_TIMEOUT_MS),
|
|
51
|
+
version: integer('version').notNull().default(1),
|
|
52
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
53
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
54
|
+
startedAt: timestamp('started_at', {withTimezone: true}),
|
|
55
|
+
finishedAt: timestamp('finished_at', {withTimezone: true}),
|
|
56
|
+
},
|
|
57
|
+
(table) => [
|
|
58
|
+
uniqueIndex('workflows_wr_trigger_idempotency_key_unique').on(table.triggerIdempotencyKey),
|
|
59
|
+
index('workflows_wr_project_created_id_idx').on(table.projectId, table.createdAt, table.id),
|
|
60
|
+
index('workflows_wr_project_status_created_id_idx').on(
|
|
61
|
+
table.projectId,
|
|
62
|
+
table.status,
|
|
63
|
+
table.createdAt,
|
|
64
|
+
table.id,
|
|
65
|
+
),
|
|
66
|
+
index('workflows_wr_project_definition_created_id_idx').on(
|
|
67
|
+
table.projectId,
|
|
68
|
+
table.definitionId,
|
|
69
|
+
table.createdAt,
|
|
70
|
+
table.id,
|
|
71
|
+
),
|
|
72
|
+
index('workflows_wr_project_trigger_created_id_idx').on(
|
|
73
|
+
table.projectId,
|
|
74
|
+
table.triggerSource,
|
|
75
|
+
table.createdAt,
|
|
76
|
+
table.id,
|
|
77
|
+
),
|
|
78
|
+
// Partial index backing the running-runs depth gauge, which counts on every
|
|
79
|
+
// Prometheus scrape. Indexes only active rows so the count stays cheap as the
|
|
80
|
+
// historical table grows.
|
|
81
|
+
index('workflows_wr_running_idx').on(table.status).where(sql`${table.status} = 'running'`),
|
|
82
|
+
check('workflows_wr_current_attempt_positive_ck', sql`${table.currentAttempt} > 0`),
|
|
83
|
+
],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
export type WorkflowRunDb = typeof workflowRuns.$inferSelect;
|
|
87
|
+
export type WorkflowRunCreateDb = typeof workflowRuns.$inferInsert;
|
|
88
|
+
|
|
89
|
+
export function toWorkflowRun(row: WorkflowRunDb): WorkflowRun {
|
|
90
|
+
return {
|
|
91
|
+
id: row.id,
|
|
92
|
+
workspaceId: row.workspaceId,
|
|
93
|
+
projectId: row.projectId,
|
|
94
|
+
definitionId: row.definitionId,
|
|
95
|
+
name: row.name,
|
|
96
|
+
status: row.status,
|
|
97
|
+
currentAttempt: row.currentAttempt,
|
|
98
|
+
triggerProvider: row.triggerProvider,
|
|
99
|
+
triggerSource: row.triggerSource,
|
|
100
|
+
triggerEvent: row.triggerEvent,
|
|
101
|
+
triggerPayload: row.triggerPayload as TriggerPayload,
|
|
102
|
+
inputs: row.inputs ?? null,
|
|
103
|
+
sourceSnapshot: row.sourceSnapshot ?? null,
|
|
104
|
+
triggerIdempotencyKey: row.triggerIdempotencyKey,
|
|
105
|
+
timeoutMs: row.timeoutMs,
|
|
106
|
+
version: row.version,
|
|
107
|
+
createdAt: row.createdAt,
|
|
108
|
+
updatedAt: row.updatedAt,
|
|
109
|
+
startedAt: row.startedAt,
|
|
110
|
+
finishedAt: row.finishedAt,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {WORKFLOWS_JOB_EXECUTION_TIMED_OUT} from '@shipfox/api-workflows-dto';
|
|
2
|
+
import {and, eq, sql} from 'drizzle-orm';
|
|
3
|
+
import {buildModel, workflowRunAttemptId} from '#test/helpers/workflow-runs.js';
|
|
4
|
+
import {db} from '../db.js';
|
|
5
|
+
import {workflowsOutbox} from '../schema/outbox.js';
|
|
6
|
+
import {
|
|
7
|
+
createWorkflowRun,
|
|
8
|
+
failJobExecutionAsTimedOut,
|
|
9
|
+
getFirstJobExecutionByJobId,
|
|
10
|
+
getJobsByWorkflowRunId,
|
|
11
|
+
getStepsByJobId,
|
|
12
|
+
resolveJobExecutionAfterLeaseExpiry,
|
|
13
|
+
updateJobExecutionStatus,
|
|
14
|
+
} from '../workflow-runs.js';
|
|
15
|
+
|
|
16
|
+
describe('workflow run job executions', () => {
|
|
17
|
+
let workspaceId: string;
|
|
18
|
+
let projectId: string;
|
|
19
|
+
let definitionId: string;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
workspaceId = crypto.randomUUID();
|
|
23
|
+
projectId = crypto.randomUUID();
|
|
24
|
+
definitionId = crypto.randomUUID();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('derives timeout outbox attempt identity from the job execution', async () => {
|
|
28
|
+
const run = await createWorkflowRun({
|
|
29
|
+
workspaceId,
|
|
30
|
+
projectId,
|
|
31
|
+
definitionId,
|
|
32
|
+
model: buildModel({jobs: {build: {steps: [{run: 'echo build'}]}}}),
|
|
33
|
+
triggerPayload: {
|
|
34
|
+
source: 'manual',
|
|
35
|
+
event: 'fire',
|
|
36
|
+
subscriptionId: crypto.randomUUID(),
|
|
37
|
+
userId: crypto.randomUUID(),
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const [job] = await getJobsByWorkflowRunId(run.id);
|
|
41
|
+
if (!job) throw new Error('Expected workflow job');
|
|
42
|
+
const execution = await getFirstJobExecutionByJobId(job.id);
|
|
43
|
+
if (!execution) throw new Error('Expected job execution');
|
|
44
|
+
const actualAttemptId = await workflowRunAttemptId(run.id);
|
|
45
|
+
|
|
46
|
+
await failJobExecutionAsTimedOut({
|
|
47
|
+
jobExecutionId: execution.id,
|
|
48
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
49
|
+
expectedVersion: execution.version,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const [event] = await db()
|
|
53
|
+
.select({payload: workflowsOutbox.payload})
|
|
54
|
+
.from(workflowsOutbox)
|
|
55
|
+
.where(
|
|
56
|
+
and(
|
|
57
|
+
eq(workflowsOutbox.eventType, WORKFLOWS_JOB_EXECUTION_TIMED_OUT),
|
|
58
|
+
sql`${workflowsOutbox.payload}->>'jobExecutionId' = ${execution.id}`,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
expect(event?.payload).toMatchObject({
|
|
62
|
+
jobId: job.id,
|
|
63
|
+
jobExecutionId: execution.id,
|
|
64
|
+
workflowRunAttemptId: actualAttemptId,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('does not cancel steps when lease expiry loses the execution version race', async () => {
|
|
69
|
+
const run = await createWorkflowRun({
|
|
70
|
+
workspaceId,
|
|
71
|
+
projectId,
|
|
72
|
+
definitionId,
|
|
73
|
+
model: buildModel({jobs: {build: {steps: [{run: 'echo build'}]}}}),
|
|
74
|
+
triggerPayload: {
|
|
75
|
+
source: 'manual',
|
|
76
|
+
event: 'fire',
|
|
77
|
+
subscriptionId: crypto.randomUUID(),
|
|
78
|
+
userId: crypto.randomUUID(),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const [job] = await getJobsByWorkflowRunId(run.id);
|
|
82
|
+
if (!job) throw new Error('Expected workflow job');
|
|
83
|
+
const execution = await getFirstJobExecutionByJobId(job.id);
|
|
84
|
+
if (!execution) throw new Error('Expected job execution');
|
|
85
|
+
await updateJobExecutionStatus({
|
|
86
|
+
jobExecutionId: execution.id,
|
|
87
|
+
status: 'running',
|
|
88
|
+
expectedVersion: execution.version,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
await resolveJobExecutionAfterLeaseExpiry({
|
|
92
|
+
jobExecutionId: execution.id,
|
|
93
|
+
expectedVersion: execution.version,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const jobSteps = await getStepsByJobId(job.id);
|
|
97
|
+
expect(jobSteps.every((step) => step.status === 'pending')).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import {WORKFLOWS_JOB_EXECUTION_TIMED_OUT} from '@shipfox/api-workflows-dto';
|
|
2
|
+
import {and, asc, desc, eq, isNull, notInArray, sql} from 'drizzle-orm';
|
|
3
|
+
import type {JobStatusReason} from '#core/entities/job.js';
|
|
4
|
+
import type {JobExecution, JobExecutionStatus} from '#core/entities/job-execution.js';
|
|
5
|
+
import {InterpolationUnresolvableError, JobNotFoundError} from '#core/errors.js';
|
|
6
|
+
import {deriveJobExecutionOutputs} from '#core/job-transition/index.js';
|
|
7
|
+
import {deriveCompletion, isTerminal} from '#core/step-transition/decide-step-transition.js';
|
|
8
|
+
import type {RuntimeCompletionStatus} from '#core/workflow-scheduling/runtime-dag.js';
|
|
9
|
+
import {
|
|
10
|
+
recordWorkflowJobExecutionLeaseExpiryResolved,
|
|
11
|
+
recordWorkflowJobExecutionQueued,
|
|
12
|
+
recordWorkflowJobExecutionStarted,
|
|
13
|
+
recordWorkflowJobExecutionStatusChanged,
|
|
14
|
+
recordWorkflowJobExecutionTimedOut,
|
|
15
|
+
} from '#metrics/instance.js';
|
|
16
|
+
import {db, type Tx} from '../db.js';
|
|
17
|
+
import {writeWorkflowsOutboxEvent} from '../outbox-writes.js';
|
|
18
|
+
import {runningJobExecutions} from '../runner-lease-table.js';
|
|
19
|
+
import {jobExecutions, toJobExecution} from '../schema/job-executions.js';
|
|
20
|
+
import {jobs, toJob} from '../schema/jobs.js';
|
|
21
|
+
import {stepAttempts, toStepAttempt} from '../schema/step-attempts.js';
|
|
22
|
+
import {steps, toStep} from '../schema/steps.js';
|
|
23
|
+
import {workflowRunAttempts} from '../schema/workflow-run-attempts.js';
|
|
24
|
+
import {toWorkflowRun, workflowRuns} from '../schema/workflow-runs.js';
|
|
25
|
+
import {getDirectDependencyJobContexts} from './jobs.js';
|
|
26
|
+
import {loadReferencedVariables} from './runs.js';
|
|
27
|
+
import {
|
|
28
|
+
getWorkflowContextForJob,
|
|
29
|
+
optimisticLockRetry,
|
|
30
|
+
TERMINAL_EXECUTION_STATUSES,
|
|
31
|
+
} from './shared.js';
|
|
32
|
+
import {bulkUpdateStepStatuses, getStepsByJobExecutionIdForUpdate} from './steps.js';
|
|
33
|
+
|
|
34
|
+
export async function lockActiveJobExecutionLeaseForUpdate(
|
|
35
|
+
params: {jobId: string; jobExecutionId: string; runnerSessionId: string},
|
|
36
|
+
tx: Tx,
|
|
37
|
+
): Promise<boolean> {
|
|
38
|
+
const rows = await tx
|
|
39
|
+
.select({id: runningJobExecutions.id})
|
|
40
|
+
.from(runningJobExecutions)
|
|
41
|
+
.where(
|
|
42
|
+
and(
|
|
43
|
+
eq(runningJobExecutions.jobId, params.jobId),
|
|
44
|
+
eq(runningJobExecutions.jobExecutionId, params.jobExecutionId),
|
|
45
|
+
eq(runningJobExecutions.runnerSessionId, params.runnerSessionId),
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
.limit(1)
|
|
49
|
+
.for('update');
|
|
50
|
+
|
|
51
|
+
return rows.length > 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function getJobExecutionById(id: string, tx?: Tx): Promise<JobExecution | undefined> {
|
|
55
|
+
const rows = await (tx ?? db())
|
|
56
|
+
.select()
|
|
57
|
+
.from(jobExecutions)
|
|
58
|
+
.where(eq(jobExecutions.id, id))
|
|
59
|
+
.limit(1);
|
|
60
|
+
const row = rows[0];
|
|
61
|
+
return row ? toJobExecution(row) : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function getJobExecutionsByWorkflowRunAttemptId(
|
|
65
|
+
workflowRunAttemptId: string,
|
|
66
|
+
): Promise<JobExecution[]> {
|
|
67
|
+
const rows = await db()
|
|
68
|
+
.select({jobExecution: jobExecutions})
|
|
69
|
+
.from(jobExecutions)
|
|
70
|
+
.innerJoin(jobs, eq(jobExecutions.jobId, jobs.id))
|
|
71
|
+
.where(eq(jobs.workflowRunAttemptId, workflowRunAttemptId))
|
|
72
|
+
.orderBy(asc(jobExecutions.sequence), asc(jobExecutions.id));
|
|
73
|
+
return rows.map((row) => toJobExecution(row.jobExecution));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function getJobExecutionsByJobId(jobId: string): Promise<JobExecution[]> {
|
|
77
|
+
const rows = await db()
|
|
78
|
+
.select()
|
|
79
|
+
.from(jobExecutions)
|
|
80
|
+
.where(eq(jobExecutions.jobId, jobId))
|
|
81
|
+
.orderBy(asc(jobExecutions.sequence), asc(jobExecutions.id));
|
|
82
|
+
return rows.map(toJobExecution);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function getFirstJobExecutionByJobId(
|
|
86
|
+
jobId: string,
|
|
87
|
+
tx?: Tx,
|
|
88
|
+
): Promise<JobExecution | undefined> {
|
|
89
|
+
const rows = await (tx ?? db())
|
|
90
|
+
.select()
|
|
91
|
+
.from(jobExecutions)
|
|
92
|
+
.where(eq(jobExecutions.jobId, jobId))
|
|
93
|
+
.orderBy(asc(jobExecutions.sequence), asc(jobExecutions.id))
|
|
94
|
+
.limit(1);
|
|
95
|
+
const row = rows[0];
|
|
96
|
+
return row ? toJobExecution(row) : undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function getLatestJobExecutionByJobId(
|
|
100
|
+
jobId: string,
|
|
101
|
+
tx?: Tx,
|
|
102
|
+
): Promise<JobExecution | undefined> {
|
|
103
|
+
const rows = await (tx ?? db())
|
|
104
|
+
.select()
|
|
105
|
+
.from(jobExecutions)
|
|
106
|
+
.where(eq(jobExecutions.jobId, jobId))
|
|
107
|
+
.orderBy(desc(jobExecutions.sequence), desc(jobExecutions.id))
|
|
108
|
+
.limit(1);
|
|
109
|
+
const row = rows[0];
|
|
110
|
+
return row ? toJobExecution(row) : undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface UpdateJobExecutionStatusAtVersionParams {
|
|
114
|
+
jobExecutionId: string;
|
|
115
|
+
status: JobExecutionStatus;
|
|
116
|
+
expectedVersion: number;
|
|
117
|
+
statusReason?: JobStatusReason | null | undefined;
|
|
118
|
+
markTimedOut?: boolean;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function resolveJobExecutionOutputs(
|
|
122
|
+
tx: Tx,
|
|
123
|
+
params: {
|
|
124
|
+
jobExecutionId: string;
|
|
125
|
+
status: JobExecutionStatus;
|
|
126
|
+
statusReason: JobStatusReason | null;
|
|
127
|
+
},
|
|
128
|
+
): Promise<Record<string, unknown> | null> {
|
|
129
|
+
const [target] = await tx
|
|
130
|
+
.select({execution: jobExecutions, job: jobs, attempt: workflowRunAttempts, run: workflowRuns})
|
|
131
|
+
.from(jobExecutions)
|
|
132
|
+
.innerJoin(jobs, eq(jobExecutions.jobId, jobs.id))
|
|
133
|
+
.innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))
|
|
134
|
+
.innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))
|
|
135
|
+
.where(eq(jobExecutions.id, params.jobExecutionId))
|
|
136
|
+
.limit(1);
|
|
137
|
+
if (!target) throw new JobNotFoundError(params.jobExecutionId);
|
|
138
|
+
const model = target.attempt.model;
|
|
139
|
+
if (!model) return null;
|
|
140
|
+
const modelJob = model.jobs.find((job) => job.key === target.job.key);
|
|
141
|
+
if (!modelJob || modelJob.outputs === undefined) return null;
|
|
142
|
+
|
|
143
|
+
const executionRows = await tx
|
|
144
|
+
.select()
|
|
145
|
+
.from(jobExecutions)
|
|
146
|
+
.where(eq(jobExecutions.jobId, target.job.id))
|
|
147
|
+
.orderBy(asc(jobExecutions.sequence), asc(jobExecutions.id));
|
|
148
|
+
const executions = executionRows.map((row) =>
|
|
149
|
+
row.id === target.execution.id
|
|
150
|
+
? toJobExecution({...row, status: params.status, statusReason: params.statusReason})
|
|
151
|
+
: toJobExecution(row),
|
|
152
|
+
);
|
|
153
|
+
const jobExecution = executions.find((execution) => execution.id === target.execution.id);
|
|
154
|
+
if (!jobExecution) throw new JobNotFoundError(params.jobExecutionId);
|
|
155
|
+
|
|
156
|
+
const stepRows = await tx
|
|
157
|
+
.select()
|
|
158
|
+
.from(steps)
|
|
159
|
+
.where(eq(steps.jobExecutionId, params.jobExecutionId))
|
|
160
|
+
.orderBy(asc(steps.position), asc(steps.id));
|
|
161
|
+
const attemptRows = await tx
|
|
162
|
+
.select()
|
|
163
|
+
.from(stepAttempts)
|
|
164
|
+
.where(eq(stepAttempts.jobExecutionId, params.jobExecutionId))
|
|
165
|
+
.orderBy(asc(stepAttempts.executionOrder), asc(stepAttempts.id));
|
|
166
|
+
const dependencyJobs = await getDirectDependencyJobContexts(target.job.id, tx);
|
|
167
|
+
|
|
168
|
+
return deriveJobExecutionOutputs({
|
|
169
|
+
run: toWorkflowRun(target.run),
|
|
170
|
+
modelJob,
|
|
171
|
+
job: toJob(target.job),
|
|
172
|
+
jobExecution,
|
|
173
|
+
executions,
|
|
174
|
+
steps: stepRows.map(toStep),
|
|
175
|
+
attempts: attemptRows.map(toStepAttempt),
|
|
176
|
+
jobs: dependencyJobs,
|
|
177
|
+
vars: await loadReferencedVariables({
|
|
178
|
+
model,
|
|
179
|
+
jobs: [modelJob],
|
|
180
|
+
workspaceId: target.run.workspaceId,
|
|
181
|
+
projectId: target.run.projectId,
|
|
182
|
+
definitionId: target.run.definitionId,
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function updateJobExecutionStatusAtVersion(
|
|
188
|
+
tx: Tx,
|
|
189
|
+
params: UpdateJobExecutionStatusAtVersionParams,
|
|
190
|
+
): Promise<{execution: JobExecution; changed: boolean} | null> {
|
|
191
|
+
let status = params.status;
|
|
192
|
+
let statusReason = params.statusReason ?? null;
|
|
193
|
+
let outputs: Record<string, unknown> | null | undefined;
|
|
194
|
+
if (TERMINAL_EXECUTION_STATUSES.includes(status)) {
|
|
195
|
+
outputs = null;
|
|
196
|
+
}
|
|
197
|
+
if (status === 'succeeded') {
|
|
198
|
+
try {
|
|
199
|
+
outputs = await resolveJobExecutionOutputs(tx, {
|
|
200
|
+
jobExecutionId: params.jobExecutionId,
|
|
201
|
+
status,
|
|
202
|
+
statusReason,
|
|
203
|
+
});
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (!(error instanceof InterpolationUnresolvableError)) throw error;
|
|
206
|
+
status = 'failed';
|
|
207
|
+
statusReason = 'unknown';
|
|
208
|
+
outputs = null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const rows = await tx
|
|
213
|
+
.update(jobExecutions)
|
|
214
|
+
.set({
|
|
215
|
+
status,
|
|
216
|
+
statusReason,
|
|
217
|
+
...(outputs === undefined ? {} : {outputs}),
|
|
218
|
+
version: sql`${jobExecutions.version} + 1`,
|
|
219
|
+
updatedAt: new Date(),
|
|
220
|
+
...(params.markTimedOut ? {timedOutAt: new Date()} : {}),
|
|
221
|
+
...(TERMINAL_EXECUTION_STATUSES.includes(status) ? {finishedAt: sql`now()`} : {}),
|
|
222
|
+
})
|
|
223
|
+
.where(
|
|
224
|
+
and(
|
|
225
|
+
eq(jobExecutions.id, params.jobExecutionId),
|
|
226
|
+
eq(jobExecutions.version, params.expectedVersion),
|
|
227
|
+
notInArray(jobExecutions.status, TERMINAL_EXECUTION_STATUSES),
|
|
228
|
+
),
|
|
229
|
+
)
|
|
230
|
+
.returning();
|
|
231
|
+
|
|
232
|
+
const row = rows[0];
|
|
233
|
+
if (!row) return null;
|
|
234
|
+
return {execution: toJobExecution(row), changed: true};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface UpdateJobExecutionStatusParams {
|
|
238
|
+
jobExecutionId: string;
|
|
239
|
+
status: JobExecutionStatus;
|
|
240
|
+
expectedVersion: number;
|
|
241
|
+
statusReason?: JobStatusReason | null | undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export async function updateJobExecutionStatus(
|
|
245
|
+
params: UpdateJobExecutionStatusParams,
|
|
246
|
+
): Promise<JobExecution> {
|
|
247
|
+
const statusReason = params.statusReason ?? null;
|
|
248
|
+
const result = await db().transaction(async (tx) => {
|
|
249
|
+
return await optimisticLockRetry({
|
|
250
|
+
updateFn: () =>
|
|
251
|
+
updateJobExecutionStatusAtVersion(tx, {
|
|
252
|
+
jobExecutionId: params.jobExecutionId,
|
|
253
|
+
status: params.status,
|
|
254
|
+
expectedVersion: params.expectedVersion,
|
|
255
|
+
statusReason,
|
|
256
|
+
}),
|
|
257
|
+
fetchFn: async () => {
|
|
258
|
+
const row = (
|
|
259
|
+
await tx
|
|
260
|
+
.select()
|
|
261
|
+
.from(jobExecutions)
|
|
262
|
+
.where(eq(jobExecutions.id, params.jobExecutionId))
|
|
263
|
+
.limit(1)
|
|
264
|
+
)[0];
|
|
265
|
+
return row ? toJobExecution(row) : undefined;
|
|
266
|
+
},
|
|
267
|
+
matchFn: (execution) =>
|
|
268
|
+
(execution.status === params.status && execution.statusReason === statusReason) ||
|
|
269
|
+
TERMINAL_EXECUTION_STATUSES.includes(execution.status)
|
|
270
|
+
? {execution, changed: false}
|
|
271
|
+
: null,
|
|
272
|
+
failureMessage: `Optimistic lock failure: job execution ${params.jobExecutionId} version ${params.expectedVersion}`,
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (result.changed) recordWorkflowJobExecutionStatusChanged(result.execution.status);
|
|
277
|
+
|
|
278
|
+
return result.execution;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export async function recordJobExecutionQueuedAt(params: {
|
|
282
|
+
jobExecutionId: string;
|
|
283
|
+
queuedAt: Date;
|
|
284
|
+
}): Promise<void> {
|
|
285
|
+
const updated = await db()
|
|
286
|
+
.update(jobExecutions)
|
|
287
|
+
.set({queuedAt: params.queuedAt})
|
|
288
|
+
.where(and(eq(jobExecutions.id, params.jobExecutionId), isNull(jobExecutions.queuedAt)))
|
|
289
|
+
.returning({id: jobExecutions.id});
|
|
290
|
+
|
|
291
|
+
if (updated.length > 0) recordWorkflowJobExecutionQueued();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export async function recordJobExecutionStartedAt(params: {
|
|
295
|
+
jobExecutionId: string;
|
|
296
|
+
startedAt: Date;
|
|
297
|
+
}): Promise<void> {
|
|
298
|
+
const updated = await db()
|
|
299
|
+
.update(jobExecutions)
|
|
300
|
+
.set({startedAt: params.startedAt})
|
|
301
|
+
.where(and(eq(jobExecutions.id, params.jobExecutionId), isNull(jobExecutions.startedAt)))
|
|
302
|
+
.returning({id: jobExecutions.id});
|
|
303
|
+
|
|
304
|
+
if (updated.length > 0) recordWorkflowJobExecutionStarted();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export async function failJobExecutionAsTimedOut(params: {
|
|
308
|
+
jobExecutionId: string;
|
|
309
|
+
workflowRunAttemptId: string;
|
|
310
|
+
expectedVersion: number;
|
|
311
|
+
}): Promise<JobExecution> {
|
|
312
|
+
const result = await db().transaction(async (tx) => {
|
|
313
|
+
const updated = await optimisticLockRetry({
|
|
314
|
+
updateFn: () =>
|
|
315
|
+
updateJobExecutionStatusAtVersion(tx, {
|
|
316
|
+
jobExecutionId: params.jobExecutionId,
|
|
317
|
+
status: 'failed',
|
|
318
|
+
expectedVersion: params.expectedVersion,
|
|
319
|
+
statusReason: 'timed_out',
|
|
320
|
+
markTimedOut: true,
|
|
321
|
+
}),
|
|
322
|
+
fetchFn: async () => {
|
|
323
|
+
const row = (
|
|
324
|
+
await tx
|
|
325
|
+
.select()
|
|
326
|
+
.from(jobExecutions)
|
|
327
|
+
.where(eq(jobExecutions.id, params.jobExecutionId))
|
|
328
|
+
.limit(1)
|
|
329
|
+
)[0];
|
|
330
|
+
return row ? toJobExecution(row) : undefined;
|
|
331
|
+
},
|
|
332
|
+
matchFn: (execution) => (execution.timedOutAt !== null ? {execution, changed: false} : null),
|
|
333
|
+
failureMessage: `Optimistic lock failure: job execution ${params.jobExecutionId} version ${params.expectedVersion}`,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
if (updated.changed) {
|
|
337
|
+
const identity = await getWorkflowContextForJob(updated.execution.jobId, tx);
|
|
338
|
+
await writeWorkflowsOutboxEvent(tx, {
|
|
339
|
+
type: WORKFLOWS_JOB_EXECUTION_TIMED_OUT,
|
|
340
|
+
payload: {
|
|
341
|
+
jobId: identity.jobId,
|
|
342
|
+
jobExecutionId: params.jobExecutionId,
|
|
343
|
+
workflowRunAttemptId: identity.workflowRunAttemptId,
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return updated;
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
if (result.changed) {
|
|
352
|
+
recordWorkflowJobExecutionStatusChanged(result.execution.status);
|
|
353
|
+
recordWorkflowJobExecutionTimedOut();
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return result.execution;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export async function resolveJobExecutionAfterLeaseExpiry(params: {
|
|
360
|
+
jobExecutionId: string;
|
|
361
|
+
expectedVersion: number;
|
|
362
|
+
}): Promise<{status: RuntimeCompletionStatus; executionVersion: number}> {
|
|
363
|
+
const result = await db().transaction(async (tx) => {
|
|
364
|
+
const jobExecutionSteps = await getStepsByJobExecutionIdForUpdate(params.jobExecutionId, tx);
|
|
365
|
+
let changedJobExecution: JobExecution | null = null;
|
|
366
|
+
|
|
367
|
+
if (jobExecutionSteps.length === 0) {
|
|
368
|
+
throw new JobNotFoundError(params.jobExecutionId);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (jobExecutionSteps.every((step) => isTerminal(step.status))) {
|
|
372
|
+
const status = deriveCompletion(jobExecutionSteps);
|
|
373
|
+
const updated = await updateJobExecutionStatusAtVersion(tx, {
|
|
374
|
+
jobExecutionId: params.jobExecutionId,
|
|
375
|
+
status,
|
|
376
|
+
expectedVersion: params.expectedVersion,
|
|
377
|
+
statusReason: statusReasonForStepCompletion(status),
|
|
378
|
+
});
|
|
379
|
+
changedJobExecution = updated?.changed ? updated.execution : null;
|
|
380
|
+
} else {
|
|
381
|
+
const updated = await updateJobExecutionStatusAtVersion(tx, {
|
|
382
|
+
jobExecutionId: params.jobExecutionId,
|
|
383
|
+
status: 'failed',
|
|
384
|
+
expectedVersion: params.expectedVersion,
|
|
385
|
+
statusReason: 'runner_lost',
|
|
386
|
+
});
|
|
387
|
+
if (updated?.changed) {
|
|
388
|
+
changedJobExecution = updated.execution;
|
|
389
|
+
await bulkUpdateStepStatuses(
|
|
390
|
+
{jobExecutionId: params.jobExecutionId, status: 'cancelled'},
|
|
391
|
+
tx,
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const jobExecutionRow = (
|
|
397
|
+
await tx
|
|
398
|
+
.select()
|
|
399
|
+
.from(jobExecutions)
|
|
400
|
+
.where(eq(jobExecutions.id, params.jobExecutionId))
|
|
401
|
+
.limit(1)
|
|
402
|
+
)[0];
|
|
403
|
+
if (!jobExecutionRow) {
|
|
404
|
+
throw new Error(`Job execution not found resolving lease expiry: ${params.jobExecutionId}`);
|
|
405
|
+
}
|
|
406
|
+
const status: RuntimeCompletionStatus =
|
|
407
|
+
jobExecutionRow.status === 'succeeded' ? 'succeeded' : 'failed';
|
|
408
|
+
return {status, executionVersion: jobExecutionRow.version, changedJobExecution};
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
recordWorkflowJobExecutionLeaseExpiryResolved(result.status);
|
|
412
|
+
if (result.changedJobExecution) {
|
|
413
|
+
recordWorkflowJobExecutionStatusChanged(result.changedJobExecution.status);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
return {status: result.status, executionVersion: result.executionVersion};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
function statusReasonForStepCompletion(status: RuntimeCompletionStatus): JobStatusReason | null {
|
|
420
|
+
return status === 'failed' ? 'step_failed' : null;
|
|
421
|
+
}
|