@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,29 @@
|
|
|
1
|
+
import { RunId } from "../types/run-id.mjs";
|
|
2
|
+
import { WorkflowImplementation } from "../types/definition.mjs";
|
|
3
|
+
import { ExecutionResult, WorkflowHandle } from "../types/result.mjs";
|
|
4
|
+
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
5
|
+
import { WorkflowExecutionOptions, WorkflowResumeOptions } from "../types/run-options.mjs";
|
|
6
|
+
import { WorkflowConditionalEventAppender, WorkflowEventReader, WorkflowLockConditionalWriterRepository, WorkflowLockListerRepository, WorkflowRunReaderRepository, WorkflowRunWriterRepository, WorkflowStepAttemptLookup } from "../types/store.mjs";
|
|
7
|
+
import { WorkflowRunStarter } from "../types/engine.mjs";
|
|
8
|
+
import { WorkflowExecutionServiceOptions } from "./execution-service.mjs";
|
|
9
|
+
//#region src/engine/execution-api.d.ts
|
|
10
|
+
interface WorkflowEngineExecutionApi {
|
|
11
|
+
runWorkflow<TInput, TOutput, TRawInput = TInput>(implementation: WorkflowImplementation<TInput, TOutput, TRawInput>, input: TRawInput, options?: WorkflowExecutionOptions): Promise<WorkflowHandle<TOutput>>;
|
|
12
|
+
runWorkflowNow<TInput, TOutput, TRawInput = TInput>(implementation: WorkflowImplementation<TInput, TOutput, TRawInput>, input: TRawInput, options?: WorkflowExecutionOptions): Promise<ExecutionResult<TOutput>>;
|
|
13
|
+
resumeWorkflow<TInput, TOutput, TRawInput = TInput>(implementation: WorkflowImplementation<TInput, TOutput, TRawInput>, runId: RunId, options?: WorkflowResumeOptions): Promise<ExecutionResult<TOutput>>;
|
|
14
|
+
}
|
|
15
|
+
type WorkflowEngineExecutionApiStore = WorkflowRunReaderRepository & WorkflowRunWriterRepository & WorkflowConditionalEventAppender & WorkflowEventReader & WorkflowStepAttemptLookup & WorkflowLockListerRepository & WorkflowLockConditionalWriterRepository;
|
|
16
|
+
interface WorkflowEngineExecutionResumer {
|
|
17
|
+
resumeWorkflow<TInput, TOutput, TRawInput = TInput>(implementation: WorkflowImplementation<TInput, TOutput, TRawInput>, runId: RunId, options?: WorkflowResumeOptions): Promise<ExecutionResult<TOutput>>;
|
|
18
|
+
}
|
|
19
|
+
interface WorkflowEngineExecutionApiOptions {
|
|
20
|
+
readonly store: WorkflowEngineExecutionApiStore;
|
|
21
|
+
readonly now: () => Temporal.Instant;
|
|
22
|
+
readonly executionService: WorkflowExecutionServiceOptions;
|
|
23
|
+
readonly emitResultLifecycleEvent: <TOutput>(result: ExecutionResult<TOutput>, previous?: WorkflowRunRecord) => Promise<ExecutionResult<TOutput>>;
|
|
24
|
+
readonly starter: WorkflowRunStarter;
|
|
25
|
+
readonly resumer: WorkflowEngineExecutionResumer;
|
|
26
|
+
}
|
|
27
|
+
declare function createWorkflowEngineExecutionApi(service: WorkflowEngineExecutionApiOptions): WorkflowEngineExecutionApi;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { WorkflowEngineExecutionApi, createWorkflowEngineExecutionApi };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getRequiredRun } from "../utility.mjs";
|
|
2
|
+
import { makeCanceledRunResult, makeCompletedRunResult } from "./run-utils.mjs";
|
|
3
|
+
import { failRunForDeadline, requireDefinitionMatchesRun } from "./state.mjs";
|
|
4
|
+
import { executeWorkflowRun } from "./execution-service.mjs";
|
|
5
|
+
//#region src/engine/execution-api.ts
|
|
6
|
+
function createWorkflowEngineExecutionApi(service) {
|
|
7
|
+
return {
|
|
8
|
+
async runWorkflow(implementation, input, executionOptions) {
|
|
9
|
+
return await service.starter.startWorkflow(implementation.definition, input, executionOptions?.start);
|
|
10
|
+
},
|
|
11
|
+
async runWorkflowNow(implementation, input, executionOptions) {
|
|
12
|
+
const handle = await service.starter.startWorkflow(implementation.definition, input, executionOptions?.start);
|
|
13
|
+
return await service.resumer.resumeWorkflow(implementation, handle.runId, { signal: executionOptions?.signal });
|
|
14
|
+
},
|
|
15
|
+
async resumeWorkflow(implementation, runId, resumeOptions) {
|
|
16
|
+
const run = await getRequiredRun(service.store, runId);
|
|
17
|
+
requireDefinitionMatchesRun(implementation.definition, run);
|
|
18
|
+
if (run.status === "completed") return makeCompletedRunResult(run);
|
|
19
|
+
if (run.status === "canceled") return makeCanceledRunResult(run);
|
|
20
|
+
const timestamp = service.now();
|
|
21
|
+
if (run.deadlineAt !== void 0 && Temporal.Instant.compare(run.deadlineAt, timestamp) <= 0) return await service.emitResultLifecycleEvent(await failRunForDeadline(service.store, run, run.deadlineAt, timestamp), run);
|
|
22
|
+
const availableAt = run.availableAt;
|
|
23
|
+
if (availableAt !== void 0 && Temporal.Instant.compare(availableAt, timestamp) > 0) return {
|
|
24
|
+
kind: "waiting",
|
|
25
|
+
run,
|
|
26
|
+
availableAt
|
|
27
|
+
};
|
|
28
|
+
return await executeWorkflowRun(service.executionService, implementation, run, resumeOptions);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createWorkflowEngineExecutionApi };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RunId } from "../types/run-id.mjs";
|
|
2
|
+
import { WorkflowImplementation } from "../types/definition.mjs";
|
|
3
|
+
import { ExecutionResult } from "../types/result.mjs";
|
|
4
|
+
import { Telemetry } from "../types/telemetry.mjs";
|
|
5
|
+
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
6
|
+
import { EventRecord } from "../types/events.mjs";
|
|
7
|
+
import { WorkflowResumeOptions } from "../types/run-options.mjs";
|
|
8
|
+
import { WorkflowConditionalEventAppender, WorkflowEventReader, WorkflowLockConditionalWriterRepository, WorkflowLockListerRepository, WorkflowMessageIdempotencyIndexLookup, WorkflowRunListerRepository, WorkflowRunReaderRepository, WorkflowRunWriterRepository, WorkflowStepAttemptLookup } from "../types/store.mjs";
|
|
9
|
+
import { WorkflowDeterministicBytesContext, WorkflowDeterministicValueContext, WorkflowExecutionLimits, WorkflowRecordedIdContext } from "../types/engine-options.mjs";
|
|
10
|
+
import { WorkflowChildWorkflowEngine } from "./child-workflow.mjs";
|
|
11
|
+
import { WorkflowStepLockEngine } from "./lock.mjs";
|
|
12
|
+
import { Logger } from "@temelj/log";
|
|
13
|
+
//#region src/engine/execution-service.d.ts
|
|
14
|
+
type WorkflowExecutionServiceStore = WorkflowRunReaderRepository & WorkflowRunListerRepository & WorkflowRunWriterRepository & WorkflowMessageIdempotencyIndexLookup & WorkflowConditionalEventAppender & WorkflowEventReader & WorkflowStepAttemptLookup & WorkflowLockListerRepository & WorkflowLockConditionalWriterRepository;
|
|
15
|
+
type WorkflowExecutionStepRuntime = WorkflowChildWorkflowEngine & WorkflowStepLockEngine;
|
|
16
|
+
interface WorkflowExecutionServiceOptions {
|
|
17
|
+
readonly store: WorkflowExecutionServiceStore;
|
|
18
|
+
readonly now: () => Temporal.Instant;
|
|
19
|
+
readonly createRecordedId: (context: WorkflowRecordedIdContext) => string;
|
|
20
|
+
readonly createDeterministicRandom: (context: WorkflowDeterministicValueContext) => number;
|
|
21
|
+
readonly createDeterministicUuid: (context: WorkflowDeterministicValueContext) => string;
|
|
22
|
+
readonly createDeterministicBytes: (context: WorkflowDeterministicBytesContext) => Uint8Array;
|
|
23
|
+
readonly maximumStepAttemptsPerRun: number;
|
|
24
|
+
readonly limits: WorkflowExecutionLimits;
|
|
25
|
+
readonly engine: WorkflowExecutionStepRuntime;
|
|
26
|
+
readonly readCurrentRunResult: <TOutput>(runId: RunId) => Promise<ExecutionResult<TOutput>>;
|
|
27
|
+
readonly emitResultLifecycleEvent: <TOutput>(result: ExecutionResult<TOutput>, previousRun?: WorkflowRunRecord) => Promise<ExecutionResult<TOutput>>;
|
|
28
|
+
readonly observeRunEvent: (run: WorkflowRunRecord, previousRun?: WorkflowRunRecord) => void;
|
|
29
|
+
readonly observeDurableEventAppended: (runId: RunId, event: EventRecord, events: readonly EventRecord[]) => void;
|
|
30
|
+
readonly observeMessageSent: (runId: RunId, event: Extract<EventRecord, {
|
|
31
|
+
readonly kind: "message_sent";
|
|
32
|
+
}>) => void;
|
|
33
|
+
readonly observeChildWorkflowStarted: (runId: RunId, event: Extract<EventRecord, {
|
|
34
|
+
readonly kind: "child_workflow_started";
|
|
35
|
+
}>) => void;
|
|
36
|
+
readonly telemetry?: Telemetry;
|
|
37
|
+
readonly logger: Logger;
|
|
38
|
+
}
|
|
39
|
+
declare function executeWorkflowRun<TInput, TOutput, TRawInput = TInput>(service: WorkflowExecutionServiceOptions, implementation: WorkflowImplementation<TInput, TOutput, TRawInput>, run: WorkflowRunRecord, executionOptions: WorkflowResumeOptions | undefined): Promise<ExecutionResult<TOutput>>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { WorkflowExecutionServiceOptions, executeWorkflowRun };
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { WorkflowNonRetryableError } from "../errors/failures.mjs";
|
|
2
|
+
import { getRequiredRun, isAbortError, nextRunAttempt } from "../utility.mjs";
|
|
3
|
+
import { WORKFLOW_ATTRIBUTES, WORKFLOW_SYSTEM, withRunTelemetry } from "../telemetry.mjs";
|
|
4
|
+
import { serializeError, toOptionalPersistedValue } from "./serialization.mjs";
|
|
5
|
+
import { WorkflowHistory } from "../history/mod.mjs";
|
|
6
|
+
import { enforceWorkflowEventHistoryNextLimit, nextRetryAt, nextWorkflowRetryAttempt, resolveWorkflowRetryConfig, retryClassificationRetryAt, shouldRetryWorkflowAttempt } from "./retry.mjs";
|
|
7
|
+
import { makeCanceledRunResult, makeCompletedRunResult } from "./run-utils.mjs";
|
|
8
|
+
import { WorkflowSuspended, failRunForDeadline, isCurrentExecutionOwner, patchCurrentExecutionRun, patchRun, releaseLocksForRun, requireDefinitionMatchesRun, transitionRunToCompleted, transitionRunToExecutionWait, transitionRunToFailed, transitionRunToRunning, wakeParentRunForTerminalChild } from "./state.mjs";
|
|
9
|
+
import { createWorkflowDeterministicApi } from "./deterministic.mjs";
|
|
10
|
+
import { createStepApi } from "./step-api.mjs";
|
|
11
|
+
//#region src/engine/execution-service.ts
|
|
12
|
+
async function executeWorkflowRun(service, implementation, run, executionOptions) {
|
|
13
|
+
return await executeWorkflowRunCore(service, implementation, run, executionOptions);
|
|
14
|
+
}
|
|
15
|
+
async function executeWorkflowRunCore(service, implementation, run, executionOptions) {
|
|
16
|
+
requireDefinitionMatchesRun(implementation.definition, run);
|
|
17
|
+
const workflowRetry = resolveWorkflowRetryConfig(implementation.config.retry, {
|
|
18
|
+
maximumAttempts: 1,
|
|
19
|
+
backoffCoefficient: 2
|
|
20
|
+
}, "Workflow retry");
|
|
21
|
+
const startedAt = service.now();
|
|
22
|
+
const isClaimedRun = run.status === "running" && run.workerId !== void 0;
|
|
23
|
+
enforceWorkflowEventHistoryNextLimit(await service.store.getEvents(run.id), service.limits);
|
|
24
|
+
const runningRun = await patchRun(service.store, run, transitionRunToRunning(run, startedAt, isClaimedRun ? run.attempts : nextRunAttempt(run.attempts)));
|
|
25
|
+
const startedEvents = await service.store.appendEventIfRunCurrent(runningRun, {
|
|
26
|
+
kind: "workflow_started",
|
|
27
|
+
timestamp: startedAt
|
|
28
|
+
});
|
|
29
|
+
if (startedEvents === void 0) return await service.readCurrentRunResult(run.id);
|
|
30
|
+
if (isClaimedRun) service.observeRunEvent(run);
|
|
31
|
+
service.observeRunEvent(runningRun, run);
|
|
32
|
+
service.observeDurableEventAppended(run.id, startedEvents.at(-1), startedEvents);
|
|
33
|
+
const history = new WorkflowHistory(startedEvents);
|
|
34
|
+
const replaying = history.hasPriorWorkflowStart();
|
|
35
|
+
const runLogger = scopedRunLogger(service.logger, runningRun, false);
|
|
36
|
+
const handlerLogger = replaying ? replayAwareLogger(runLogger, history) : runLogger;
|
|
37
|
+
const environment = {
|
|
38
|
+
store: service.store,
|
|
39
|
+
runId: run.id,
|
|
40
|
+
history,
|
|
41
|
+
now: service.now,
|
|
42
|
+
createRecordedId: service.createRecordedId,
|
|
43
|
+
createDeterministicRandom: service.createDeterministicRandom,
|
|
44
|
+
createDeterministicUuid: service.createDeterministicUuid,
|
|
45
|
+
createDeterministicBytes: service.createDeterministicBytes,
|
|
46
|
+
maximumStepAttemptsPerRun: service.maximumStepAttemptsPerRun,
|
|
47
|
+
limits: service.limits,
|
|
48
|
+
executionOwner: runningRun,
|
|
49
|
+
telemetry: service.telemetry,
|
|
50
|
+
logger: handlerLogger,
|
|
51
|
+
replaying,
|
|
52
|
+
observeDurableEventAppended: service.observeDurableEventAppended,
|
|
53
|
+
observeMessageSent: service.observeMessageSent,
|
|
54
|
+
observeChildWorkflowStarted: service.observeChildWorkflowStarted
|
|
55
|
+
};
|
|
56
|
+
const executionAbort = watchRunCancellationWithSignal(service.store, runningRun, executionOptions?.signal ?? new AbortController().signal);
|
|
57
|
+
const executionSignal = executionAbort.signal;
|
|
58
|
+
const deterministic = createWorkflowDeterministicApi(environment);
|
|
59
|
+
const step = createStepApi(environment, service.engine, executionSignal, deterministic);
|
|
60
|
+
const telemetryContext = {
|
|
61
|
+
run: runningRun,
|
|
62
|
+
...run.telemetryContext === void 0 ? {} : { traceContext: run.telemetryContext }
|
|
63
|
+
};
|
|
64
|
+
const executeClaimedRun = async () => {
|
|
65
|
+
try {
|
|
66
|
+
history.requireStartedEventsAreUnique();
|
|
67
|
+
history.requireTerminalEventsHaveStartedEvents();
|
|
68
|
+
history.requireTerminalEventsAreUnique();
|
|
69
|
+
const output = await implementation.handler({
|
|
70
|
+
input: runningRun.input,
|
|
71
|
+
step,
|
|
72
|
+
deterministic,
|
|
73
|
+
log: handlerLogger,
|
|
74
|
+
run: {
|
|
75
|
+
id: runningRun.id,
|
|
76
|
+
workflowName: runningRun.workflowName,
|
|
77
|
+
...runningRun.workflowVersion === void 0 ? {} : { workflowVersion: runningRun.workflowVersion },
|
|
78
|
+
createdAt: runningRun.createdAt
|
|
79
|
+
},
|
|
80
|
+
signal: executionSignal,
|
|
81
|
+
version: runningRun.workflowVersion
|
|
82
|
+
});
|
|
83
|
+
history.requireReplayConsumed();
|
|
84
|
+
const latestRun = await getRequiredRun(service.store, run.id);
|
|
85
|
+
if (latestRun.status === "canceled") return makeCanceledRunResult(latestRun);
|
|
86
|
+
if (!isCurrentExecutionOwner(latestRun, runningRun)) return await service.readCurrentRunResult(run.id);
|
|
87
|
+
const completedAt = service.now();
|
|
88
|
+
enforceWorkflowEventHistoryNextLimit(history.events, service.limits);
|
|
89
|
+
const completedRun = await patchCurrentExecutionRun(service.store, runningRun, transitionRunToCompleted(runningRun, toOptionalPersistedValue(output, "workflow output", service.limits), completedAt));
|
|
90
|
+
if (completedRun === void 0) return await service.readCurrentRunResult(run.id);
|
|
91
|
+
const completedEvents = await service.store.appendEventIfRunCurrent(completedRun, {
|
|
92
|
+
kind: "workflow_completed",
|
|
93
|
+
timestamp: completedAt
|
|
94
|
+
});
|
|
95
|
+
if (completedEvents === void 0) return await service.readCurrentRunResult(run.id);
|
|
96
|
+
service.observeDurableEventAppended(run.id, completedEvents.at(-1), completedEvents);
|
|
97
|
+
await releaseLocksForRun(service.store, completedRun.id, completedAt);
|
|
98
|
+
await wakeParentRunForTerminalChild(service.store, completedRun, completedAt);
|
|
99
|
+
return await service.emitResultLifecycleEvent(makeCompletedRunResult(completedRun), runningRun);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
const latestRun = await service.store.getRun(run.id);
|
|
102
|
+
if (latestRun?.status === "canceled") return makeCanceledRunResult(latestRun);
|
|
103
|
+
if (latestRun === void 0 || !isCurrentExecutionOwner(latestRun, runningRun)) return await service.readCurrentRunResult(run.id);
|
|
104
|
+
if (executionOptions?.signal?.aborted === true && isAbortError(error)) {
|
|
105
|
+
const abortedAt = service.now();
|
|
106
|
+
const waitingRun = await patchCurrentExecutionRun(service.store, runningRun, transitionRunToExecutionWait(runningRun, abortedAt, abortedAt));
|
|
107
|
+
if (waitingRun === void 0) return await service.readCurrentRunResult(run.id);
|
|
108
|
+
return await service.emitResultLifecycleEvent({
|
|
109
|
+
kind: "waiting",
|
|
110
|
+
run: waitingRun,
|
|
111
|
+
availableAt: abortedAt
|
|
112
|
+
}, runningRun);
|
|
113
|
+
}
|
|
114
|
+
if (error instanceof WorkflowSuspended) {
|
|
115
|
+
const suspendedAt = service.now();
|
|
116
|
+
const deadlineAt = runningRun.deadlineAt;
|
|
117
|
+
if (deadlineAt !== void 0 && (error.retryReason !== void 0 ? Temporal.Instant.compare(deadlineAt, error.availableAt) <= 0 : Temporal.Instant.compare(deadlineAt, error.availableAt) < 0)) return await service.emitResultLifecycleEvent(await failRunForDeadline(service.store, runningRun, deadlineAt, suspendedAt, runningRun), runningRun);
|
|
118
|
+
const waitingRun = await patchCurrentExecutionRun(service.store, runningRun, transitionRunToExecutionWait(runningRun, suspendedAt, error.availableAt, {
|
|
119
|
+
retryAt: error.retryAt,
|
|
120
|
+
retryReason: error.retryReason,
|
|
121
|
+
retryAttempt: error.retryAttempt,
|
|
122
|
+
retryStepId: error.retryStep?.id,
|
|
123
|
+
retryStepName: error.retryStep?.name
|
|
124
|
+
}));
|
|
125
|
+
if (waitingRun === void 0) return await service.readCurrentRunResult(run.id);
|
|
126
|
+
return await service.emitResultLifecycleEvent({
|
|
127
|
+
kind: "waiting",
|
|
128
|
+
run: waitingRun,
|
|
129
|
+
availableAt: error.availableAt
|
|
130
|
+
}, runningRun);
|
|
131
|
+
}
|
|
132
|
+
const failedAt = service.now();
|
|
133
|
+
const serialized = serializeError(error);
|
|
134
|
+
const workflowAttempt = runningRun.attempts ?? 1;
|
|
135
|
+
const failWorkflowRun = async (errorRecord) => {
|
|
136
|
+
const failedRun = await patchCurrentExecutionRun(service.store, runningRun, transitionRunToFailed(runningRun, errorRecord, failedAt, "failed"));
|
|
137
|
+
if (failedRun === void 0) return await service.readCurrentRunResult(run.id);
|
|
138
|
+
const failedEvents = await service.store.appendEventIfRunCurrent(failedRun, {
|
|
139
|
+
kind: "workflow_failed",
|
|
140
|
+
timestamp: failedAt
|
|
141
|
+
});
|
|
142
|
+
if (failedEvents === void 0) return await service.readCurrentRunResult(run.id);
|
|
143
|
+
service.observeDurableEventAppended(run.id, failedEvents.at(-1), failedEvents);
|
|
144
|
+
await releaseLocksForRun(service.store, failedRun.id, failedAt);
|
|
145
|
+
await wakeParentRunForTerminalChild(service.store, failedRun, failedAt);
|
|
146
|
+
return await service.emitResultLifecycleEvent({
|
|
147
|
+
kind: "failed",
|
|
148
|
+
run: failedRun,
|
|
149
|
+
error: errorRecord
|
|
150
|
+
}, runningRun);
|
|
151
|
+
};
|
|
152
|
+
if (!(error instanceof WorkflowNonRetryableError) && shouldRetryWorkflowAttempt(workflowRetry, workflowAttempt)) {
|
|
153
|
+
let retryAt;
|
|
154
|
+
let nextAttempt;
|
|
155
|
+
try {
|
|
156
|
+
retryAt = retryClassificationRetryAt(failedAt, error, "Workflow retry classification") ?? nextRetryAt(failedAt, workflowRetry, workflowAttempt, "Workflow retry delay") ?? failedAt;
|
|
157
|
+
nextAttempt = nextWorkflowRetryAttempt(workflowAttempt);
|
|
158
|
+
} catch (retryError) {
|
|
159
|
+
return await failWorkflowRun(serializeError(retryError));
|
|
160
|
+
}
|
|
161
|
+
const deadlineAt = runningRun.deadlineAt;
|
|
162
|
+
if (deadlineAt !== void 0 && Temporal.Instant.compare(deadlineAt, retryAt) <= 0) return await service.emitResultLifecycleEvent(await failRunForDeadline(service.store, runningRun, deadlineAt, failedAt, runningRun), runningRun);
|
|
163
|
+
const waitingRun = await patchCurrentExecutionRun(service.store, runningRun, transitionRunToExecutionWait(runningRun, failedAt, retryAt, {
|
|
164
|
+
retryAt,
|
|
165
|
+
retryReason: "workflow",
|
|
166
|
+
retryAttempt: nextAttempt,
|
|
167
|
+
error: serialized
|
|
168
|
+
}));
|
|
169
|
+
if (waitingRun === void 0) return await service.readCurrentRunResult(run.id);
|
|
170
|
+
return await service.emitResultLifecycleEvent({
|
|
171
|
+
kind: "waiting",
|
|
172
|
+
run: waitingRun,
|
|
173
|
+
availableAt: retryAt
|
|
174
|
+
}, runningRun);
|
|
175
|
+
}
|
|
176
|
+
return await failWorkflowRun(serialized);
|
|
177
|
+
} finally {
|
|
178
|
+
executionAbort.dispose();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
try {
|
|
182
|
+
const result = await withRunTelemetry(service.telemetry, telemetryContext, executeClaimedRun);
|
|
183
|
+
try {
|
|
184
|
+
service.telemetry?.recordRunExecution?.({
|
|
185
|
+
...telemetryContext,
|
|
186
|
+
result
|
|
187
|
+
});
|
|
188
|
+
} catch {
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
return result;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
try {
|
|
194
|
+
service.telemetry?.recordRunExecution?.({
|
|
195
|
+
...telemetryContext,
|
|
196
|
+
error
|
|
197
|
+
});
|
|
198
|
+
} catch {
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function scopedRunLogger(logger, run, replaying) {
|
|
205
|
+
return logger.child({
|
|
206
|
+
[WORKFLOW_ATTRIBUTES.system]: WORKFLOW_SYSTEM,
|
|
207
|
+
[WORKFLOW_ATTRIBUTES.workflowName]: run.workflowName,
|
|
208
|
+
...run.workflowVersion === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workflowVersion]: run.workflowVersion },
|
|
209
|
+
[WORKFLOW_ATTRIBUTES.runId]: run.id,
|
|
210
|
+
[WORKFLOW_ATTRIBUTES.namespace]: run.namespace,
|
|
211
|
+
[WORKFLOW_ATTRIBUTES.runAttempt]: run.attempts,
|
|
212
|
+
...run.workerId === void 0 ? {} : { [WORKFLOW_ATTRIBUTES.workerId]: run.workerId },
|
|
213
|
+
[WORKFLOW_ATTRIBUTES.replay]: replaying
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
function replayAwareLogger(logger, history) {
|
|
217
|
+
return new ReplayAwareLogger(logger, history);
|
|
218
|
+
}
|
|
219
|
+
var ReplayAwareLogger = class ReplayAwareLogger {
|
|
220
|
+
#logger;
|
|
221
|
+
#history;
|
|
222
|
+
constructor(logger, history) {
|
|
223
|
+
this.#logger = logger;
|
|
224
|
+
this.#history = history;
|
|
225
|
+
}
|
|
226
|
+
child(attributes) {
|
|
227
|
+
return new ReplayAwareLogger(this.#logger.child(attributes), this.#history);
|
|
228
|
+
}
|
|
229
|
+
log(level, message, attributes) {
|
|
230
|
+
if (this.#history.isReplayConsumed()) this.#logger.log(level, message, attributes);
|
|
231
|
+
}
|
|
232
|
+
trace(message, attributes) {
|
|
233
|
+
if (this.#history.isReplayConsumed()) this.#logger.trace(message, attributes);
|
|
234
|
+
}
|
|
235
|
+
debug(message, attributes) {
|
|
236
|
+
if (this.#history.isReplayConsumed()) this.#logger.debug(message, attributes);
|
|
237
|
+
}
|
|
238
|
+
info(message, attributes) {
|
|
239
|
+
if (this.#history.isReplayConsumed()) this.#logger.info(message, attributes);
|
|
240
|
+
}
|
|
241
|
+
warn(message, attributes) {
|
|
242
|
+
if (this.#history.isReplayConsumed()) this.#logger.warn(message, attributes);
|
|
243
|
+
}
|
|
244
|
+
error(message, attributes) {
|
|
245
|
+
if (this.#history.isReplayConsumed()) this.#logger.error(message, attributes);
|
|
246
|
+
}
|
|
247
|
+
fatal(message, attributes) {
|
|
248
|
+
if (this.#history.isReplayConsumed()) this.#logger.fatal(message, attributes);
|
|
249
|
+
}
|
|
250
|
+
async flush() {
|
|
251
|
+
await this.#logger.flush?.();
|
|
252
|
+
}
|
|
253
|
+
async close() {
|
|
254
|
+
await this.#logger.close?.();
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
function watchRunCancellationWithSignal(store, executionOwner, parentSignal) {
|
|
258
|
+
const controller = new AbortController();
|
|
259
|
+
let disposed = false;
|
|
260
|
+
let polling = false;
|
|
261
|
+
let interval;
|
|
262
|
+
const abortFromParent = () => {
|
|
263
|
+
controller.abort(parentSignal.reason);
|
|
264
|
+
};
|
|
265
|
+
if (parentSignal.aborted) abortFromParent();
|
|
266
|
+
else parentSignal.addEventListener("abort", abortFromParent, { once: true });
|
|
267
|
+
const poll = () => {
|
|
268
|
+
if (disposed || polling || controller.signal.aborted) return;
|
|
269
|
+
polling = true;
|
|
270
|
+
store.getRun(executionOwner.id).then((run) => {
|
|
271
|
+
if (!disposed && !controller.signal.aborted && run?.status === "canceled" && run.id === executionOwner.id && run.attempts === executionOwner.attempts) controller.abort(new DOMException("Workflow run canceled", "AbortError"));
|
|
272
|
+
}).catch(() => {}).finally(() => {
|
|
273
|
+
polling = false;
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
interval = setInterval(poll, 25);
|
|
277
|
+
poll();
|
|
278
|
+
return {
|
|
279
|
+
signal: controller.signal,
|
|
280
|
+
dispose() {
|
|
281
|
+
disposed = true;
|
|
282
|
+
if (interval !== void 0) clearInterval(interval);
|
|
283
|
+
parentSignal.removeEventListener("abort", abortFromParent);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
//#endregion
|
|
288
|
+
export { executeWorkflowRun };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { MessageId } from "../types/message-id.mjs";
|
|
2
|
+
import { RunId } from "../types/run-id.mjs";
|
|
3
|
+
import { CreateHookOptions, CreateWebhookOptions, Hook as Hook$1, HookInspection, ResumeHookOptions, Webhook as Webhook$1 } from "../types/hook.mjs";
|
|
4
|
+
import { WorkflowStepHookApi } from "../types/step.mjs";
|
|
5
|
+
import { Telemetry, TelemetryContext } from "../types/telemetry.mjs";
|
|
6
|
+
import { WorkflowRunRecord } from "../types/run.mjs";
|
|
7
|
+
import { EventRecord } from "../types/events.mjs";
|
|
8
|
+
import { WorkflowConditionalEventAppender, WorkflowEventReader, WorkflowMessageIdempotencyIndexLookup, WorkflowRunConditionalWriterRepository, WorkflowRunReaderRepository } from "../types/store.mjs";
|
|
9
|
+
import { WorkflowExecutionLimits } from "../types/engine-options.mjs";
|
|
10
|
+
import { WorkflowExecutionEnvironment } from "../types/engine.mjs";
|
|
11
|
+
import { StorageValue } from "@temelj/storage";
|
|
12
|
+
//#region src/engine/hooks.d.ts
|
|
13
|
+
type WorkflowHookStore = WorkflowMessageIdempotencyIndexLookup & WorkflowRunReaderRepository & WorkflowEventReader & WorkflowConditionalEventAppender & WorkflowRunConditionalWriterRepository;
|
|
14
|
+
interface WorkflowHookServiceOptions {
|
|
15
|
+
readonly store: WorkflowHookStore;
|
|
16
|
+
readonly now: () => Temporal.Instant;
|
|
17
|
+
readonly limits: WorkflowExecutionLimits;
|
|
18
|
+
readonly emitMessageSent: (runId: RunId, event: Extract<EventRecord, {
|
|
19
|
+
readonly kind: "message_sent";
|
|
20
|
+
}>) => void;
|
|
21
|
+
readonly emitHookResumed: (runId: RunId, messageId: MessageId, payload: StorageValue | undefined, traceContext: TelemetryContext | undefined) => void;
|
|
22
|
+
readonly emitWebhookResumed: (runId: RunId, messageId: MessageId, payload: StorageValue | undefined, traceContext: TelemetryContext | undefined) => void;
|
|
23
|
+
readonly telemetry?: Telemetry;
|
|
24
|
+
}
|
|
25
|
+
declare function createHook<TPayload>(runId: RunId, options: CreateHookOptions, wait: () => Promise<unknown>): Hook$1<TPayload>;
|
|
26
|
+
declare function createWebhook<TPayload>(runId: RunId, options: CreateWebhookOptions, wait: () => Promise<unknown>): Webhook$1<TPayload>;
|
|
27
|
+
declare function createWorkflowStepHookApi(environment: WorkflowExecutionEnvironment): WorkflowStepHookApi;
|
|
28
|
+
declare class Hook<TPayload> implements Hook$1<TPayload> {
|
|
29
|
+
#private;
|
|
30
|
+
readonly token: string;
|
|
31
|
+
readonly runId: RunId;
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly messageId: MessageId;
|
|
34
|
+
constructor(runId: RunId, options: CreateHookOptions, wait: () => Promise<unknown>);
|
|
35
|
+
wait(): Promise<TPayload>;
|
|
36
|
+
then<TResult1 = TPayload, TResult2 = never>(onfulfilled?: ((value: TPayload) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
37
|
+
}
|
|
38
|
+
declare class Webhook<TPayload> implements Webhook$1<TPayload> {
|
|
39
|
+
#private;
|
|
40
|
+
readonly token: string;
|
|
41
|
+
readonly runId: RunId;
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly messageId: MessageId;
|
|
44
|
+
readonly metadata?: unknown;
|
|
45
|
+
constructor(runId: RunId, options: CreateWebhookOptions, wait: () => Promise<unknown>);
|
|
46
|
+
wait(): Promise<TPayload>;
|
|
47
|
+
then<TResult1 = TPayload, TResult2 = never>(onfulfilled?: ((value: TPayload) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): PromiseLike<TResult1 | TResult2>;
|
|
48
|
+
}
|
|
49
|
+
declare function resumeHook(token: string, options: ResumeHookOptions | undefined, service: WorkflowHookServiceOptions): Promise<void>;
|
|
50
|
+
declare function resumeWebhook(token: string, options: ResumeHookOptions | undefined, service: WorkflowHookServiceOptions): Promise<void>;
|
|
51
|
+
declare function disposeHook(token: string, service: WorkflowHookServiceOptions): Promise<HookInspection>;
|
|
52
|
+
declare function disposeWebhook(token: string, service: WorkflowHookServiceOptions): Promise<HookInspection>;
|
|
53
|
+
declare function getHookByToken(token: string, store: WorkflowRunReaderRepository & WorkflowEventReader, now: Temporal.Instant): Promise<HookInspection>;
|
|
54
|
+
declare function inspectHookToken(token: string, run: WorkflowRunRecord | undefined, events: readonly EventRecord[], now: Temporal.Instant): HookInspection;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { Hook, Webhook, createHook, createWebhook, createWorkflowStepHookApi, disposeHook, disposeWebhook, getHookByToken, inspectHookToken, resumeHook, resumeWebhook };
|