@temelj/workflow 0.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/attributes.d.mts +15 -0
- package/dist/attributes.mjs +30 -0
- package/dist/client/create.d.mts +31 -0
- package/dist/client/create.mjs +67 -0
- package/dist/client/facades.d.mts +21 -0
- package/dist/client/facades.mjs +142 -0
- package/dist/client/mod.d.mts +2 -0
- package/dist/client/mod.mjs +2 -0
- package/dist/client/run-handle.d.mts +66 -0
- package/dist/client/run-handle.mjs +156 -0
- package/dist/client/worker-options.d.mts +17 -0
- package/dist/client/worker-options.mjs +25 -0
- package/dist/collection.d.mts +15 -0
- package/dist/collection.mjs +33 -0
- package/dist/compiled-function.d.mts +27 -0
- package/dist/compiled-function.mjs +54 -0
- package/dist/definition.d.mts +37 -0
- package/dist/definition.mjs +83 -0
- package/dist/engine/child-workflow.d.mts +10 -0
- package/dist/engine/child-workflow.mjs +333 -0
- package/dist/engine/command-identity.d.mts +9 -0
- package/dist/engine/command-identity.mjs +14 -0
- package/dist/engine/create.d.mts +106 -0
- package/dist/engine/create.mjs +402 -0
- package/dist/engine/deterministic.d.mts +12 -0
- package/dist/engine/deterministic.mjs +102 -0
- package/dist/engine/durable-command.d.mts +10 -0
- package/dist/engine/durable-command.mjs +17 -0
- package/dist/engine/execution-api.d.mts +29 -0
- package/dist/engine/execution-api.mjs +33 -0
- package/dist/engine/execution-service.d.mts +41 -0
- package/dist/engine/execution-service.mjs +288 -0
- package/dist/engine/hooks.d.mts +56 -0
- package/dist/engine/hooks.mjs +237 -0
- package/dist/engine/inspection-api.d.mts +34 -0
- package/dist/engine/inspection-api.mjs +77 -0
- package/dist/engine/inspection.d.mts +18 -0
- package/dist/engine/inspection.mjs +149 -0
- package/dist/engine/lifecycle.d.mts +18 -0
- package/dist/engine/lifecycle.mjs +38 -0
- package/dist/engine/lock-replay.d.mts +30 -0
- package/dist/engine/lock-replay.mjs +38 -0
- package/dist/engine/lock.d.mts +21 -0
- package/dist/engine/lock.mjs +197 -0
- package/dist/engine/message.d.mts +47 -0
- package/dist/engine/message.mjs +357 -0
- package/dist/engine/mod.d.mts +4 -0
- package/dist/engine/mod.mjs +2 -0
- package/dist/engine/observation.d.mts +35 -0
- package/dist/engine/observation.mjs +201 -0
- package/dist/engine/recovery.d.mts +26 -0
- package/dist/engine/recovery.mjs +92 -0
- package/dist/engine/replay.d.mts +41 -0
- package/dist/engine/replay.mjs +122 -0
- package/dist/engine/retry-policy.d.mts +4 -0
- package/dist/engine/retry-policy.mjs +4 -0
- package/dist/engine/retry.d.mts +23 -0
- package/dist/engine/retry.mjs +75 -0
- package/dist/engine/run-data.d.mts +9 -0
- package/dist/engine/run-data.mjs +74 -0
- package/dist/engine/run-service.d.mts +38 -0
- package/dist/engine/run-service.mjs +133 -0
- package/dist/engine/run-utils.d.mts +16 -0
- package/dist/engine/run-utils.mjs +83 -0
- package/dist/engine/schedule.d.mts +25 -0
- package/dist/engine/schedule.mjs +207 -0
- package/dist/engine/serialization.d.mts +9 -0
- package/dist/engine/serialization.mjs +85 -0
- package/dist/engine/start-api.d.mts +30 -0
- package/dist/engine/start-api.mjs +98 -0
- package/dist/engine/state.d.mts +77 -0
- package/dist/engine/state.mjs +464 -0
- package/dist/engine/step-api.d.mts +9 -0
- package/dist/engine/step-api.mjs +25 -0
- package/dist/engine/stream.d.mts +55 -0
- package/dist/engine/stream.mjs +333 -0
- package/dist/engine/summary/active-events.d.mts +34 -0
- package/dist/engine/summary/active-events.mjs +69 -0
- package/dist/engine/summary/child-workflow-runs.d.mts +24 -0
- package/dist/engine/summary/child-workflow-runs.mjs +138 -0
- package/dist/engine/summary/child-workflow-waits.d.mts +21 -0
- package/dist/engine/summary/child-workflow-waits.mjs +67 -0
- package/dist/engine/summary/recovery-child-workflow-waits.d.mts +11 -0
- package/dist/engine/summary/recovery-child-workflow-waits.mjs +89 -0
- package/dist/engine/summary/recovery-due-runs.d.mts +16 -0
- package/dist/engine/summary/recovery-due-runs.mjs +52 -0
- package/dist/engine/summary/recovery-failed-runs.d.mts +14 -0
- package/dist/engine/summary/recovery-failed-runs.mjs +33 -0
- package/dist/engine/summary/recovery-lease-runs.d.mts +16 -0
- package/dist/engine/summary/recovery-lease-runs.mjs +69 -0
- package/dist/engine/summary/recovery-locks.d.mts +18 -0
- package/dist/engine/summary/recovery-locks.mjs +100 -0
- package/dist/engine/summary/recovery-message-waits.d.mts +11 -0
- package/dist/engine/summary/recovery-message-waits.mjs +74 -0
- package/dist/engine/summary/recovery-retry-runs.d.mts +17 -0
- package/dist/engine/summary/recovery-retry-runs.mjs +65 -0
- package/dist/engine/summary/recovery-run-timestamps.d.mts +13 -0
- package/dist/engine/summary/recovery-run-timestamps.mjs +18 -0
- package/dist/engine/summary/recovery-runs.d.mts +23 -0
- package/dist/engine/summary/recovery-runs.mjs +54 -0
- package/dist/engine/summary/recovery-schedules.d.mts +10 -0
- package/dist/engine/summary/recovery-schedules.mjs +46 -0
- package/dist/engine/summary/recovery-sleep-waits.d.mts +10 -0
- package/dist/engine/summary/recovery-sleep-waits.mjs +53 -0
- package/dist/engine/summary/recovery-waits.d.mts +21 -0
- package/dist/engine/summary/recovery-waits.mjs +29 -0
- package/dist/engine/summary/run-availability.d.mts +13 -0
- package/dist/engine/summary/run-availability.mjs +37 -0
- package/dist/engine/summary/run-cleanup.d.mts +14 -0
- package/dist/engine/summary/run-cleanup.mjs +44 -0
- package/dist/engine/summary/run-failure.d.mts +14 -0
- package/dist/engine/summary/run-failure.mjs +62 -0
- package/dist/engine/summary/run-hooks.d.mts +14 -0
- package/dist/engine/summary/run-hooks.mjs +63 -0
- package/dist/engine/summary/run-lease.d.mts +11 -0
- package/dist/engine/summary/run-lease.mjs +64 -0
- package/dist/engine/summary/run-message-waits.d.mts +15 -0
- package/dist/engine/summary/run-message-waits.mjs +62 -0
- package/dist/engine/summary/run-metrics.d.mts +31 -0
- package/dist/engine/summary/run-metrics.mjs +93 -0
- package/dist/engine/summary/run-retry.d.mts +9 -0
- package/dist/engine/summary/run-retry.mjs +69 -0
- package/dist/engine/summary/run-sleeps.d.mts +15 -0
- package/dist/engine/summary/run-sleeps.mjs +61 -0
- package/dist/engine/summary/run-state.d.mts +26 -0
- package/dist/engine/summary/run-state.mjs +48 -0
- package/dist/engine/summary/run-status.d.mts +16 -0
- package/dist/engine/summary/run-status.mjs +35 -0
- package/dist/engine/summary/run-streams.d.mts +14 -0
- package/dist/engine/summary/run-streams.mjs +46 -0
- package/dist/engine/summary/run-transition.d.mts +9 -0
- package/dist/engine/summary/run-transition.mjs +39 -0
- package/dist/engine/summary/run-workflow.d.mts +9 -0
- package/dist/engine/summary/run-workflow.mjs +47 -0
- package/dist/engine/summary/step-attempt-active-child-workflows.d.mts +13 -0
- package/dist/engine/summary/step-attempt-active-child-workflows.mjs +55 -0
- package/dist/engine/summary/step-attempt-active-fields.d.mts +23 -0
- package/dist/engine/summary/step-attempt-active-fields.mjs +14 -0
- package/dist/engine/summary/step-attempt-active-message-waits.d.mts +12 -0
- package/dist/engine/summary/step-attempt-active-message-waits.mjs +47 -0
- package/dist/engine/summary/step-attempt-active-sleeps.d.mts +19 -0
- package/dist/engine/summary/step-attempt-active-sleeps.mjs +44 -0
- package/dist/engine/summary/step-attempt-buckets.d.mts +22 -0
- package/dist/engine/summary/step-attempt-buckets.mjs +152 -0
- package/dist/engine/summary/step-attempt-failure.d.mts +12 -0
- package/dist/engine/summary/step-attempt-failure.mjs +61 -0
- package/dist/engine/summary/step-attempt-lifecycle.d.mts +13 -0
- package/dist/engine/summary/step-attempt-lifecycle.mjs +19 -0
- package/dist/engine/summary/step-attempts.d.mts +11 -0
- package/dist/engine/summary/step-attempts.mjs +43 -0
- package/dist/engine/summary.d.mts +32 -0
- package/dist/engine/summary.mjs +37 -0
- package/dist/engine/task.d.mts +6 -0
- package/dist/engine/task.mjs +207 -0
- package/dist/errors/base.d.mts +99 -0
- package/dist/errors/base.mjs +426 -0
- package/dist/errors/capability.d.mts +11 -0
- package/dist/errors/capability.mjs +23 -0
- package/dist/errors/definition.d.mts +21 -0
- package/dist/errors/definition.mjs +51 -0
- package/dist/errors/details.d.mts +13 -0
- package/dist/errors/details.mjs +65 -0
- package/dist/errors/failures.d.mts +81 -0
- package/dist/errors/failures.mjs +168 -0
- package/dist/errors/hook.d.mts +14 -0
- package/dist/errors/hook.mjs +30 -0
- package/dist/errors/implementation.d.mts +11 -0
- package/dist/errors/implementation.mjs +25 -0
- package/dist/errors/lock.d.mts +28 -0
- package/dist/errors/lock.mjs +70 -0
- package/dist/errors/message.d.mts +106 -0
- package/dist/errors/message.mjs +122 -0
- package/dist/errors/mod.d.mts +17 -0
- package/dist/errors/mod.mjs +17 -0
- package/dist/errors/record-view.d.mts +11 -0
- package/dist/errors/record-view.mjs +24 -0
- package/dist/errors/records.d.mts +7 -0
- package/dist/errors/records.mjs +280 -0
- package/dist/errors/run.d.mts +116 -0
- package/dist/errors/run.mjs +232 -0
- package/dist/errors/runtime.d.mts +12 -0
- package/dist/errors/runtime.mjs +24 -0
- package/dist/errors/schedule.d.mts +27 -0
- package/dist/errors/schedule.mjs +65 -0
- package/dist/errors/step.d.mts +76 -0
- package/dist/errors/step.mjs +113 -0
- package/dist/errors/stream.d.mts +24 -0
- package/dist/errors/stream.mjs +64 -0
- package/dist/esbuild.d.mts +7 -0
- package/dist/esbuild.mjs +6 -0
- package/dist/events/descriptors.d.mts +245 -0
- package/dist/events/descriptors.mjs +405 -0
- package/dist/events/mod.d.mts +3 -0
- package/dist/events/mod.mjs +2 -0
- package/dist/history/attempt-key.d.mts +6 -0
- package/dist/history/attempt-key.mjs +7 -0
- package/dist/history/mod.d.mts +71 -0
- package/dist/history/mod.mjs +195 -0
- package/dist/history/projection.d.mts +8 -0
- package/dist/history/projection.mjs +259 -0
- package/dist/history/replay-projection.d.mts +88 -0
- package/dist/history/replay-projection.mjs +369 -0
- package/dist/history/sequencer.d.mts +16 -0
- package/dist/history/sequencer.mjs +78 -0
- package/dist/history/step-attempts.d.mts +9 -0
- package/dist/history/step-attempts.mjs +50 -0
- package/dist/history/timeline.d.mts +16 -0
- package/dist/history/timeline.mjs +272 -0
- package/dist/history/validator.d.mts +9 -0
- package/dist/history/validator.mjs +110 -0
- package/dist/inspection/mod.d.mts +5 -0
- package/dist/inspection/mod.mjs +3 -0
- package/dist/message-options.d.mts +8 -0
- package/dist/message-options.mjs +25 -0
- package/dist/mod.d.mts +52 -0
- package/dist/mod.mjs +26 -0
- package/dist/otel/support.d.mts +18 -0
- package/dist/otel/support.mjs +102 -0
- package/dist/otel.d.mts +30 -0
- package/dist/otel.mjs +588 -0
- package/dist/pagination.d.mts +25 -0
- package/dist/pagination.mjs +73 -0
- package/dist/registry.d.mts +20 -0
- package/dist/registry.mjs +48 -0
- package/dist/rolldown.d.mts +7 -0
- package/dist/rolldown.mjs +6 -0
- package/dist/rollup.d.mts +7 -0
- package/dist/rollup.mjs +6 -0
- package/dist/rspack.d.mts +7 -0
- package/dist/rspack.mjs +6 -0
- package/dist/runtime.d.mts +34 -0
- package/dist/runtime.mjs +194 -0
- package/dist/step-definition.d.mts +10 -0
- package/dist/step-definition.mjs +15 -0
- package/dist/store/append-projection.d.mts +15 -0
- package/dist/store/append-projection.mjs +26 -0
- package/dist/store/capabilities.d.mts +14 -0
- package/dist/store/capabilities.mjs +42 -0
- package/dist/store/cleanup.d.mts +18 -0
- package/dist/store/cleanup.mjs +338 -0
- package/dist/store/compaction.d.mts +5 -0
- package/dist/store/compaction.mjs +8 -0
- package/dist/store/create.d.mts +52 -0
- package/dist/store/create.mjs +159 -0
- package/dist/store/event-append-project.d.mts +15 -0
- package/dist/store/event-append-project.mjs +77 -0
- package/dist/store/event-append.d.mts +37 -0
- package/dist/store/event-append.mjs +80 -0
- package/dist/store/event-history.d.mts +22 -0
- package/dist/store/event-history.mjs +75 -0
- package/dist/store/event.d.mts +10 -0
- package/dist/store/event.mjs +28 -0
- package/dist/store/idempotency.d.mts +10 -0
- package/dist/store/idempotency.mjs +167 -0
- package/dist/store/instrumentation.d.mts +7 -0
- package/dist/store/instrumentation.mjs +123 -0
- package/dist/store/lock.d.mts +8 -0
- package/dist/store/lock.mjs +28 -0
- package/dist/store/materialization.d.mts +30 -0
- package/dist/store/materialization.mjs +127 -0
- package/dist/store/message-index.d.mts +21 -0
- package/dist/store/message-index.mjs +121 -0
- package/dist/store/mod.d.mts +5 -0
- package/dist/store/mod.mjs +4 -0
- package/dist/store/query.d.mts +24 -0
- package/dist/store/query.mjs +82 -0
- package/dist/store/revision.d.mts +4 -0
- package/dist/store/revision.mjs +7 -0
- package/dist/store/run.d.mts +49 -0
- package/dist/store/run.mjs +236 -0
- package/dist/store/schedule.d.mts +12 -0
- package/dist/store/schedule.mjs +41 -0
- package/dist/store/schema.d.mts +14 -0
- package/dist/store/schema.mjs +17 -0
- package/dist/store/step-attempt.d.mts +14 -0
- package/dist/store/step-attempt.mjs +23 -0
- package/dist/store/storage-value.d.mts +5 -0
- package/dist/store/storage-value.mjs +6 -0
- package/dist/store/validation.d.mts +35 -0
- package/dist/store/validation.mjs +77 -0
- package/dist/store-keys.d.mts +49 -0
- package/dist/store-keys.mjs +63 -0
- package/dist/telemetry.d.mts +132 -0
- package/dist/telemetry.mjs +172 -0
- package/dist/temporal.d.mts +23 -0
- package/dist/temporal.mjs +59 -0
- package/dist/timer.d.mts +12 -0
- package/dist/timer.mjs +28 -0
- package/dist/types/cleanup.d.mts +112 -0
- package/dist/types/cleanup.mjs +22 -0
- package/dist/types/client.d.mts +270 -0
- package/dist/types/client.mjs +1 -0
- package/dist/types/common.d.mts +19 -0
- package/dist/types/common.mjs +15 -0
- package/dist/types/definition.d.mts +92 -0
- package/dist/types/definition.mjs +1 -0
- package/dist/types/engine-options.d.mts +76 -0
- package/dist/types/engine-options.mjs +1 -0
- package/dist/types/engine.d.mts +309 -0
- package/dist/types/engine.mjs +1 -0
- package/dist/types/error-code.d.mts +256 -0
- package/dist/types/error-code.mjs +131 -0
- package/dist/types/error.d.mts +236 -0
- package/dist/types/error.mjs +48 -0
- package/dist/types/events.d.mts +2869 -0
- package/dist/types/events.mjs +283 -0
- package/dist/types/hook.d.mts +149 -0
- package/dist/types/hook.mjs +66 -0
- package/dist/types/lock.d.mts +63 -0
- package/dist/types/lock.mjs +18 -0
- package/dist/types/message-id.d.mts +7 -0
- package/dist/types/message-id.mjs +5 -0
- package/dist/types/message.d.mts +87 -0
- package/dist/types/message.mjs +1 -0
- package/dist/types/observation.d.mts +146 -0
- package/dist/types/observation.mjs +1 -0
- package/dist/types/pagination.d.mts +32 -0
- package/dist/types/pagination.mjs +13 -0
- package/dist/types/result.d.mts +62 -0
- package/dist/types/result.mjs +1 -0
- package/dist/types/retry.d.mts +48 -0
- package/dist/types/retry.mjs +1 -0
- package/dist/types/run-id.d.mts +7 -0
- package/dist/types/run-id.mjs +5 -0
- package/dist/types/run-list.d.mts +43 -0
- package/dist/types/run-list.mjs +1 -0
- package/dist/types/run-options.d.mts +86 -0
- package/dist/types/run-options.mjs +1 -0
- package/dist/types/run.d.mts +355 -0
- package/dist/types/run.mjs +207 -0
- package/dist/types/runtime.d.mts +143 -0
- package/dist/types/runtime.mjs +21 -0
- package/dist/types/schedule.d.mts +127 -0
- package/dist/types/schedule.mjs +48 -0
- package/dist/types/step-attempts.d.mts +326 -0
- package/dist/types/step-attempts.mjs +43 -0
- package/dist/types/step-id.d.mts +7 -0
- package/dist/types/step-id.mjs +5 -0
- package/dist/types/step.d.mts +183 -0
- package/dist/types/step.mjs +5 -0
- package/dist/types/store.d.mts +254 -0
- package/dist/types/store.mjs +1 -0
- package/dist/types/stream-id.d.mts +7 -0
- package/dist/types/stream-id.mjs +5 -0
- package/dist/types/stream.d.mts +126 -0
- package/dist/types/stream.mjs +1 -0
- package/dist/types/summary.d.mts +318 -0
- package/dist/types/summary.mjs +1 -0
- package/dist/types/telemetry.d.mts +74 -0
- package/dist/types/telemetry.mjs +9 -0
- package/dist/types/timeline.d.mts +237 -0
- package/dist/types/timeline.mjs +1 -0
- package/dist/types/vite.d.mts +65 -0
- package/dist/types/vite.mjs +1 -0
- package/dist/types/worker-id.d.mts +7 -0
- package/dist/types/worker-id.mjs +5 -0
- package/dist/types/worker.d.mts +94 -0
- package/dist/types/worker.mjs +1 -0
- package/dist/utility.d.mts +49 -0
- package/dist/utility.mjs +122 -0
- package/dist/vite/ast.d.mts +23 -0
- package/dist/vite/ast.mjs +73 -0
- package/dist/vite/error.d.mts +19 -0
- package/dist/vite/error.mjs +47 -0
- package/dist/vite/generated-name.d.mts +7 -0
- package/dist/vite/generated-name.mjs +9 -0
- package/dist/vite/manifest.d.mts +7 -0
- package/dist/vite/manifest.mjs +106 -0
- package/dist/vite/plugin.d.mts +7 -0
- package/dist/vite/plugin.mjs +190 -0
- package/dist/vite/safety.d.mts +12 -0
- package/dist/vite/safety.mjs +96 -0
- package/dist/vite/source-edit.d.mts +12 -0
- package/dist/vite/source-edit.mjs +44 -0
- package/dist/vite/source-map.d.mts +11 -0
- package/dist/vite/source-map.mjs +53 -0
- package/dist/vite/source.d.mts +7 -0
- package/dist/vite/source.mjs +14 -0
- package/dist/vite/transform.d.mts +7 -0
- package/dist/vite/transform.mjs +405 -0
- package/dist/vite.d.mts +6 -0
- package/dist/vite.mjs +5 -0
- package/dist/webhook.d.mts +16 -0
- package/dist/webhook.mjs +17 -0
- package/dist/webpack.d.mts +7 -0
- package/dist/webpack.mjs +6 -0
- package/dist/worker/error.d.mts +11 -0
- package/dist/worker/error.mjs +40 -0
- package/dist/worker.d.mts +18 -0
- package/dist/worker.mjs +427 -0
- package/package.json +144 -0
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { WorkflowStateError } from "../errors/base.mjs";
|
|
2
|
+
import { WorkflowRunCanceledError, WorkflowRunCancellationError, WorkflowRunDeadlineExceededError, WorkflowRunMismatchError } from "../errors/run.mjs";
|
|
3
|
+
import { getRequiredRun, isPositiveSafeInteger } from "../utility.mjs";
|
|
4
|
+
import { applyWorkflowAttributePatch } from "../attributes.mjs";
|
|
5
|
+
import "./retry-policy.mjs";
|
|
6
|
+
import { serializeError } from "./serialization.mjs";
|
|
7
|
+
import { WorkflowHistory } from "../history/mod.mjs";
|
|
8
|
+
import { enforceWorkflowEventHistoryNextLimit } from "./retry.mjs";
|
|
9
|
+
import { readRunResult } from "./run-utils.mjs";
|
|
10
|
+
//#region src/engine/state.ts
|
|
11
|
+
function requireDefinitionMatchesRun(definition, run) {
|
|
12
|
+
if (definition.name !== run.workflowName) WorkflowRunMismatchError.mismatch({
|
|
13
|
+
runId: run.id,
|
|
14
|
+
expectedWorkflowName: definition.name,
|
|
15
|
+
actualWorkflowName: run.workflowName
|
|
16
|
+
});
|
|
17
|
+
if (definition.version !== run.workflowVersion) WorkflowRunMismatchError.mismatch({
|
|
18
|
+
runId: run.id,
|
|
19
|
+
expectedWorkflowName: definition.version === void 0 ? definition.name : `${definition.name}@${definition.version}`,
|
|
20
|
+
actualWorkflowName: run.workflowVersion === void 0 ? run.workflowName : `${run.workflowName}@${run.workflowVersion}`
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function appendEventIfCurrentExecution(store, history, event, executionOwner, limits, beforeAppend, afterAppend) {
|
|
24
|
+
let appendedEvents;
|
|
25
|
+
await history.append(async () => {
|
|
26
|
+
beforeAppend?.();
|
|
27
|
+
enforceWorkflowEventHistoryNextLimit(history.events, limits);
|
|
28
|
+
const events = await store.appendEventIfRunCurrent(executionOwner, event);
|
|
29
|
+
if (events === void 0) WorkflowStaleExecutionError.stale(executionOwner.id);
|
|
30
|
+
appendedEvents = events;
|
|
31
|
+
return events;
|
|
32
|
+
});
|
|
33
|
+
if (appendedEvents !== void 0) afterAppend?.(event, appendedEvents);
|
|
34
|
+
}
|
|
35
|
+
async function requireCurrentExecutionOwner(store, runId, executionOwner) {
|
|
36
|
+
const current = await store.getRun(runId);
|
|
37
|
+
if (current === void 0 || !isCurrentExecutionOwner(current, executionOwner)) WorkflowStaleExecutionError.stale(runId);
|
|
38
|
+
}
|
|
39
|
+
async function patchRun(store, current, patch) {
|
|
40
|
+
const next = {
|
|
41
|
+
...current,
|
|
42
|
+
...patch
|
|
43
|
+
};
|
|
44
|
+
return await store.updateRun(next);
|
|
45
|
+
}
|
|
46
|
+
async function patchRunIfCurrent(store, current, patch) {
|
|
47
|
+
return await store.updateRunIfCurrent(current, {
|
|
48
|
+
...current,
|
|
49
|
+
...patch
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function updateRunMetadataIfCurrent(store, runId, metadata, timestamp) {
|
|
53
|
+
for (let attempt = 0; attempt < 16; attempt++) {
|
|
54
|
+
const updated = await patchRunIfCurrent(store, await getRequiredRun(store, runId), {
|
|
55
|
+
metadata,
|
|
56
|
+
updatedAt: timestamp
|
|
57
|
+
});
|
|
58
|
+
if (updated !== void 0) return updated;
|
|
59
|
+
}
|
|
60
|
+
WorkflowStateError.failedRunMetadataUpdate(runId);
|
|
61
|
+
}
|
|
62
|
+
async function setRunAttributesIfCurrent(store, runId, attributes, timestamp) {
|
|
63
|
+
for (let attempt = 0; attempt < 16; attempt++) {
|
|
64
|
+
const current = await getRequiredRun(store, runId);
|
|
65
|
+
const updated = await patchRunIfCurrent(store, current, {
|
|
66
|
+
attributes: applyWorkflowAttributePatch(current.attributes, attributes),
|
|
67
|
+
updatedAt: timestamp
|
|
68
|
+
});
|
|
69
|
+
if (updated !== void 0) return updated;
|
|
70
|
+
}
|
|
71
|
+
WorkflowStateError.failedRunAttributesUpdate(runId);
|
|
72
|
+
}
|
|
73
|
+
async function patchCurrentExecutionRun(store, executionOwner, patch) {
|
|
74
|
+
const current = await store.getRun(executionOwner.id);
|
|
75
|
+
if (current === void 0 || !isCurrentExecutionOwner(current, executionOwner)) return;
|
|
76
|
+
return await patchRunIfCurrent(store, current, patch);
|
|
77
|
+
}
|
|
78
|
+
async function patchCurrentExecutionRunAttributes(store, executionOwner, attributes, timestamp) {
|
|
79
|
+
const current = await store.getRun(executionOwner.id);
|
|
80
|
+
if (current === void 0 || !isCurrentExecutionOwner(current, executionOwner)) return;
|
|
81
|
+
return await patchRunIfCurrent(store, current, {
|
|
82
|
+
attributes: applyWorkflowAttributePatch(current.attributes, attributes),
|
|
83
|
+
updatedAt: timestamp
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function transitionRunToMissingImplementationWait(run, error, timestamp, availableAt, retryAttempt) {
|
|
87
|
+
return {
|
|
88
|
+
...run,
|
|
89
|
+
status: "waiting",
|
|
90
|
+
error,
|
|
91
|
+
updatedAt: timestamp,
|
|
92
|
+
lastTransitionAt: timestamp,
|
|
93
|
+
lastTransitionReason: "missing_implementation",
|
|
94
|
+
availableAt,
|
|
95
|
+
retryAt: availableAt,
|
|
96
|
+
retryReason: "missing_implementation",
|
|
97
|
+
retryAttempt,
|
|
98
|
+
retryStepId: void 0,
|
|
99
|
+
retryStepName: void 0,
|
|
100
|
+
workerId: void 0,
|
|
101
|
+
leaseExpiresAt: void 0,
|
|
102
|
+
deadlineAt: run.deadlineAt,
|
|
103
|
+
output: void 0,
|
|
104
|
+
finishedAt: void 0
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function transitionRunToFailed(run, error, timestamp, lastTransitionReason, deadlineAt) {
|
|
108
|
+
return {
|
|
109
|
+
...run,
|
|
110
|
+
status: "failed",
|
|
111
|
+
error,
|
|
112
|
+
updatedAt: timestamp,
|
|
113
|
+
lastTransitionAt: timestamp,
|
|
114
|
+
lastTransitionReason,
|
|
115
|
+
finishedAt: timestamp,
|
|
116
|
+
output: void 0,
|
|
117
|
+
availableAt: void 0,
|
|
118
|
+
retryAt: void 0,
|
|
119
|
+
retryReason: void 0,
|
|
120
|
+
retryAttempt: void 0,
|
|
121
|
+
retryStepId: void 0,
|
|
122
|
+
retryStepName: void 0,
|
|
123
|
+
workerId: void 0,
|
|
124
|
+
leaseExpiresAt: void 0,
|
|
125
|
+
deadlineAt: deadlineAt ?? run.deadlineAt
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function transitionRunToRunning(run, timestamp, attempts) {
|
|
129
|
+
return {
|
|
130
|
+
...run,
|
|
131
|
+
status: "running",
|
|
132
|
+
attempts,
|
|
133
|
+
updatedAt: timestamp,
|
|
134
|
+
lastTransitionAt: timestamp,
|
|
135
|
+
lastTransitionReason: "started",
|
|
136
|
+
startedAt: run.startedAt ?? timestamp,
|
|
137
|
+
availableAt: void 0,
|
|
138
|
+
error: void 0,
|
|
139
|
+
output: void 0,
|
|
140
|
+
finishedAt: void 0,
|
|
141
|
+
retryAt: void 0,
|
|
142
|
+
retryReason: void 0,
|
|
143
|
+
retryAttempt: void 0,
|
|
144
|
+
retryStepId: void 0,
|
|
145
|
+
retryStepName: void 0
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function transitionRunToCompleted(run, output, timestamp) {
|
|
149
|
+
return {
|
|
150
|
+
...run,
|
|
151
|
+
status: "completed",
|
|
152
|
+
...output === void 0 ? { output: void 0 } : { output },
|
|
153
|
+
error: void 0,
|
|
154
|
+
updatedAt: timestamp,
|
|
155
|
+
lastTransitionAt: timestamp,
|
|
156
|
+
lastTransitionReason: "completed",
|
|
157
|
+
finishedAt: timestamp,
|
|
158
|
+
availableAt: void 0,
|
|
159
|
+
workerId: void 0,
|
|
160
|
+
leaseExpiresAt: void 0,
|
|
161
|
+
retryAt: void 0,
|
|
162
|
+
retryReason: void 0,
|
|
163
|
+
retryAttempt: void 0,
|
|
164
|
+
retryStepId: void 0,
|
|
165
|
+
retryStepName: void 0
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function transitionRunToExecutionWait(run, timestamp, availableAt, options = {}) {
|
|
169
|
+
return {
|
|
170
|
+
...run,
|
|
171
|
+
status: "waiting",
|
|
172
|
+
availableAt,
|
|
173
|
+
updatedAt: timestamp,
|
|
174
|
+
lastTransitionAt: timestamp,
|
|
175
|
+
lastTransitionReason: options.retryReason === void 0 ? "waiting" : "retry",
|
|
176
|
+
workerId: void 0,
|
|
177
|
+
leaseExpiresAt: void 0,
|
|
178
|
+
retryAt: options.retryAt,
|
|
179
|
+
retryReason: options.retryReason,
|
|
180
|
+
retryAttempt: options.retryAttempt,
|
|
181
|
+
retryStepId: options.retryStepId,
|
|
182
|
+
retryStepName: options.retryStepName,
|
|
183
|
+
error: options.error,
|
|
184
|
+
output: void 0,
|
|
185
|
+
finishedAt: void 0
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function transitionRunToWaiting(run, timestamp, availableAt) {
|
|
189
|
+
return {
|
|
190
|
+
...run,
|
|
191
|
+
status: "waiting",
|
|
192
|
+
availableAt,
|
|
193
|
+
updatedAt: timestamp,
|
|
194
|
+
lastTransitionAt: timestamp,
|
|
195
|
+
lastTransitionReason: "waiting",
|
|
196
|
+
deadlineAt: run.deadlineAt,
|
|
197
|
+
workerId: void 0,
|
|
198
|
+
leaseExpiresAt: void 0,
|
|
199
|
+
error: void 0,
|
|
200
|
+
output: void 0,
|
|
201
|
+
finishedAt: void 0
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function transitionRunToRescheduled(run, timestamp, availableAt) {
|
|
205
|
+
return {
|
|
206
|
+
...run,
|
|
207
|
+
availableAt,
|
|
208
|
+
updatedAt: timestamp,
|
|
209
|
+
lastTransitionAt: timestamp,
|
|
210
|
+
lastTransitionReason: "rescheduled",
|
|
211
|
+
deadlineAt: run.deadlineAt,
|
|
212
|
+
leaseExpiresAt: void 0,
|
|
213
|
+
workerId: void 0,
|
|
214
|
+
retryAt: run.retryReason === void 0 ? void 0 : availableAt,
|
|
215
|
+
retryReason: run.retryReason,
|
|
216
|
+
retryAttempt: run.retryAttempt,
|
|
217
|
+
retryStepId: run.retryStepId,
|
|
218
|
+
retryStepName: run.retryStepName,
|
|
219
|
+
error: void 0,
|
|
220
|
+
output: void 0,
|
|
221
|
+
finishedAt: void 0
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function transitionRunAfterStaleLeaseRelease(run, timestamp, availableAt) {
|
|
225
|
+
return {
|
|
226
|
+
...transitionRunToWaiting(run, timestamp, availableAt),
|
|
227
|
+
lastTransitionReason: "lease_released",
|
|
228
|
+
retryAt: void 0,
|
|
229
|
+
retryReason: void 0,
|
|
230
|
+
retryAttempt: void 0,
|
|
231
|
+
retryStepId: void 0,
|
|
232
|
+
retryStepName: void 0,
|
|
233
|
+
deadlineAt: run.deadlineAt,
|
|
234
|
+
updatedAt: timestamp,
|
|
235
|
+
lastTransitionAt: timestamp
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function transitionRunToManualRetry(run, timestamp, availableAt, retryAttempt) {
|
|
239
|
+
return {
|
|
240
|
+
...run,
|
|
241
|
+
status: "pending",
|
|
242
|
+
availableAt,
|
|
243
|
+
updatedAt: timestamp,
|
|
244
|
+
lastTransitionAt: timestamp,
|
|
245
|
+
lastTransitionReason: "manual_retry",
|
|
246
|
+
deadlineAt: run.deadlineAt,
|
|
247
|
+
workerId: void 0,
|
|
248
|
+
leaseExpiresAt: void 0,
|
|
249
|
+
retryAt: availableAt,
|
|
250
|
+
retryReason: run.retryReason ?? "workflow",
|
|
251
|
+
retryAttempt,
|
|
252
|
+
retryStepId: run.retryStepId,
|
|
253
|
+
retryStepName: run.retryStepName,
|
|
254
|
+
error: void 0,
|
|
255
|
+
output: void 0,
|
|
256
|
+
finishedAt: void 0
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function transitionRunToPermanentFailure(run, error, timestamp) {
|
|
260
|
+
return {
|
|
261
|
+
...run,
|
|
262
|
+
status: "failed",
|
|
263
|
+
error,
|
|
264
|
+
output: void 0,
|
|
265
|
+
availableAt: void 0,
|
|
266
|
+
updatedAt: timestamp,
|
|
267
|
+
lastTransitionAt: timestamp,
|
|
268
|
+
lastTransitionReason: "permanent_failure",
|
|
269
|
+
deadlineAt: run.deadlineAt,
|
|
270
|
+
workerId: void 0,
|
|
271
|
+
leaseExpiresAt: void 0,
|
|
272
|
+
retryAt: void 0,
|
|
273
|
+
retryReason: void 0,
|
|
274
|
+
retryAttempt: void 0,
|
|
275
|
+
retryStepId: void 0,
|
|
276
|
+
retryStepName: void 0,
|
|
277
|
+
finishedAt: timestamp
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function transitionRunToCanceled(run, error, timestamp) {
|
|
281
|
+
return {
|
|
282
|
+
...run,
|
|
283
|
+
status: "canceled",
|
|
284
|
+
error,
|
|
285
|
+
updatedAt: timestamp,
|
|
286
|
+
lastTransitionAt: timestamp,
|
|
287
|
+
lastTransitionReason: "canceled",
|
|
288
|
+
finishedAt: timestamp,
|
|
289
|
+
availableAt: void 0,
|
|
290
|
+
output: void 0,
|
|
291
|
+
workerId: void 0,
|
|
292
|
+
leaseExpiresAt: void 0,
|
|
293
|
+
retryAt: void 0,
|
|
294
|
+
retryReason: void 0,
|
|
295
|
+
retryAttempt: void 0,
|
|
296
|
+
retryStepId: void 0,
|
|
297
|
+
retryStepName: void 0
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function transitionRunAfterParentWake(run, timestamp) {
|
|
301
|
+
return {
|
|
302
|
+
...run,
|
|
303
|
+
availableAt: timestamp,
|
|
304
|
+
updatedAt: timestamp,
|
|
305
|
+
lastTransitionAt: timestamp,
|
|
306
|
+
lastTransitionReason: "waiting",
|
|
307
|
+
deadlineAt: run.deadlineAt,
|
|
308
|
+
retryAt: run.retryAt,
|
|
309
|
+
startedAt: run.startedAt ?? timestamp,
|
|
310
|
+
error: void 0,
|
|
311
|
+
output: void 0,
|
|
312
|
+
finishedAt: void 0
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function isCurrentExecutionOwner(current, execution) {
|
|
316
|
+
return current.status === "running" && current.workerId === execution.workerId && current.attempts === execution.attempts;
|
|
317
|
+
}
|
|
318
|
+
async function cancelRunWithChildren(store, runId, canceledAt) {
|
|
319
|
+
const run = await getRequiredRun(store, runId);
|
|
320
|
+
if (run.status === "completed" || run.status === "failed") WorkflowRunCancellationError.cannotCancel(runId, run.status);
|
|
321
|
+
if (run.status === "canceled") return run;
|
|
322
|
+
const canceledRun = await patchRunIfCurrent(store, run, transitionRunToCanceled(run, serializeError(WorkflowRunCanceledError.create(runId)), canceledAt));
|
|
323
|
+
if (canceledRun === void 0) {
|
|
324
|
+
const latest = await getRequiredRun(store, runId);
|
|
325
|
+
if (latest.status === "completed" || latest.status === "failed") WorkflowRunCancellationError.cannotCancel(runId, latest.status);
|
|
326
|
+
if (latest.status === "canceled") return latest;
|
|
327
|
+
return await cancelRunWithChildren(store, runId, canceledAt);
|
|
328
|
+
}
|
|
329
|
+
await releaseLocksForRun(store, run.id, canceledAt);
|
|
330
|
+
await cancelActiveChildRuns(store, run.id, canceledAt);
|
|
331
|
+
await wakeParentRunForTerminalChild(store, canceledRun, canceledAt);
|
|
332
|
+
return canceledRun;
|
|
333
|
+
}
|
|
334
|
+
async function cancelActiveChildRuns(store, parentRunId, canceledAt) {
|
|
335
|
+
const attempts = await store.listStepAttempts(parentRunId, {
|
|
336
|
+
kind: "workflow",
|
|
337
|
+
status: "running"
|
|
338
|
+
});
|
|
339
|
+
const childRunIds = /* @__PURE__ */ new Set();
|
|
340
|
+
for (const attempt of attempts) if (attempt.childRunId !== void 0 && (attempt.cancellation ?? "cascade") === "cascade" && await parentHasActiveChildWorkflowEventForAttempt(store, parentRunId, attempt)) childRunIds.add(attempt.childRunId);
|
|
341
|
+
for (const childRunId of childRunIds) {
|
|
342
|
+
const child = await store.getRun(childRunId);
|
|
343
|
+
if (child === void 0) continue;
|
|
344
|
+
if (!await parentHasActiveChildWorkflowAttemptForRun(store, parentRunId, child)) continue;
|
|
345
|
+
if (child.status === "completed" || child.status === "failed" || child.status === "canceled") continue;
|
|
346
|
+
await cancelRunWithChildren(store, child.id, canceledAt);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function wakeParentRunForTerminalChild(store, childRun, timestamp) {
|
|
350
|
+
if (childRun.parentRunId === void 0) return;
|
|
351
|
+
const parentRun = await store.getRun(childRun.parentRunId);
|
|
352
|
+
if (parentRun === void 0 || parentRun.status !== "waiting") return;
|
|
353
|
+
if (!await parentHasActiveChildWorkflowAttemptForRun(store, parentRun.id, childRun)) return;
|
|
354
|
+
const wakeAt = timestamp;
|
|
355
|
+
if (parentRun.availableAt !== void 0 && Temporal.Instant.compare(parentRun.availableAt, wakeAt) <= 0) return;
|
|
356
|
+
await patchRun(store, parentRun, transitionRunAfterParentWake(parentRun, timestamp));
|
|
357
|
+
}
|
|
358
|
+
async function wakeParentRunForWaitingChild(store, childRun, availableAt) {
|
|
359
|
+
if (childRun.parentRunId === void 0) return;
|
|
360
|
+
const parentRun = await store.getRun(childRun.parentRunId);
|
|
361
|
+
if (parentRun === void 0 || parentRun.status !== "waiting") return;
|
|
362
|
+
if (!await parentHasActiveChildWorkflowAttemptForRun(store, parentRun.id, childRun)) return;
|
|
363
|
+
const wakeAt = availableAt;
|
|
364
|
+
if (parentRun.availableAt !== void 0 && Temporal.Instant.compare(parentRun.availableAt, wakeAt) <= 0) return;
|
|
365
|
+
await patchRun(store, parentRun, transitionRunAfterParentWake(parentRun, availableAt));
|
|
366
|
+
}
|
|
367
|
+
async function parentHasActiveChildWorkflowAttemptForRun(store, parentRunId, childRun) {
|
|
368
|
+
if (childRun.parentRunId !== parentRunId) return false;
|
|
369
|
+
const attempts = await store.listStepAttempts(parentRunId, {
|
|
370
|
+
kind: "workflow",
|
|
371
|
+
status: "running",
|
|
372
|
+
childRunId: childRun.id
|
|
373
|
+
});
|
|
374
|
+
for (const attempt of attempts) if (childRun.parentRunId === parentRunId && childRun.parentStepId === attempt.stepId && childRun.parentStepName === attempt.stepName && childRun.parentStepAttempt === attempt.attempt && attempt.childRunId === childRun.id && attempt.workflowName === childRun.workflowName && attempt.workflowVersion === childRun.workflowVersion && await parentHasActiveChildWorkflowEventForAttempt(store, parentRunId, attempt)) return true;
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
async function parentHasActiveChildWorkflowEventForAttempt(store, parentRunId, attempt) {
|
|
378
|
+
if (attempt.childRunId === void 0) return false;
|
|
379
|
+
const lifecycle = new WorkflowHistory(await store.getEvents(parentRunId)).childWorkflowLifecycleForAttempt(attempt);
|
|
380
|
+
if (lifecycle.started === void 0) return false;
|
|
381
|
+
if (!isPositiveSafeInteger(lifecycle.started.attempt)) return false;
|
|
382
|
+
return !lifecycle.hasTerminalAfterStarted;
|
|
383
|
+
}
|
|
384
|
+
async function failRunForDeadline(store, run, deadlineAt, failedAt, executionOwner) {
|
|
385
|
+
const serialized = serializeError(WorkflowRunDeadlineExceededError.create(run.id, deadlineAt));
|
|
386
|
+
if (executionOwner !== void 0) {
|
|
387
|
+
const current = await store.getRun(run.id);
|
|
388
|
+
if (current === void 0 || !isCurrentExecutionOwner(current, executionOwner)) return await readRunResult(store, run.id, failedAt);
|
|
389
|
+
}
|
|
390
|
+
await cancelActiveChildRuns(store, run.id, failedAt);
|
|
391
|
+
const failedRun = executionOwner === void 0 ? await patchRun(store, run, transitionRunToFailed(run, serialized, failedAt, "deadline")) : await patchCurrentExecutionRun(store, executionOwner, transitionRunToFailed(executionOwner, serialized, failedAt, "deadline"));
|
|
392
|
+
if (failedRun === void 0) return await readRunResult(store, run.id, failedAt);
|
|
393
|
+
if (await store.appendEventIfRunCurrent(failedRun, {
|
|
394
|
+
kind: "workflow_failed",
|
|
395
|
+
timestamp: failedAt
|
|
396
|
+
}) === void 0) return await readRunResult(store, run.id, failedAt);
|
|
397
|
+
await releaseLocksForRun(store, run.id, failedAt);
|
|
398
|
+
await wakeParentRunForTerminalChild(store, failedRun, failedAt);
|
|
399
|
+
return {
|
|
400
|
+
kind: "failed",
|
|
401
|
+
run: failedRun,
|
|
402
|
+
error: serialized
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
async function releaseLocksForRun(store, runId, releasedAt) {
|
|
406
|
+
const timestamp = releasedAt;
|
|
407
|
+
const locks = await store.listLocks();
|
|
408
|
+
await Promise.all(locks.filter((lock) => lock.releasedAt === void 0 && lock.holderRunId === runId).map(async (lock) => {
|
|
409
|
+
await store.updateLockIfCurrent(lock, {
|
|
410
|
+
...lock,
|
|
411
|
+
releasedAt: timestamp
|
|
412
|
+
});
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
var WorkflowSuspended = class WorkflowSuspended extends Error {
|
|
416
|
+
availableAt;
|
|
417
|
+
retryAt;
|
|
418
|
+
retryReason;
|
|
419
|
+
retryAttempt;
|
|
420
|
+
retryStep;
|
|
421
|
+
constructor(availableAt, context) {
|
|
422
|
+
super(`Workflow suspended until ${availableAt.toString()}`);
|
|
423
|
+
this.name = "WorkflowSuspended";
|
|
424
|
+
this.availableAt = availableAt;
|
|
425
|
+
if (Error.captureStackTrace !== void 0) Error.captureStackTrace(this, context ?? this.constructor);
|
|
426
|
+
}
|
|
427
|
+
static until(availableAt) {
|
|
428
|
+
throw new WorkflowSuspended(availableAt, WorkflowSuspended.until);
|
|
429
|
+
}
|
|
430
|
+
static forStepRetry(retryAt, retryStep, retryAttempt) {
|
|
431
|
+
const suspended = new WorkflowSuspended(retryAt, WorkflowSuspended.forStepRetry);
|
|
432
|
+
Object.defineProperties(suspended, {
|
|
433
|
+
retryAt: {
|
|
434
|
+
value: retryAt,
|
|
435
|
+
enumerable: true
|
|
436
|
+
},
|
|
437
|
+
retryReason: {
|
|
438
|
+
value: "step",
|
|
439
|
+
enumerable: true
|
|
440
|
+
},
|
|
441
|
+
retryAttempt: {
|
|
442
|
+
value: retryAttempt,
|
|
443
|
+
enumerable: true
|
|
444
|
+
},
|
|
445
|
+
retryStep: {
|
|
446
|
+
value: retryStep,
|
|
447
|
+
enumerable: true
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
throw suspended;
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
var WorkflowStaleExecutionError = class WorkflowStaleExecutionError extends Error {
|
|
454
|
+
constructor(runId, context) {
|
|
455
|
+
super(`Workflow execution no longer owns run: ${runId}`);
|
|
456
|
+
this.name = "WorkflowStaleExecutionError";
|
|
457
|
+
if (Error.captureStackTrace !== void 0) Error.captureStackTrace(this, context ?? this.constructor);
|
|
458
|
+
}
|
|
459
|
+
static stale(runId) {
|
|
460
|
+
throw new WorkflowStaleExecutionError(runId, WorkflowStaleExecutionError.stale);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
//#endregion
|
|
464
|
+
export { WorkflowStaleExecutionError, WorkflowSuspended, appendEventIfCurrentExecution, cancelActiveChildRuns, cancelRunWithChildren, failRunForDeadline, getRequiredRun, isCurrentExecutionOwner, parentHasActiveChildWorkflowAttemptForRun, parentHasActiveChildWorkflowEventForAttempt, patchCurrentExecutionRun, patchCurrentExecutionRunAttributes, patchRun, patchRunIfCurrent, releaseLocksForRun, requireCurrentExecutionOwner, requireDefinitionMatchesRun, setRunAttributesIfCurrent, transitionRunAfterParentWake, transitionRunAfterStaleLeaseRelease, transitionRunToCanceled, transitionRunToCompleted, transitionRunToExecutionWait, transitionRunToFailed, transitionRunToManualRetry, transitionRunToMissingImplementationWait, transitionRunToPermanentFailure, transitionRunToRescheduled, transitionRunToRunning, transitionRunToWaiting, updateRunMetadataIfCurrent, wakeParentRunForTerminalChild, wakeParentRunForWaitingChild };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WorkflowDeterministicApi, WorkflowStepApi } from "../types/step.mjs";
|
|
2
|
+
import { WorkflowExecutionEnvironment } from "../types/engine.mjs";
|
|
3
|
+
import { WorkflowChildWorkflowEngine } from "./child-workflow.mjs";
|
|
4
|
+
import { WorkflowStepLockEngine } from "./lock.mjs";
|
|
5
|
+
//#region src/engine/step-api.d.ts
|
|
6
|
+
type WorkflowStepRuntime = WorkflowChildWorkflowEngine & WorkflowStepLockEngine;
|
|
7
|
+
declare function createStepApi(environment: WorkflowExecutionEnvironment, engine: WorkflowStepRuntime, executionSignal: AbortSignal, deterministic: WorkflowDeterministicApi): WorkflowStepApi;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { createStepApi };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createWorkflowStepWorkflowApi } from "./child-workflow.mjs";
|
|
2
|
+
import { createWorkflowStepMessageApi } from "./message.mjs";
|
|
3
|
+
import { createWorkflowStepHookApi } from "./hooks.mjs";
|
|
4
|
+
import { createWorkflowStepLockApi } from "./lock.mjs";
|
|
5
|
+
import { createWorkflowRunDataApi } from "./run-data.mjs";
|
|
6
|
+
import { createWorkflowStepStreamApi } from "./stream.mjs";
|
|
7
|
+
import { createWorkflowStepTaskApi } from "./task.mjs";
|
|
8
|
+
//#region src/engine/step-api.ts
|
|
9
|
+
function createStepApi(environment, engine, executionSignal, deterministic) {
|
|
10
|
+
const task = createWorkflowStepTaskApi(environment, executionSignal);
|
|
11
|
+
const runTask = async (config, callback) => await task.run(config, callback);
|
|
12
|
+
return {
|
|
13
|
+
log: environment.logger,
|
|
14
|
+
task,
|
|
15
|
+
workflow: createWorkflowStepWorkflowApi(environment, engine),
|
|
16
|
+
message: createWorkflowStepMessageApi(environment),
|
|
17
|
+
lock: createWorkflowStepLockApi(environment, engine, runTask),
|
|
18
|
+
runData: createWorkflowRunDataApi(environment),
|
|
19
|
+
deterministic,
|
|
20
|
+
stream: createWorkflowStepStreamApi(environment),
|
|
21
|
+
hook: createWorkflowStepHookApi(environment)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createStepApi };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RunId } from "../types/run-id.mjs";
|
|
2
|
+
import { StreamIdOrName } from "../types/stream-id.mjs";
|
|
3
|
+
import { CreateStreamOptions, FollowStreamOptions, ReadStreamOptions, ReadStreamPageOptions, Stream as Stream$1, StreamChunk, StreamInfo, StreamPage, StreamState, StreamUpdate, WaitStreamOptions } from "../types/stream.mjs";
|
|
4
|
+
import { WorkflowStepStreamApi } from "../types/step.mjs";
|
|
5
|
+
import { WorkflowStepIdentity } from "../types/run.mjs";
|
|
6
|
+
import { EventRecord } from "../types/events.mjs";
|
|
7
|
+
import { WorkflowEventHistoryWatcher, WorkflowEventReader, WorkflowRunReaderRepository } from "../types/store.mjs";
|
|
8
|
+
import { WorkflowExecutionEnvironment } from "../types/engine.mjs";
|
|
9
|
+
//#region src/engine/stream.d.ts
|
|
10
|
+
interface WorkflowStreamReader<TChunk> {
|
|
11
|
+
(options?: ReadStreamOptions): Promise<StreamState<TChunk>>;
|
|
12
|
+
}
|
|
13
|
+
interface WorkflowStreamInfoReader {
|
|
14
|
+
(): Promise<StreamInfo>;
|
|
15
|
+
}
|
|
16
|
+
interface WorkflowStreamChangeWaiter {
|
|
17
|
+
(options: {
|
|
18
|
+
readonly signal?: AbortSignal;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
interface WorkflowStreamWaitOptions {
|
|
22
|
+
readonly waitForChange?: WorkflowStreamChangeWaiter;
|
|
23
|
+
}
|
|
24
|
+
type WorkflowStreamStore = WorkflowRunReaderRepository & WorkflowEventReader & WorkflowEventHistoryWatcher;
|
|
25
|
+
interface WorkflowStreamServiceOptions {
|
|
26
|
+
readonly store: WorkflowStreamStore;
|
|
27
|
+
}
|
|
28
|
+
declare function getStreamInfoForRun(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName): Promise<StreamInfo>;
|
|
29
|
+
declare function readStreamForRun<TChunk = unknown>(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName, readOptions?: ReadStreamOptions): Promise<StreamState<TChunk>>;
|
|
30
|
+
declare function readStreamPageForRun<TChunk = unknown>(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName, readOptions?: ReadStreamPageOptions): Promise<StreamPage<TChunk>>;
|
|
31
|
+
declare function followStreamForRun<TChunk = unknown>(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName, followOptions?: FollowStreamOptions): AsyncIterable<StreamUpdate<TChunk>>;
|
|
32
|
+
declare function waitForStreamForRun(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName, waitOptions?: WaitStreamOptions): Promise<StreamInfo | undefined>;
|
|
33
|
+
declare function waitForStreamChunkForRun<TChunk = unknown>(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName, afterIndex: number, waitOptions?: WaitStreamOptions): Promise<StreamChunk<TChunk> | undefined>;
|
|
34
|
+
declare function waitForStreamTerminalForRun(service: WorkflowStreamServiceOptions, runId: RunId, streamIdOrName: StreamIdOrName, waitOptions?: WaitStreamOptions): Promise<StreamInfo | undefined>;
|
|
35
|
+
declare function createWorkflowStepStreamApi(environment: WorkflowExecutionEnvironment): WorkflowStepStreamApi;
|
|
36
|
+
declare function createStream<TChunk>(environment: WorkflowExecutionEnvironment, identity: WorkflowStepIdentity<"stream">, name: string, options?: CreateStreamOptions): Stream<TChunk>;
|
|
37
|
+
declare class Stream<TChunk> implements Stream$1<TChunk> {
|
|
38
|
+
#private;
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly contentType?: string;
|
|
42
|
+
readonly metadata?: unknown;
|
|
43
|
+
constructor(environment: WorkflowExecutionEnvironment, identity: WorkflowStepIdentity<"stream">, name: string, options?: CreateStreamOptions);
|
|
44
|
+
write(chunk: TChunk): Promise<void>;
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
error(error: unknown): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
declare function readStream<TChunk = unknown>(runId: RunId, events: readonly EventRecord[], streamIdOrName: StreamIdOrName, options?: ReadStreamOptions): StreamState<TChunk>;
|
|
49
|
+
declare function followStream<TChunk = unknown>(read: WorkflowStreamReader<TChunk>, options?: FollowStreamOptions, waitOptions?: WorkflowStreamWaitOptions): AsyncIterable<StreamUpdate<TChunk>>;
|
|
50
|
+
declare function waitForStream(readInfo: WorkflowStreamInfoReader, options?: WaitStreamOptions, waitOptions?: WorkflowStreamWaitOptions): Promise<StreamInfo | undefined>;
|
|
51
|
+
declare function waitForStreamChunk<TChunk = unknown>(read: WorkflowStreamReader<TChunk>, afterIndex: number, options?: WaitStreamOptions, waitOptions?: WorkflowStreamWaitOptions): Promise<StreamChunk<TChunk> | undefined>;
|
|
52
|
+
declare function waitForStreamTerminal(readInfo: WorkflowStreamInfoReader, options?: WaitStreamOptions, waitOptions?: WorkflowStreamWaitOptions): Promise<StreamInfo | undefined>;
|
|
53
|
+
declare function getStreamInfo(runId: RunId, events: readonly EventRecord[], streamIdOrName: StreamIdOrName): StreamInfo;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createStream, createWorkflowStepStreamApi, followStream, followStreamForRun, getStreamInfo, getStreamInfoForRun, readStream, readStreamForRun, readStreamPageForRun, waitForStream, waitForStreamChunk, waitForStreamChunkForRun, waitForStreamForRun, waitForStreamTerminal, waitForStreamTerminalForRun };
|