@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,564 @@
|
|
|
1
|
+
import type {AgentDefaultsResolver} from '@shipfox/api-agent/core/resolve-agent-config';
|
|
2
|
+
import {
|
|
3
|
+
WORKFLOWS_JOB_ACTIVATED,
|
|
4
|
+
type WorkflowsJobActivatedEventDto,
|
|
5
|
+
} from '@shipfox/api-workflows-dto';
|
|
6
|
+
import {and, asc, count, eq, inArray, isNull, notInArray, sql} from 'drizzle-orm';
|
|
7
|
+
import {loadAgentToolMaterializationContext} from '#core/agent-tools.js';
|
|
8
|
+
import {isJobTerminal, type JobStatus, type ResolutionReason} from '#core/entities/job.js';
|
|
9
|
+
import type {JobExecutionStatus, WorkflowExecutionEvent} from '#core/entities/job-execution.js';
|
|
10
|
+
import {type DeriveJobSuccessResult, deriveJobSuccess} from '#core/job-transition/index.js';
|
|
11
|
+
import {
|
|
12
|
+
type MaterializedListenerExecution,
|
|
13
|
+
materializeListenerExecution,
|
|
14
|
+
} from '#core/listener-execution-materialization.js';
|
|
15
|
+
import {
|
|
16
|
+
applyListenerFilterSnapshots,
|
|
17
|
+
assembleListenerSnapshotContext,
|
|
18
|
+
type ListenerTriggerWithSnapshot,
|
|
19
|
+
planListenerFilterSnapshots,
|
|
20
|
+
} from '#core/step-config/assemble-run-context.js';
|
|
21
|
+
import {
|
|
22
|
+
recordListenerEventsCoalesced,
|
|
23
|
+
recordWorkflowJobExecutionStatusChanged,
|
|
24
|
+
recordWorkflowListenerResolved,
|
|
25
|
+
} from '#metrics/instance.js';
|
|
26
|
+
import {db, type Tx} from './db.js';
|
|
27
|
+
import {writeWorkflowsOutboxEvent} from './outbox-writes.js';
|
|
28
|
+
import {type JobExecutionDb, jobExecutions, toJobExecution} from './schema/job-executions.js';
|
|
29
|
+
import {type JobListenerEventDb, jobListenerEvents} from './schema/job-listener-events.js';
|
|
30
|
+
import {jobs, toJob} from './schema/jobs.js';
|
|
31
|
+
import {steps} from './schema/steps.js';
|
|
32
|
+
import {workflowRunAttempts} from './schema/workflow-run-attempts.js';
|
|
33
|
+
import {toWorkflowRun, workflowRuns} from './schema/workflow-runs.js';
|
|
34
|
+
import {
|
|
35
|
+
bulkUpdateStepStatuses,
|
|
36
|
+
getDirectDependencyJobContexts,
|
|
37
|
+
updateJobStatusAtVersion,
|
|
38
|
+
} from './workflow-runs.js';
|
|
39
|
+
|
|
40
|
+
const TERMINAL_EXECUTION_STATUSES: JobExecutionStatus[] = ['succeeded', 'failed', 'cancelled'];
|
|
41
|
+
const MAX_LISTENER_RESOLUTION_ATTEMPTS = 3;
|
|
42
|
+
|
|
43
|
+
export interface ActivateJobListenerParams {
|
|
44
|
+
jobId: string;
|
|
45
|
+
expectedVersion: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ActivateJobListenerResult {
|
|
49
|
+
status: 'running' | 'terminal';
|
|
50
|
+
jobStatus: JobStatus;
|
|
51
|
+
jobVersion: number;
|
|
52
|
+
executionCount: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type JobActivatedListenerMatcher = Extract<
|
|
56
|
+
WorkflowsJobActivatedEventDto,
|
|
57
|
+
{mode: 'listening'}
|
|
58
|
+
>['on'][number] &
|
|
59
|
+
ListenerTriggerWithSnapshot;
|
|
60
|
+
|
|
61
|
+
function applyActivatedListenerFilterSnapshots(
|
|
62
|
+
plans: Parameters<typeof applyListenerFilterSnapshots>[0],
|
|
63
|
+
context: Parameters<typeof applyListenerFilterSnapshots>[1],
|
|
64
|
+
): JobActivatedListenerMatcher[] {
|
|
65
|
+
return applyListenerFilterSnapshots(plans, context);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function activateJobListener(
|
|
69
|
+
params: ActivateJobListenerParams,
|
|
70
|
+
): Promise<ActivateJobListenerResult> {
|
|
71
|
+
return await db().transaction(async (tx) => {
|
|
72
|
+
const [target] = await tx
|
|
73
|
+
.select({job: jobs, run: workflowRuns})
|
|
74
|
+
.from(jobs)
|
|
75
|
+
.innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))
|
|
76
|
+
.innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))
|
|
77
|
+
.where(eq(jobs.id, params.jobId))
|
|
78
|
+
.limit(1)
|
|
79
|
+
.for('update');
|
|
80
|
+
if (!target) throw new Error(`Job not found: ${params.jobId}`);
|
|
81
|
+
|
|
82
|
+
const [{value: executionCount} = {value: 0}] = await tx
|
|
83
|
+
.select({value: count()})
|
|
84
|
+
.from(jobExecutions)
|
|
85
|
+
.where(eq(jobExecutions.jobId, params.jobId));
|
|
86
|
+
|
|
87
|
+
if (['succeeded', 'failed', 'cancelled', 'skipped'].includes(target.job.status)) {
|
|
88
|
+
return {
|
|
89
|
+
status: 'terminal',
|
|
90
|
+
jobStatus: target.job.status,
|
|
91
|
+
jobVersion: target.job.version,
|
|
92
|
+
executionCount,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let job = toJob(target.job);
|
|
97
|
+
if (target.job.status === 'pending') {
|
|
98
|
+
const updated = await updateJobStatusAtVersion(tx, {
|
|
99
|
+
jobId: params.jobId,
|
|
100
|
+
status: 'running',
|
|
101
|
+
expectedVersion: params.expectedVersion,
|
|
102
|
+
});
|
|
103
|
+
if (!updated) {
|
|
104
|
+
const [existing] = await tx.select().from(jobs).where(eq(jobs.id, params.jobId)).limit(1);
|
|
105
|
+
if (existing?.status !== 'running') {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Optimistic lock failure activating listener job ${params.jobId} version ${params.expectedVersion}`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
job = toJob(existing);
|
|
111
|
+
} else {
|
|
112
|
+
job = updated.job;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const listenerRows = await tx
|
|
117
|
+
.update(jobs)
|
|
118
|
+
.set({listenerStatus: 'listening', updatedAt: new Date()})
|
|
119
|
+
.where(and(eq(jobs.id, params.jobId), eq(jobs.listenerStatus, 'inactive')))
|
|
120
|
+
.returning();
|
|
121
|
+
|
|
122
|
+
if (listenerRows[0]) {
|
|
123
|
+
const matchers = {
|
|
124
|
+
on: target.job.listeningOn ?? [],
|
|
125
|
+
until: target.job.listeningUntil ?? null,
|
|
126
|
+
};
|
|
127
|
+
const snapshotPlan = planListenerFilterSnapshots(matchers);
|
|
128
|
+
const dependencyJobs =
|
|
129
|
+
snapshotPlan.jobKeys.size === 0
|
|
130
|
+
? []
|
|
131
|
+
: await getDirectDependencyJobContexts(params.jobId, tx);
|
|
132
|
+
const snapshotContext = assembleListenerSnapshotContext({
|
|
133
|
+
job: toJob(target.job),
|
|
134
|
+
run: toWorkflowRun(target.run),
|
|
135
|
+
triggerPayload: target.run.triggerPayload,
|
|
136
|
+
inputs: target.run.inputs,
|
|
137
|
+
plan: snapshotPlan,
|
|
138
|
+
dependencyJobs,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
await writeWorkflowsOutboxEvent(tx, {
|
|
142
|
+
type: WORKFLOWS_JOB_ACTIVATED,
|
|
143
|
+
payload: {
|
|
144
|
+
jobId: params.jobId,
|
|
145
|
+
workflowRunId: target.run.id,
|
|
146
|
+
workspaceId: target.run.workspaceId,
|
|
147
|
+
mode: 'listening',
|
|
148
|
+
on: applyActivatedListenerFilterSnapshots(snapshotPlan.on, snapshotContext),
|
|
149
|
+
until:
|
|
150
|
+
matchers.until === null
|
|
151
|
+
? null
|
|
152
|
+
: applyActivatedListenerFilterSnapshots(snapshotPlan.until, snapshotContext),
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {status: 'running', jobStatus: job.status, jobVersion: job.version, executionCount};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type DrainListenerEventsResult =
|
|
162
|
+
| {
|
|
163
|
+
kind: 'execution';
|
|
164
|
+
jobExecutionId: string;
|
|
165
|
+
executionVersion: number;
|
|
166
|
+
sequence: number;
|
|
167
|
+
requiredLabels: string[];
|
|
168
|
+
status: JobExecutionStatus;
|
|
169
|
+
}
|
|
170
|
+
| {kind: 'resolve-requested'}
|
|
171
|
+
| {kind: 'empty'};
|
|
172
|
+
|
|
173
|
+
export interface DrainListenerEventsParams {
|
|
174
|
+
jobId: string;
|
|
175
|
+
expectedSequence: number;
|
|
176
|
+
maxSize?: number | undefined;
|
|
177
|
+
resolveAgentDefaults?: AgentDefaultsResolver | undefined;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export async function drainListenerEventsIntoExecution(
|
|
181
|
+
params: DrainListenerEventsParams,
|
|
182
|
+
): Promise<DrainListenerEventsResult> {
|
|
183
|
+
const drained = await db().transaction(async (tx) => {
|
|
184
|
+
const existing = await findExistingExecution(params, tx);
|
|
185
|
+
if (existing) return {result: existing};
|
|
186
|
+
|
|
187
|
+
const resolveRequested = await hasPendingResolveEvent(params.jobId, tx);
|
|
188
|
+
if (resolveRequested) return {result: {kind: 'resolve-requested' as const}};
|
|
189
|
+
|
|
190
|
+
const bufferedEvents = await lockBufferedFireEvents(params, tx);
|
|
191
|
+
if (bufferedEvents.length === 0) return {result: {kind: 'empty' as const}};
|
|
192
|
+
|
|
193
|
+
const target = await loadListenerMaterializationTarget(params.jobId, tx);
|
|
194
|
+
const agentToolContext =
|
|
195
|
+
target.attempt.agentToolMaterialization === null
|
|
196
|
+
? await loadAgentToolMaterializationContext({
|
|
197
|
+
model: target.attempt.model,
|
|
198
|
+
workspaceId: target.run.workspaceId,
|
|
199
|
+
projectId: target.run.projectId,
|
|
200
|
+
})
|
|
201
|
+
: undefined;
|
|
202
|
+
const materialized = materializeListenerExecution({
|
|
203
|
+
model: target.attempt.model,
|
|
204
|
+
run: toWorkflowRun(target.run),
|
|
205
|
+
job: toJob(target.job),
|
|
206
|
+
sequence: params.expectedSequence,
|
|
207
|
+
triggerEvents: listenerTriggerEvents(bufferedEvents),
|
|
208
|
+
priorExecutions: target.priorExecutions,
|
|
209
|
+
resolveAgentDefaults: params.resolveAgentDefaults,
|
|
210
|
+
agentToolContext,
|
|
211
|
+
agentToolSnapshot: target.attempt.agentToolMaterialization,
|
|
212
|
+
});
|
|
213
|
+
const execution = await persistMaterializedListenerExecution(tx, {
|
|
214
|
+
jobId: params.jobId,
|
|
215
|
+
sequence: params.expectedSequence,
|
|
216
|
+
bufferedEventIds: bufferedEvents.map((event) => event.id),
|
|
217
|
+
materialized,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
if (materialized.status === 'failed') {
|
|
221
|
+
recordWorkflowJobExecutionStatusChanged(materialized.status);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
result: drainExecutionResult(execution),
|
|
226
|
+
batchSize: bufferedEvents.length,
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
if (drained.result.kind === 'execution' && drained.batchSize !== undefined) {
|
|
231
|
+
recordListenerEventsCoalesced(drained.batchSize);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return drained.result;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface ListenerBufferPeek {
|
|
238
|
+
fireCount: number;
|
|
239
|
+
resolvePending: boolean;
|
|
240
|
+
oldestAgeMs: number;
|
|
241
|
+
newestAgeMs: number;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export async function peekListenerBuffer(params: {jobId: string}): Promise<ListenerBufferPeek> {
|
|
245
|
+
const [row] = await db()
|
|
246
|
+
.select({
|
|
247
|
+
fireCount: sql<number>`count(*) filter (where ${jobListenerEvents.disposition} = 'fire')::integer`,
|
|
248
|
+
resolvePending: sql<boolean>`coalesce(bool_or(${jobListenerEvents.disposition} = 'resolve'), false)`,
|
|
249
|
+
oldestAgeMs: sql<number>`coalesce(floor(extract(epoch from (statement_timestamp() - min(${jobListenerEvents.receivedAt}) filter (where ${jobListenerEvents.disposition} = 'fire'))) * 1000), 0)::integer`,
|
|
250
|
+
newestAgeMs: sql<number>`coalesce(floor(extract(epoch from (statement_timestamp() - max(${jobListenerEvents.receivedAt}) filter (where ${jobListenerEvents.disposition} = 'fire'))) * 1000), 0)::integer`,
|
|
251
|
+
})
|
|
252
|
+
.from(jobListenerEvents)
|
|
253
|
+
.where(
|
|
254
|
+
and(
|
|
255
|
+
eq(jobListenerEvents.jobId, params.jobId),
|
|
256
|
+
isNull(jobListenerEvents.consumedByExecutionId),
|
|
257
|
+
),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
fireCount: row?.fireCount ?? 0,
|
|
262
|
+
resolvePending: row?.resolvePending ?? false,
|
|
263
|
+
oldestAgeMs: row?.oldestAgeMs ?? 0,
|
|
264
|
+
newestAgeMs: row?.newestAgeMs ?? 0,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export async function resolveJobListener(params: {
|
|
269
|
+
jobId: string;
|
|
270
|
+
reason: ResolutionReason;
|
|
271
|
+
}): Promise<{status: 'succeeded' | 'failed'; jobVersion: number}> {
|
|
272
|
+
let result: ApplyJobListenerResolutionResult | undefined;
|
|
273
|
+
for (let attempt = 0; attempt < MAX_LISTENER_RESOLUTION_ATTEMPTS; attempt += 1) {
|
|
274
|
+
const decision = await deriveJobListenerResolutionDecision(params.jobId);
|
|
275
|
+
result = await applyJobListenerResolution(params, decision);
|
|
276
|
+
if (result.kind === 'applied') break;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (result?.kind !== 'applied') {
|
|
280
|
+
throw new Error(`Optimistic lock failure resolving listener job ${params.jobId}`);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (result.changed) recordWorkflowListenerResolved(params.reason);
|
|
284
|
+
return {status: result.status, jobVersion: result.jobVersion};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
type JobListenerResolutionDecision = DeriveJobSuccessResult & {
|
|
288
|
+
expectedVersion: number;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
type ApplyJobListenerResolutionResult =
|
|
292
|
+
| {
|
|
293
|
+
kind: 'applied';
|
|
294
|
+
status: 'succeeded' | 'failed';
|
|
295
|
+
jobVersion: number;
|
|
296
|
+
changed: boolean;
|
|
297
|
+
}
|
|
298
|
+
| {kind: 'stale'};
|
|
299
|
+
|
|
300
|
+
async function deriveJobListenerResolutionDecision(
|
|
301
|
+
jobId: string,
|
|
302
|
+
): Promise<JobListenerResolutionDecision> {
|
|
303
|
+
const [jobRow] = await db().select().from(jobs).where(eq(jobs.id, jobId)).limit(1);
|
|
304
|
+
if (!jobRow) throw new Error(`Job not found: ${jobId}`);
|
|
305
|
+
|
|
306
|
+
const [executionRows, dependencyJobs] = await Promise.all([
|
|
307
|
+
db()
|
|
308
|
+
.select()
|
|
309
|
+
.from(jobExecutions)
|
|
310
|
+
.where(eq(jobExecutions.jobId, jobId))
|
|
311
|
+
.orderBy(asc(jobExecutions.sequence), asc(jobExecutions.id)),
|
|
312
|
+
getDirectDependencyJobContexts(jobId),
|
|
313
|
+
]);
|
|
314
|
+
return {
|
|
315
|
+
expectedVersion: jobRow.version,
|
|
316
|
+
...deriveJobSuccess({
|
|
317
|
+
success: jobRow.success,
|
|
318
|
+
executions: executionRows.map(toJobExecution),
|
|
319
|
+
jobs: dependencyJobs,
|
|
320
|
+
}),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async function applyJobListenerResolution(
|
|
325
|
+
params: {
|
|
326
|
+
jobId: string;
|
|
327
|
+
reason: ResolutionReason;
|
|
328
|
+
},
|
|
329
|
+
decision: JobListenerResolutionDecision,
|
|
330
|
+
): Promise<ApplyJobListenerResolutionResult> {
|
|
331
|
+
return await db().transaction(async (tx) => {
|
|
332
|
+
const [jobRow] = await tx
|
|
333
|
+
.select()
|
|
334
|
+
.from(jobs)
|
|
335
|
+
.where(eq(jobs.id, params.jobId))
|
|
336
|
+
.limit(1)
|
|
337
|
+
.for('update');
|
|
338
|
+
if (!jobRow) throw new Error(`Job not found: ${params.jobId}`);
|
|
339
|
+
|
|
340
|
+
if (jobRow.version !== decision.expectedVersion && !isJobTerminal(jobRow.status)) {
|
|
341
|
+
return {kind: 'stale' as const};
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const listenerRows = await tx
|
|
345
|
+
.update(jobs)
|
|
346
|
+
.set({
|
|
347
|
+
listenerStatus: 'resolved',
|
|
348
|
+
resolutionReason: params.reason,
|
|
349
|
+
updatedAt: new Date(),
|
|
350
|
+
})
|
|
351
|
+
.where(and(eq(jobs.id, params.jobId), notInArray(jobs.listenerStatus, ['resolved'])))
|
|
352
|
+
.returning({id: jobs.id});
|
|
353
|
+
|
|
354
|
+
const updated = await updateJobStatusAtVersion(tx, {
|
|
355
|
+
jobId: params.jobId,
|
|
356
|
+
status: decision.status,
|
|
357
|
+
expectedVersion: decision.expectedVersion,
|
|
358
|
+
statusReason: decision.statusReason,
|
|
359
|
+
evaluationTrace: decision.trace,
|
|
360
|
+
});
|
|
361
|
+
const job = updated?.job ?? toJob(jobRow);
|
|
362
|
+
const resolvedStatus: 'succeeded' | 'failed' =
|
|
363
|
+
job.status === 'succeeded' ? 'succeeded' : 'failed';
|
|
364
|
+
return {
|
|
365
|
+
kind: 'applied' as const,
|
|
366
|
+
status: resolvedStatus,
|
|
367
|
+
jobVersion: job.version,
|
|
368
|
+
changed: listenerRows.length > 0 || updated?.changed === true,
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export async function settleListenerJobExecution(params: {
|
|
374
|
+
jobExecutionId: string;
|
|
375
|
+
status: Extract<JobExecutionStatus, 'failed' | 'cancelled'>;
|
|
376
|
+
}): Promise<void> {
|
|
377
|
+
const changed = await db().transaction(async (tx) => {
|
|
378
|
+
const [execution] = await tx
|
|
379
|
+
.update(jobExecutions)
|
|
380
|
+
.set({
|
|
381
|
+
status: params.status,
|
|
382
|
+
statusReason: params.status === 'failed' ? 'step_failed' : 'run_cancelled',
|
|
383
|
+
version: sql`${jobExecutions.version} + 1`,
|
|
384
|
+
updatedAt: new Date(),
|
|
385
|
+
finishedAt: sql`now()`,
|
|
386
|
+
})
|
|
387
|
+
.where(
|
|
388
|
+
and(
|
|
389
|
+
eq(jobExecutions.id, params.jobExecutionId),
|
|
390
|
+
notInArray(jobExecutions.status, TERMINAL_EXECUTION_STATUSES),
|
|
391
|
+
),
|
|
392
|
+
)
|
|
393
|
+
.returning();
|
|
394
|
+
if (!execution) return false;
|
|
395
|
+
await bulkUpdateStepStatuses(
|
|
396
|
+
{jobExecutionId: params.jobExecutionId, status: params.status},
|
|
397
|
+
tx,
|
|
398
|
+
);
|
|
399
|
+
return true;
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
if (changed) {
|
|
403
|
+
recordWorkflowJobExecutionStatusChanged(params.status);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export async function countActiveListeners(): Promise<number> {
|
|
408
|
+
const [row] = await db()
|
|
409
|
+
.select({value: count()})
|
|
410
|
+
.from(jobs)
|
|
411
|
+
.where(eq(jobs.listenerStatus, 'listening'));
|
|
412
|
+
return row?.value ?? 0;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
async function findExistingExecution(
|
|
416
|
+
params: DrainListenerEventsParams,
|
|
417
|
+
tx: Tx,
|
|
418
|
+
): Promise<Extract<DrainListenerEventsResult, {kind: 'execution'}> | undefined> {
|
|
419
|
+
const [existing] = await tx
|
|
420
|
+
.select()
|
|
421
|
+
.from(jobExecutions)
|
|
422
|
+
.where(
|
|
423
|
+
and(
|
|
424
|
+
eq(jobExecutions.jobId, params.jobId),
|
|
425
|
+
eq(jobExecutions.sequence, params.expectedSequence),
|
|
426
|
+
),
|
|
427
|
+
)
|
|
428
|
+
.limit(1);
|
|
429
|
+
if (!existing) return undefined;
|
|
430
|
+
return drainExecutionResult(existing);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async function hasPendingResolveEvent(jobId: string, tx: Tx): Promise<boolean> {
|
|
434
|
+
const [resolveEvent] = await tx
|
|
435
|
+
.select({id: jobListenerEvents.id})
|
|
436
|
+
.from(jobListenerEvents)
|
|
437
|
+
.where(
|
|
438
|
+
and(
|
|
439
|
+
eq(jobListenerEvents.jobId, jobId),
|
|
440
|
+
eq(jobListenerEvents.disposition, 'resolve'),
|
|
441
|
+
isNull(jobListenerEvents.consumedByExecutionId),
|
|
442
|
+
),
|
|
443
|
+
)
|
|
444
|
+
.orderBy(asc(jobListenerEvents.receivedAt), asc(jobListenerEvents.id))
|
|
445
|
+
.limit(1)
|
|
446
|
+
.for('update');
|
|
447
|
+
return resolveEvent !== undefined;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async function lockBufferedFireEvents(
|
|
451
|
+
params: DrainListenerEventsParams,
|
|
452
|
+
tx: Tx,
|
|
453
|
+
): Promise<JobListenerEventDb[]> {
|
|
454
|
+
const bufferedQuery = tx
|
|
455
|
+
.select()
|
|
456
|
+
.from(jobListenerEvents)
|
|
457
|
+
.where(
|
|
458
|
+
and(
|
|
459
|
+
eq(jobListenerEvents.jobId, params.jobId),
|
|
460
|
+
eq(jobListenerEvents.disposition, 'fire'),
|
|
461
|
+
isNull(jobListenerEvents.consumedByExecutionId),
|
|
462
|
+
),
|
|
463
|
+
)
|
|
464
|
+
.orderBy(asc(jobListenerEvents.receivedAt), asc(jobListenerEvents.id));
|
|
465
|
+
return await (params.maxSize === undefined
|
|
466
|
+
? bufferedQuery
|
|
467
|
+
: bufferedQuery.limit(params.maxSize)
|
|
468
|
+
).for('update');
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function listenerTriggerEvents(
|
|
472
|
+
bufferedEvents: readonly JobListenerEventDb[],
|
|
473
|
+
): WorkflowExecutionEvent[] {
|
|
474
|
+
return bufferedEvents.map((event) => ({
|
|
475
|
+
source: event.source,
|
|
476
|
+
event: event.event,
|
|
477
|
+
delivery_id: event.deliveryId,
|
|
478
|
+
received_at: event.receivedAt.toISOString(),
|
|
479
|
+
data: event.payload,
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
async function persistMaterializedListenerExecution(
|
|
484
|
+
tx: Tx,
|
|
485
|
+
params: {
|
|
486
|
+
readonly jobId: string;
|
|
487
|
+
readonly sequence: number;
|
|
488
|
+
readonly bufferedEventIds: readonly string[];
|
|
489
|
+
readonly materialized: MaterializedListenerExecution;
|
|
490
|
+
},
|
|
491
|
+
): Promise<JobExecutionDb> {
|
|
492
|
+
const [execution] = await tx
|
|
493
|
+
.insert(jobExecutions)
|
|
494
|
+
.values({
|
|
495
|
+
jobId: params.jobId,
|
|
496
|
+
sequence: params.sequence,
|
|
497
|
+
name: params.materialized.name,
|
|
498
|
+
runner: params.materialized.runner.length === 0 ? null : [...params.materialized.runner],
|
|
499
|
+
status: params.materialized.status,
|
|
500
|
+
statusReason: params.materialized.statusReason,
|
|
501
|
+
triggerEvents: [...params.materialized.triggerEvents],
|
|
502
|
+
evaluationTrace: params.materialized.evaluationTrace,
|
|
503
|
+
...(params.materialized.status === 'failed' ? {finishedAt: sql`now()`} : {}),
|
|
504
|
+
})
|
|
505
|
+
.returning();
|
|
506
|
+
if (!execution) throw new Error('Insert returned no rows');
|
|
507
|
+
|
|
508
|
+
await tx
|
|
509
|
+
.update(jobListenerEvents)
|
|
510
|
+
.set({consumedByExecutionId: execution.id})
|
|
511
|
+
.where(inArray(jobListenerEvents.id, [...params.bufferedEventIds]));
|
|
512
|
+
|
|
513
|
+
if (params.materialized.status === 'pending' && params.materialized.steps.length > 0) {
|
|
514
|
+
await tx.insert(steps).values(
|
|
515
|
+
params.materialized.steps.map((step) => ({
|
|
516
|
+
jobExecutionId: execution.id,
|
|
517
|
+
key: step.key,
|
|
518
|
+
name: step.name,
|
|
519
|
+
sourceLocation: step.sourceLocation,
|
|
520
|
+
status: step.status,
|
|
521
|
+
type: step.type,
|
|
522
|
+
config: step.config,
|
|
523
|
+
configPlan: step.configPlan ?? null,
|
|
524
|
+
authoredConfig: step.authoredConfig,
|
|
525
|
+
condition: step.condition ?? null,
|
|
526
|
+
position: step.position,
|
|
527
|
+
})),
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
return execution;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
function drainExecutionResult(
|
|
535
|
+
execution: JobExecutionDb,
|
|
536
|
+
): Extract<DrainListenerEventsResult, {kind: 'execution'}> {
|
|
537
|
+
return {
|
|
538
|
+
kind: 'execution',
|
|
539
|
+
jobExecutionId: execution.id,
|
|
540
|
+
executionVersion: execution.version,
|
|
541
|
+
sequence: execution.sequence,
|
|
542
|
+
requiredLabels: execution.runner ?? [],
|
|
543
|
+
status: execution.status,
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
async function loadListenerMaterializationTarget(jobId: string, tx: Tx) {
|
|
548
|
+
const [target] = await tx
|
|
549
|
+
.select({job: jobs, attempt: workflowRunAttempts, run: workflowRuns})
|
|
550
|
+
.from(jobs)
|
|
551
|
+
.innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))
|
|
552
|
+
.innerJoin(workflowRuns, eq(workflowRunAttempts.workflowRunId, workflowRuns.id))
|
|
553
|
+
.where(eq(jobs.id, jobId))
|
|
554
|
+
.limit(1)
|
|
555
|
+
.for('update');
|
|
556
|
+
if (!target) throw new Error(`Job not found: ${jobId}`);
|
|
557
|
+
|
|
558
|
+
const priorExecutions = await tx
|
|
559
|
+
.select()
|
|
560
|
+
.from(jobExecutions)
|
|
561
|
+
.where(eq(jobExecutions.jobId, jobId))
|
|
562
|
+
.orderBy(asc(jobExecutions.sequence), asc(jobExecutions.id));
|
|
563
|
+
return {...target, priorExecutions: priorExecutions.map(toJobExecution)};
|
|
564
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type {WorkflowsEventMapDto} from '@shipfox/api-workflows-dto';
|
|
2
|
+
import {writeOutboxEvent, writeOutboxEvents} from '@shipfox/node-outbox';
|
|
3
|
+
import type {Tx} from './db.js';
|
|
4
|
+
import {workflowsOutbox} from './schema/outbox.js';
|
|
5
|
+
|
|
6
|
+
type WorkflowsOutboxEvent = {
|
|
7
|
+
[K in keyof WorkflowsEventMapDto & string]: {
|
|
8
|
+
type: K;
|
|
9
|
+
payload: WorkflowsEventMapDto[K];
|
|
10
|
+
};
|
|
11
|
+
}[keyof WorkflowsEventMapDto & string];
|
|
12
|
+
|
|
13
|
+
export async function writeWorkflowsOutboxEvent(
|
|
14
|
+
tx: Tx,
|
|
15
|
+
event: WorkflowsOutboxEvent,
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
await writeOutboxEvent<WorkflowsEventMapDto>(tx, workflowsOutbox, {
|
|
18
|
+
...event,
|
|
19
|
+
orderingKey: workflowRunOrderingKey(event),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function writeWorkflowsOutboxEvents(
|
|
24
|
+
tx: Tx,
|
|
25
|
+
events: WorkflowsOutboxEvent[],
|
|
26
|
+
): Promise<void> {
|
|
27
|
+
await writeOutboxEvents<WorkflowsEventMapDto>(
|
|
28
|
+
tx,
|
|
29
|
+
workflowsOutbox,
|
|
30
|
+
events.map((event) => ({
|
|
31
|
+
...event,
|
|
32
|
+
orderingKey: workflowRunOrderingKey(event),
|
|
33
|
+
})),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function workflowRunOrderingKey(event: WorkflowsOutboxEvent): string | undefined {
|
|
38
|
+
const workflowRunId = (event.payload as {workflowRunId?: unknown}).workflowRunId;
|
|
39
|
+
return typeof workflowRunId === 'string' ? workflowRunId : undefined;
|
|
40
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {and, desc, eq} from 'drizzle-orm';
|
|
2
|
+
import {db} from '#db/db.js';
|
|
3
|
+
import {jobExecutions} from '#db/schema/job-executions.js';
|
|
4
|
+
import {jobs} from '#db/schema/jobs.js';
|
|
5
|
+
import {workflowRunAttempts} from '#db/schema/workflow-run-attempts.js';
|
|
6
|
+
import {createRerunWorkflowRun, getWorkflowRunByAttemptId} from '#db/workflow-runs.js';
|
|
7
|
+
import {jobFactory} from '#test/index.js';
|
|
8
|
+
|
|
9
|
+
describe('createRerunWorkflowRun with a failed listener', () => {
|
|
10
|
+
it('re-creates the listener fresh without carrying it over', async () => {
|
|
11
|
+
const job = await jobFactory.create({}, {transient: {status: 'failed'}});
|
|
12
|
+
await db()
|
|
13
|
+
.update(jobs)
|
|
14
|
+
.set({
|
|
15
|
+
mode: 'listening',
|
|
16
|
+
status: 'failed',
|
|
17
|
+
statusReason: 'timed_out',
|
|
18
|
+
listenerStatus: 'resolved',
|
|
19
|
+
resolutionReason: 'timeout',
|
|
20
|
+
maxExecutions: 5,
|
|
21
|
+
onResolve: 'cancel',
|
|
22
|
+
})
|
|
23
|
+
.where(eq(jobs.id, job.id));
|
|
24
|
+
await db()
|
|
25
|
+
.update(workflowRunAttempts)
|
|
26
|
+
.set({status: 'failed'})
|
|
27
|
+
.where(eq(workflowRunAttempts.id, job.workflowRunAttemptId));
|
|
28
|
+
const sourceRun = await getWorkflowRunByAttemptId(job.workflowRunAttemptId);
|
|
29
|
+
if (!sourceRun) throw new Error('source run not found');
|
|
30
|
+
|
|
31
|
+
const rerun = await createRerunWorkflowRun({
|
|
32
|
+
workflowRunId: sourceRun.id,
|
|
33
|
+
mode: 'failed',
|
|
34
|
+
actorUserId: crypto.randomUUID(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const [newAttempt] = await db()
|
|
38
|
+
.select()
|
|
39
|
+
.from(workflowRunAttempts)
|
|
40
|
+
.where(eq(workflowRunAttempts.workflowRunId, rerun.id))
|
|
41
|
+
.orderBy(desc(workflowRunAttempts.attempt))
|
|
42
|
+
.limit(1);
|
|
43
|
+
if (!newAttempt) throw new Error('new attempt not found');
|
|
44
|
+
const [clonedJob] = await db()
|
|
45
|
+
.select()
|
|
46
|
+
.from(jobs)
|
|
47
|
+
.where(and(eq(jobs.workflowRunAttemptId, newAttempt.id), eq(jobs.mode, 'listening')));
|
|
48
|
+
if (!clonedJob) throw new Error('cloned listener job not found');
|
|
49
|
+
const clonedExecutions = await db()
|
|
50
|
+
.select()
|
|
51
|
+
.from(jobExecutions)
|
|
52
|
+
.where(eq(jobExecutions.jobId, clonedJob.id));
|
|
53
|
+
|
|
54
|
+
expect(clonedJob.status).toBe('pending');
|
|
55
|
+
expect(clonedJob.carriedOver).toBe(false);
|
|
56
|
+
expect(clonedJob.listenerStatus).toBe('inactive');
|
|
57
|
+
expect(clonedJob.resolutionReason).toBeNull();
|
|
58
|
+
// Listener config carries over so the retried run behaves identically.
|
|
59
|
+
expect(clonedJob.maxExecutions).toBe(5);
|
|
60
|
+
expect(clonedJob.onResolve).toBe('cancel');
|
|
61
|
+
// A fresh listener starts with no firings to re-run.
|
|
62
|
+
expect(clonedExecutions).toHaveLength(0);
|
|
63
|
+
});
|
|
64
|
+
});
|