@workflow/core 5.2.3 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/capabilities.d.ts +2 -0
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +7 -1
- package/dist/classify-error.d.ts.map +1 -1
- package/dist/classify-error.js +3 -2
- package/dist/create-hook.d.ts +15 -0
- package/dist/create-hook.d.ts.map +1 -1
- package/dist/create-hook.js +1 -1
- package/dist/events-consumer.d.ts +98 -6
- package/dist/events-consumer.d.ts.map +1 -1
- package/dist/events-consumer.js +198 -13
- package/dist/flushable-stream.js +11 -2
- package/dist/global.d.ts +6 -0
- package/dist/global.d.ts.map +1 -1
- package/dist/global.js +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +65 -35
- package/dist/private.d.ts +41 -2
- package/dist/private.d.ts.map +1 -1
- package/dist/private.js +39 -4
- package/dist/replay-payload-cache.d.ts +13 -2
- package/dist/replay-payload-cache.d.ts.map +1 -1
- package/dist/replay-payload-cache.js +20 -10
- package/dist/runtime/after-terminal-write.d.ts +33 -0
- package/dist/runtime/after-terminal-write.d.ts.map +1 -0
- package/dist/runtime/after-terminal-write.js +23 -0
- package/dist/runtime/child-run-completion-notify.d.ts +36 -0
- package/dist/runtime/child-run-completion-notify.d.ts.map +1 -0
- package/dist/runtime/child-run-completion-notify.js +97 -0
- package/dist/runtime/child-run-completion.d.ts +45 -0
- package/dist/runtime/child-run-completion.d.ts.map +1 -0
- package/dist/runtime/child-run-completion.js +192 -0
- package/dist/runtime/constants.d.ts +161 -176
- package/dist/runtime/constants.d.ts.map +1 -1
- package/dist/runtime/constants.js +194 -273
- package/dist/runtime/delivery.d.ts +270 -0
- package/dist/runtime/delivery.d.ts.map +1 -0
- package/dist/runtime/delivery.js +325 -0
- package/dist/runtime/deployment-guard.d.ts +8 -1
- package/dist/runtime/deployment-guard.d.ts.map +1 -1
- package/dist/runtime/deployment-guard.js +12 -6
- package/dist/runtime/get-port-lazy.d.ts.map +1 -1
- package/dist/runtime/get-port-lazy.js +77 -14
- package/dist/runtime/helpers.d.ts +50 -4
- package/dist/runtime/helpers.d.ts.map +1 -1
- package/dist/runtime/helpers.js +88 -10
- package/dist/runtime/hook-creation.d.ts +45 -0
- package/dist/runtime/hook-creation.d.ts.map +1 -0
- package/dist/runtime/hook-creation.js +98 -0
- package/dist/runtime/hook-wake.d.ts +16 -14
- package/dist/runtime/hook-wake.d.ts.map +1 -1
- package/dist/runtime/hook-wake.js +31 -18
- package/dist/runtime/invocations.d.ts.map +1 -1
- package/dist/runtime/invocations.js +9 -3
- package/dist/runtime/out-of-band-observation.d.ts +28 -17
- package/dist/runtime/out-of-band-observation.d.ts.map +1 -1
- package/dist/runtime/out-of-band-observation.js +12 -3
- package/dist/runtime/quickjs-delivery-shared.d.ts +126 -0
- package/dist/runtime/quickjs-delivery-shared.d.ts.map +1 -0
- package/dist/runtime/quickjs-delivery-shared.js +176 -0
- package/dist/runtime/quickjs-log-view.d.ts +17 -0
- package/dist/runtime/quickjs-log-view.d.ts.map +1 -1
- package/dist/runtime/quickjs-log-view.js +31 -1
- package/dist/runtime/quickjs-pending-ops.d.ts +181 -0
- package/dist/runtime/quickjs-pending-ops.d.ts.map +1 -0
- package/dist/runtime/quickjs-pending-ops.js +633 -0
- package/dist/runtime/quickjs-runtime.d.ts +30 -5
- package/dist/runtime/quickjs-runtime.d.ts.map +1 -1
- package/dist/runtime/quickjs-runtime.js +546 -169
- package/dist/runtime/quickjs-serde.d.ts.map +1 -1
- package/dist/runtime/quickjs-serde.js +96 -5
- package/dist/runtime/replay-budget.d.ts +8 -1
- package/dist/runtime/replay-budget.d.ts.map +1 -1
- package/dist/runtime/replay-budget.js +12 -8
- package/dist/runtime/resume-hook.d.ts +15 -10
- package/dist/runtime/resume-hook.d.ts.map +1 -1
- package/dist/runtime/resume-hook.js +211 -65
- package/dist/runtime/run-spec-routing.d.ts +52 -0
- package/dist/runtime/run-spec-routing.d.ts.map +1 -0
- package/dist/runtime/run-spec-routing.js +78 -0
- package/dist/runtime/run-spec-version.d.ts +8 -4
- package/dist/runtime/run-spec-version.d.ts.map +1 -1
- package/dist/runtime/run-spec-version.js +11 -7
- package/dist/runtime/run.d.ts +29 -3
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +116 -11
- package/dist/runtime/runs.d.ts +58 -2
- package/dist/runtime/runs.d.ts.map +1 -1
- package/dist/runtime/runs.js +228 -30
- package/dist/runtime/spec8/constants.d.ts +177 -0
- package/dist/runtime/spec8/constants.d.ts.map +1 -0
- package/dist/runtime/spec8/constants.js +232 -0
- package/dist/runtime/spec8/count-step-started-events.d.ts.map +1 -0
- package/dist/runtime/spec8/count-step-started-events.js +72 -0
- package/dist/runtime/spec8/delivery.d.ts +6 -0
- package/dist/runtime/spec8/delivery.d.ts.map +1 -0
- package/dist/runtime/spec8/delivery.js +4250 -0
- package/dist/runtime/spec8/inline-steps-in-flight.d.ts +58 -0
- package/dist/runtime/spec8/inline-steps-in-flight.d.ts.map +1 -0
- package/dist/runtime/spec8/inline-steps-in-flight.js +104 -0
- package/dist/runtime/spec8/open-hook-wait-state.d.ts.map +1 -0
- package/dist/runtime/spec8/open-hook-wait-state.js +93 -0
- package/dist/runtime/{quickjs-entrypoint.d.ts → spec8/quickjs-entrypoint.d.ts} +0 -20
- package/dist/runtime/spec8/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/spec8/quickjs-entrypoint.js +1779 -0
- package/dist/runtime/{step-executor.d.ts → spec8/step-executor.d.ts} +11 -7
- package/dist/runtime/spec8/step-executor.d.ts.map +1 -0
- package/dist/runtime/spec8/step-executor.js +1134 -0
- package/dist/runtime/{step-ownership.d.ts → spec8/step-ownership.d.ts} +1 -1
- package/dist/runtime/spec8/step-ownership.d.ts.map +1 -0
- package/dist/runtime/spec8/step-ownership.js +114 -0
- package/dist/runtime/spec8/step-single-flight.d.ts +34 -0
- package/dist/runtime/spec8/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/spec8/step-single-flight.js +36 -0
- package/dist/runtime/{suspension-handler.d.ts → spec8/suspension-handler.d.ts} +68 -24
- package/dist/runtime/spec8/suspension-handler.d.ts.map +1 -0
- package/dist/runtime/spec8/suspension-handler.js +1291 -0
- package/dist/runtime/spec9/consume-after-commit.d.ts +33 -0
- package/dist/runtime/spec9/consume-after-commit.d.ts.map +1 -0
- package/dist/runtime/spec9/consume-after-commit.js +13 -0
- package/dist/runtime/spec9/consumed-position.d.ts +38 -0
- package/dist/runtime/spec9/consumed-position.d.ts.map +1 -0
- package/dist/runtime/spec9/consumed-position.js +48 -0
- package/dist/runtime/spec9/creator-rules.d.ts +220 -0
- package/dist/runtime/spec9/creator-rules.d.ts.map +1 -0
- package/dist/runtime/spec9/creator-rules.js +357 -0
- package/dist/runtime/spec9/deadline.d.ts +18 -0
- package/dist/runtime/spec9/deadline.d.ts.map +1 -0
- package/dist/runtime/spec9/deadline.js +27 -0
- package/dist/runtime/spec9/delivery.d.ts +17 -0
- package/dist/runtime/spec9/delivery.d.ts.map +1 -0
- package/dist/runtime/spec9/delivery.js +3837 -0
- package/dist/runtime/spec9/fence-refusals.d.ts +20 -0
- package/dist/runtime/spec9/fence-refusals.d.ts.map +1 -0
- package/dist/runtime/spec9/fence-refusals.js +55 -0
- package/dist/runtime/spec9/in-band-writer.d.ts +275 -0
- package/dist/runtime/spec9/in-band-writer.d.ts.map +1 -0
- package/dist/runtime/spec9/in-band-writer.js +831 -0
- package/dist/runtime/spec9/live-feed.d.ts +151 -0
- package/dist/runtime/spec9/live-feed.d.ts.map +1 -0
- package/dist/runtime/spec9/live-feed.js +311 -0
- package/dist/runtime/spec9/log-state.d.ts +137 -0
- package/dist/runtime/spec9/log-state.d.ts.map +1 -0
- package/dist/runtime/spec9/log-state.js +176 -0
- package/dist/runtime/spec9/quickjs-entrypoint.d.ts +185 -0
- package/dist/runtime/spec9/quickjs-entrypoint.d.ts.map +1 -0
- package/dist/runtime/spec9/quickjs-entrypoint.js +2332 -0
- package/dist/runtime/spec9/read-deadline.d.ts +46 -0
- package/dist/runtime/spec9/read-deadline.d.ts.map +1 -0
- package/dist/runtime/spec9/read-deadline.js +88 -0
- package/dist/runtime/spec9/run-ahead.d.ts +65 -0
- package/dist/runtime/spec9/run-ahead.d.ts.map +1 -0
- package/dist/runtime/spec9/run-ahead.js +102 -0
- package/dist/runtime/spec9/step-delivery.d.ts +111 -0
- package/dist/runtime/spec9/step-delivery.d.ts.map +1 -0
- package/dist/runtime/spec9/step-delivery.js +149 -0
- package/dist/runtime/spec9/step-executor.d.ts +217 -0
- package/dist/runtime/spec9/step-executor.d.ts.map +1 -0
- package/dist/runtime/spec9/step-executor.js +782 -0
- package/dist/runtime/spec9/step-handler.d.ts +92 -0
- package/dist/runtime/spec9/step-handler.d.ts.map +1 -0
- package/dist/runtime/spec9/step-handler.js +375 -0
- package/dist/runtime/spec9/step-message.d.ts +42 -0
- package/dist/runtime/spec9/step-message.d.ts.map +1 -0
- package/dist/runtime/spec9/step-message.js +81 -0
- package/dist/runtime/spec9/step-retention.d.ts +44 -0
- package/dist/runtime/spec9/step-retention.d.ts.map +1 -0
- package/dist/runtime/spec9/step-retention.js +51 -0
- package/dist/runtime/spec9/step-single-flight.d.ts +19 -0
- package/dist/runtime/spec9/step-single-flight.d.ts.map +1 -0
- package/dist/runtime/spec9/step-single-flight.js +24 -0
- package/dist/runtime/spec9/step-wait-creation.d.ts +162 -0
- package/dist/runtime/spec9/step-wait-creation.d.ts.map +1 -0
- package/dist/runtime/spec9/step-wait-creation.js +450 -0
- package/dist/runtime/spec9/suspension-handler.d.ts +125 -0
- package/dist/runtime/spec9/suspension-handler.d.ts.map +1 -0
- package/dist/runtime/spec9/suspension-handler.js +327 -0
- package/dist/runtime/spec9/wait-timer.d.ts +143 -0
- package/dist/runtime/spec9/wait-timer.d.ts.map +1 -0
- package/dist/runtime/spec9/wait-timer.js +173 -0
- package/dist/runtime/start-hook-binding.d.ts +50 -0
- package/dist/runtime/start-hook-binding.d.ts.map +1 -0
- package/dist/runtime/start-hook-binding.js +85 -0
- package/dist/runtime/start-hook-delivery.d.ts +47 -0
- package/dist/runtime/start-hook-delivery.d.ts.map +1 -0
- package/dist/runtime/start-hook-delivery.js +94 -0
- package/dist/runtime/start-hook-holder.d.ts +50 -0
- package/dist/runtime/start-hook-holder.d.ts.map +1 -0
- package/dist/runtime/start-hook-holder.js +149 -0
- package/dist/runtime/start.d.ts +76 -4
- package/dist/runtime/start.d.ts.map +1 -1
- package/dist/runtime/start.js +451 -62
- package/dist/runtime/step-latency.d.ts +3 -3
- package/dist/runtime/step-latency.js +1 -1
- package/dist/runtime/step-single-flight.d.ts +4 -8
- package/dist/runtime/step-single-flight.d.ts.map +1 -1
- package/dist/runtime/step-single-flight.js +23 -36
- package/dist/runtime/step-streams.d.ts +6 -0
- package/dist/runtime/step-streams.d.ts.map +1 -0
- package/dist/runtime/step-streams.js +40 -0
- package/dist/runtime/suspension-hooks.d.ts +84 -0
- package/dist/runtime/suspension-hooks.d.ts.map +1 -0
- package/dist/runtime/suspension-hooks.js +310 -0
- package/dist/runtime/wait-continuation.d.ts +27 -0
- package/dist/runtime/wait-continuation.d.ts.map +1 -1
- package/dist/runtime/wait-continuation.js +27 -2
- package/dist/runtime/world-compatibility.d.ts +22 -3
- package/dist/runtime/world-compatibility.d.ts.map +1 -1
- package/dist/runtime/world-compatibility.js +37 -2
- package/dist/runtime/world.d.ts.map +1 -1
- package/dist/runtime/world.js +2 -1
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +118 -4154
- package/dist/serialization/abort-stream.d.ts +11 -0
- package/dist/serialization/abort-stream.d.ts.map +1 -0
- package/dist/serialization/abort-stream.js +86 -0
- package/dist/serialization/reducers/common-vm.d.ts.map +1 -1
- package/dist/serialization/reducers/common-vm.js +39 -2
- package/dist/serialization/reducers/common.d.ts.map +1 -1
- package/dist/serialization/reducers/common.js +26 -3
- package/dist/serialization/types.d.ts +10 -1
- package/dist/serialization/types.d.ts.map +1 -1
- package/dist/serialization/types.js +1 -1
- package/dist/serialization.d.ts +21 -5
- package/dist/serialization.d.ts.map +1 -1
- package/dist/serialization.js +136 -79
- package/dist/set-attributes.d.ts.map +1 -1
- package/dist/set-attributes.js +9 -14
- package/dist/step/context-storage.d.ts +2 -0
- package/dist/step/context-storage.d.ts.map +1 -1
- package/dist/step/context-storage.js +1 -1
- package/dist/step.d.ts.map +1 -1
- package/dist/step.js +23 -16
- package/dist/telemetry/semantic-conventions.d.ts +218 -3
- package/dist/telemetry/semantic-conventions.d.ts.map +1 -1
- package/dist/telemetry/semantic-conventions.js +161 -2
- package/dist/test-support/append-only-world.d.ts +437 -0
- package/dist/test-support/append-only-world.d.ts.map +1 -0
- package/dist/test-support/append-only-world.js +816 -0
- package/dist/test-support/fence-snapshot.d.ts +11 -0
- package/dist/test-support/fence-snapshot.d.ts.map +1 -0
- package/dist/test-support/fence-snapshot.js +12 -0
- package/dist/test-support/load-events.d.ts +8 -0
- package/dist/test-support/load-events.d.ts.map +1 -0
- package/dist/test-support/load-events.js +27 -0
- package/dist/test-support/orchestrator-harness.d.ts +502 -0
- package/dist/test-support/orchestrator-harness.d.ts.map +1 -0
- package/dist/test-support/orchestrator-harness.js +116 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/dist/workflow/abort-controller.d.ts.map +1 -1
- package/dist/workflow/abort-controller.js +7 -5
- package/dist/workflow/hook.d.ts +5 -0
- package/dist/workflow/hook.d.ts.map +1 -1
- package/dist/workflow/hook.js +83 -19
- package/dist/workflow.d.ts +45 -16
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +111 -50
- package/docs/api-reference/create-hook.mdx +8 -0
- package/docs/api-reference/create-webhook.mdx +1 -1
- package/docs/api-reference/fetch.mdx +2 -0
- package/docs/foundations/errors-and-retries.mdx +6 -0
- package/docs/foundations/hooks.mdx +3 -1
- package/docs/foundations/idempotency.mdx +190 -60
- package/docs/foundations/starting-workflows.mdx +3 -7
- package/docs/how-it-works/event-sourcing.mdx +6 -0
- package/package.json +5 -5
- package/dist/runtime/count-step-started-events.d.ts.map +0 -1
- package/dist/runtime/count-step-started-events.js +0 -72
- package/dist/runtime/open-hook-wait-state.d.ts.map +0 -1
- package/dist/runtime/open-hook-wait-state.js +0 -93
- package/dist/runtime/quickjs-entrypoint.d.ts.map +0 -1
- package/dist/runtime/quickjs-entrypoint.js +0 -2314
- package/dist/runtime/step-executor.d.ts.map +0 -1
- package/dist/runtime/step-executor.js +0 -1156
- package/dist/runtime/step-ownership.d.ts.map +0 -1
- package/dist/runtime/step-ownership.js +0 -114
- package/dist/runtime/suspension-handler.d.ts.map +0 -1
- package/dist/runtime/suspension-handler.js +0 -1562
- /package/dist/runtime/{count-step-started-events.d.ts → spec8/count-step-started-events.d.ts} +0 -0
- /package/dist/runtime/{open-hook-wait-state.d.ts → spec8/open-hook-wait-state.d.ts} +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { WorkflowInvokePayload } from '@workflow/world';
|
|
2
|
+
type WaitContinuation = NonNullable<WorkflowInvokePayload['waitContinuation']>;
|
|
3
|
+
/**
|
|
4
|
+
* The deadline (epoch ms) of the timer hop a sender at `nowMs` sends for a
|
|
5
|
+
* wait due at `resumeAtMs`.
|
|
6
|
+
*
|
|
7
|
+
* A wait longer than one queue delay (`getWaitContinuationMaxDelaySeconds`)
|
|
8
|
+
* is reached in hops, and the hops are anchored on the wait's deadline: the
|
|
9
|
+
* last one is due at `resumeAtMs`, and each one before it one maximum delay
|
|
10
|
+
* earlier. A sender sends the earliest hop that is still ahead of it, so
|
|
11
|
+
* every sender within the same hop window computes the same deadline, and
|
|
12
|
+
* with it the same idempotency key ({@link waitTimerMessage}): the timers
|
|
13
|
+
* that the creating delivery, its redelivery, a delivery completing an
|
|
14
|
+
* earlier wait of the chain and a hop's own redelivery send for one hop are
|
|
15
|
+
* one message.
|
|
16
|
+
*
|
|
17
|
+
* `afterHopAtMs` is the deadline of the intermediate hop being delivered,
|
|
18
|
+
* when the sender is one: the next hop then comes after it whatever the
|
|
19
|
+
* sender's clock says, so a hop delivered a little early (the queue's clock
|
|
20
|
+
* ahead of the host's) does not compute its own deadline again, whose key it
|
|
21
|
+
* has spent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function waitTimerHopAtMs(params: {
|
|
24
|
+
resumeAtMs: number;
|
|
25
|
+
nowMs: number;
|
|
26
|
+
afterHopAtMs?: number;
|
|
27
|
+
}): number;
|
|
28
|
+
/**
|
|
29
|
+
* The timer message of a spec 9 wait, and its idempotency key.
|
|
30
|
+
*
|
|
31
|
+
* A wait longer than one queue delay is reached in hops
|
|
32
|
+
* ({@link waitTimerHopAtMs}). Every hop but the last is an intermediate hop:
|
|
33
|
+
* it carries the wait's deadline (`waitContinuation.resumeAtMs`), which
|
|
34
|
+
* tells the World not to serialize or coalesce it (`isIntermediateWaitHop`
|
|
35
|
+
* in `@workflow/world`), and its own (`waitContinuation.hopAtMs`), and its
|
|
36
|
+
* delivery only sends the next hop (see `continueWaitHop` in `delivery.ts`).
|
|
37
|
+
* The last hop, due with the wait, carries neither and is an ordinary
|
|
38
|
+
* orchestrator message: if the queue coalesces it into a running delivery
|
|
39
|
+
* of the run, that delivery's re-run finds the wait due and completes it.
|
|
40
|
+
*
|
|
41
|
+
* Every hop is keyed `wait:<correlationId>:<resumeAtMs>:<hopAtMs>`: the
|
|
42
|
+
* wait, its deadline (a correlation id can be given a new deadline by a
|
|
43
|
+
* replay after a creation that did not commit) and the hop's deadline. So
|
|
44
|
+
* the timers every sender sends for one hop of one wait are deduplicated
|
|
45
|
+
* by the queue instead of starting parallel hop chains.
|
|
46
|
+
*
|
|
47
|
+
* `attempt` counts the re-arms of a wait whose last timer was delivered
|
|
48
|
+
* before the wait was due (clock skew between the queue and the host): that
|
|
49
|
+
* delivery has spent the key of the hop due at `resumeAtMs`, so its re-arm
|
|
50
|
+
* carries `:a<attempt>` (one more than the delivered timer's), and so does
|
|
51
|
+
* every hop after it. A redelivery of the early timer computes the same
|
|
52
|
+
* re-arm key. The near-due safety net keys its re-arms by the sender's
|
|
53
|
+
* second instead ({@link nearDueTimerIdempotencyKey}).
|
|
54
|
+
*/
|
|
55
|
+
export declare function waitTimerMessage(params: {
|
|
56
|
+
correlationId: string;
|
|
57
|
+
resumeAtMs: number;
|
|
58
|
+
/** Seconds until the wait is due, as the caller rounds them: the last hop's delay. */
|
|
59
|
+
seconds: number;
|
|
60
|
+
nowMs: number;
|
|
61
|
+
attempt?: number;
|
|
62
|
+
/** The deadline of the intermediate hop being delivered, on its delivery. */
|
|
63
|
+
afterHopAtMs?: number;
|
|
64
|
+
}): {
|
|
65
|
+
waitContinuation: WaitContinuation;
|
|
66
|
+
delaySeconds: number;
|
|
67
|
+
hopAtMs: number;
|
|
68
|
+
idempotencyKey: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* The idempotency key of one hop of a wait's timer (see
|
|
72
|
+
* {@link waitTimerMessage}).
|
|
73
|
+
*/
|
|
74
|
+
export declare function waitTimerIdempotencyKey(params: {
|
|
75
|
+
correlationId: string;
|
|
76
|
+
resumeAtMs: number;
|
|
77
|
+
hopAtMs: number;
|
|
78
|
+
attempt?: number;
|
|
79
|
+
}): string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether a timer a delivery sends takes the near-due re-arm's key
|
|
82
|
+
* ({@link nearDueTimerIdempotencyKey}) instead of its hop's: a wait's last
|
|
83
|
+
* hop, sent by a delivery that may hold a timer the queue coalesced into it
|
|
84
|
+
* (any delivery but its message's first), other than a timer delivery's
|
|
85
|
+
* re-arm of its own wait (which carries the next attempt).
|
|
86
|
+
*
|
|
87
|
+
* The queue can coalesce a wait's last hop that came due before its wait
|
|
88
|
+
* (clock skew, or a World that clamps the delay below a hop) into a
|
|
89
|
+
* delivery that owns the wait's chain. That delivery finds the wait not yet
|
|
90
|
+
* due and arms it again, while the queue still holds the coalesced hop's key,
|
|
91
|
+
* which it never delivered: under that key the re-arm would be dropped and
|
|
92
|
+
* the wait left with no timer. Intermediate hops are never coalesced
|
|
93
|
+
* (`isIntermediateWaitHop` in `@workflow/world`), so they keep their key
|
|
94
|
+
* from every sender, and a long wait's hops never form parallel chains.
|
|
95
|
+
*/
|
|
96
|
+
export declare function rearmsCoalescableTimer(params: {
|
|
97
|
+
mayHoldCoalescedTimer: boolean;
|
|
98
|
+
intermediate: boolean;
|
|
99
|
+
attempt: number;
|
|
100
|
+
}): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* The idempotency key of a near-due re-arm: the timer a suspending delivery
|
|
103
|
+
* that may hold a coalesced timer sends for an open wait due within the
|
|
104
|
+
* near-due window, whatever chain the wait is in (`armNearDueTimers` in
|
|
105
|
+
* `delivery.ts`, and the QuickJS engine's exit sweep).
|
|
106
|
+
*
|
|
107
|
+
* Without a key every such delivery sent one timer for every near-due wait,
|
|
108
|
+
* and nothing deduplicated them: a fan-out whose waits came due one
|
|
109
|
+
* delivery at a time sent a timer per wait per delivery. The key collapses
|
|
110
|
+
* the re-arms of one wait, for one `resumeAt`, sent within the same second
|
|
111
|
+
* of the sender's clock, into one message on every World (world-vercel
|
|
112
|
+
* keeps a key for a day, world-local while its message lives, world-postgres
|
|
113
|
+
* while its job exists).
|
|
114
|
+
*
|
|
115
|
+
* It has the shape of a hop's key ({@link waitTimerIdempotencyKey}) with the
|
|
116
|
+
* sender's second, `s<second>`, in place of the hop's deadline. The second
|
|
117
|
+
* is in it so that a re-arm can itself be re-armed: a re-arm reaches the
|
|
118
|
+
* queue with a delay of at least a second, so the delivery it may be
|
|
119
|
+
* coalesced into early, a little before its wait is due, sends its own
|
|
120
|
+
* re-arm in a later second, under a fresh key. The hop's deadline would not
|
|
121
|
+
* do: a near-due re-arm stands in for the wait's last hop, which the queue
|
|
122
|
+
* coalesced into a delivery and never delivered, and whose key it still
|
|
123
|
+
* holds, so a re-arm under that key would be dropped.
|
|
124
|
+
*/
|
|
125
|
+
export declare function nearDueTimerIdempotencyKey(params: {
|
|
126
|
+
correlationId: string;
|
|
127
|
+
resumeAtMs: number;
|
|
128
|
+
nowMs: number;
|
|
129
|
+
}): string;
|
|
130
|
+
/** How many near-due re-arm keys {@link sendNearDueTimerOnce} remembers. */
|
|
131
|
+
export declare const SENT_NEAR_DUE_TIMER_KEYS_LIMIT = 10000;
|
|
132
|
+
/**
|
|
133
|
+
* Sends a near-due re-arm (`send`) unless this process already sent one
|
|
134
|
+
* under `key` ({@link nearDueTimerIdempotencyKey}), and says whether it
|
|
135
|
+
* sent. Every coalesced re-run of a busy run's delivery arms every near-due
|
|
136
|
+
* wait, and the queue would drop each repeat by its key anyway: this skips
|
|
137
|
+
* the send itself, which a suspending delivery otherwise makes once per
|
|
138
|
+
* near-due wait. A failed send is forgotten, so a later delivery retries it.
|
|
139
|
+
* Bounded to the {@link SENT_NEAR_DUE_TIMER_KEYS_LIMIT} newest keys.
|
|
140
|
+
*/
|
|
141
|
+
export declare function sendNearDueTimerOnce(key: string, send: () => Promise<void>): Promise<boolean>;
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=wait-timer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait-timer.d.ts","sourceRoot":"","sources":["../../../src/runtime/spec9/wait-timer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG7D,KAAK,gBAAgB,GAAG,WAAW,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,MAAM,CAYT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG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
1
|
+
import { globalSingleton } from '@workflow/utils';
|
|
2
|
+
import { getWaitContinuationMaxDelaySeconds } from '../wait-continuation.js';
|
|
3
|
+
/**
|
|
4
|
+
* The deadline (epoch ms) of the timer hop a sender at `nowMs` sends for a
|
|
5
|
+
* wait due at `resumeAtMs`.
|
|
6
|
+
*
|
|
7
|
+
* A wait longer than one queue delay (`getWaitContinuationMaxDelaySeconds`)
|
|
8
|
+
* is reached in hops, and the hops are anchored on the wait's deadline: the
|
|
9
|
+
* last one is due at `resumeAtMs`, and each one before it one maximum delay
|
|
10
|
+
* earlier. A sender sends the earliest hop that is still ahead of it, so
|
|
11
|
+
* every sender within the same hop window computes the same deadline, and
|
|
12
|
+
* with it the same idempotency key ({@link waitTimerMessage}): the timers
|
|
13
|
+
* that the creating delivery, its redelivery, a delivery completing an
|
|
14
|
+
* earlier wait of the chain and a hop's own redelivery send for one hop are
|
|
15
|
+
* one message.
|
|
16
|
+
*
|
|
17
|
+
* `afterHopAtMs` is the deadline of the intermediate hop being delivered,
|
|
18
|
+
* when the sender is one: the next hop then comes after it whatever the
|
|
19
|
+
* sender's clock says, so a hop delivered a little early (the queue's clock
|
|
20
|
+
* ahead of the host's) does not compute its own deadline again, whose key it
|
|
21
|
+
* has spent.
|
|
22
|
+
*/
|
|
23
|
+
export function waitTimerHopAtMs(params) {
|
|
24
|
+
const { resumeAtMs, nowMs, afterHopAtMs } = params;
|
|
25
|
+
const maxMs = getWaitContinuationMaxDelaySeconds() * 1000;
|
|
26
|
+
const remainingMs = resumeAtMs - nowMs;
|
|
27
|
+
let hopAtMs = remainingMs <= maxMs
|
|
28
|
+
? resumeAtMs
|
|
29
|
+
: resumeAtMs - (Math.ceil(remainingMs / maxMs) - 1) * maxMs;
|
|
30
|
+
if (afterHopAtMs !== undefined) {
|
|
31
|
+
hopAtMs = Math.max(hopAtMs, Math.min(resumeAtMs, afterHopAtMs + maxMs));
|
|
32
|
+
}
|
|
33
|
+
return hopAtMs;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The timer message of a spec 9 wait, and its idempotency key.
|
|
37
|
+
*
|
|
38
|
+
* A wait longer than one queue delay is reached in hops
|
|
39
|
+
* ({@link waitTimerHopAtMs}). Every hop but the last is an intermediate hop:
|
|
40
|
+
* it carries the wait's deadline (`waitContinuation.resumeAtMs`), which
|
|
41
|
+
* tells the World not to serialize or coalesce it (`isIntermediateWaitHop`
|
|
42
|
+
* in `@workflow/world`), and its own (`waitContinuation.hopAtMs`), and its
|
|
43
|
+
* delivery only sends the next hop (see `continueWaitHop` in `delivery.ts`).
|
|
44
|
+
* The last hop, due with the wait, carries neither and is an ordinary
|
|
45
|
+
* orchestrator message: if the queue coalesces it into a running delivery
|
|
46
|
+
* of the run, that delivery's re-run finds the wait due and completes it.
|
|
47
|
+
*
|
|
48
|
+
* Every hop is keyed `wait:<correlationId>:<resumeAtMs>:<hopAtMs>`: the
|
|
49
|
+
* wait, its deadline (a correlation id can be given a new deadline by a
|
|
50
|
+
* replay after a creation that did not commit) and the hop's deadline. So
|
|
51
|
+
* the timers every sender sends for one hop of one wait are deduplicated
|
|
52
|
+
* by the queue instead of starting parallel hop chains.
|
|
53
|
+
*
|
|
54
|
+
* `attempt` counts the re-arms of a wait whose last timer was delivered
|
|
55
|
+
* before the wait was due (clock skew between the queue and the host): that
|
|
56
|
+
* delivery has spent the key of the hop due at `resumeAtMs`, so its re-arm
|
|
57
|
+
* carries `:a<attempt>` (one more than the delivered timer's), and so does
|
|
58
|
+
* every hop after it. A redelivery of the early timer computes the same
|
|
59
|
+
* re-arm key. The near-due safety net keys its re-arms by the sender's
|
|
60
|
+
* second instead ({@link nearDueTimerIdempotencyKey}).
|
|
61
|
+
*/
|
|
62
|
+
export function waitTimerMessage(params) {
|
|
63
|
+
const { correlationId, resumeAtMs, seconds, nowMs, attempt = 0, afterHopAtMs, } = params;
|
|
64
|
+
const maxSeconds = getWaitContinuationMaxDelaySeconds();
|
|
65
|
+
const hopAtMs = waitTimerHopAtMs({ resumeAtMs, nowMs, afterHopAtMs });
|
|
66
|
+
const intermediate = hopAtMs < resumeAtMs;
|
|
67
|
+
const delaySeconds = Math.min(maxSeconds, intermediate ? Math.max(1, Math.ceil((hopAtMs - nowMs) / 1000)) : seconds);
|
|
68
|
+
return {
|
|
69
|
+
delaySeconds,
|
|
70
|
+
hopAtMs,
|
|
71
|
+
idempotencyKey: waitTimerIdempotencyKey({
|
|
72
|
+
correlationId,
|
|
73
|
+
resumeAtMs,
|
|
74
|
+
hopAtMs,
|
|
75
|
+
attempt,
|
|
76
|
+
}),
|
|
77
|
+
waitContinuation: {
|
|
78
|
+
correlationId,
|
|
79
|
+
attempt,
|
|
80
|
+
...(intermediate ? { resumeAtMs, hopAtMs } : {}),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The idempotency key of one hop of a wait's timer (see
|
|
86
|
+
* {@link waitTimerMessage}).
|
|
87
|
+
*/
|
|
88
|
+
export function waitTimerIdempotencyKey(params) {
|
|
89
|
+
const { correlationId, resumeAtMs, hopAtMs, attempt = 0 } = params;
|
|
90
|
+
return `wait:${correlationId}:${resumeAtMs}:${hopAtMs}${attempt > 0 ? `:a${attempt}` : ''}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Whether a timer a delivery sends takes the near-due re-arm's key
|
|
94
|
+
* ({@link nearDueTimerIdempotencyKey}) instead of its hop's: a wait's last
|
|
95
|
+
* hop, sent by a delivery that may hold a timer the queue coalesced into it
|
|
96
|
+
* (any delivery but its message's first), other than a timer delivery's
|
|
97
|
+
* re-arm of its own wait (which carries the next attempt).
|
|
98
|
+
*
|
|
99
|
+
* The queue can coalesce a wait's last hop that came due before its wait
|
|
100
|
+
* (clock skew, or a World that clamps the delay below a hop) into a
|
|
101
|
+
* delivery that owns the wait's chain. That delivery finds the wait not yet
|
|
102
|
+
* due and arms it again, while the queue still holds the coalesced hop's key,
|
|
103
|
+
* which it never delivered: under that key the re-arm would be dropped and
|
|
104
|
+
* the wait left with no timer. Intermediate hops are never coalesced
|
|
105
|
+
* (`isIntermediateWaitHop` in `@workflow/world`), so they keep their key
|
|
106
|
+
* from every sender, and a long wait's hops never form parallel chains.
|
|
107
|
+
*/
|
|
108
|
+
export function rearmsCoalescableTimer(params) {
|
|
109
|
+
return (params.mayHoldCoalescedTimer && !params.intermediate && params.attempt === 0);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The idempotency key of a near-due re-arm: the timer a suspending delivery
|
|
113
|
+
* that may hold a coalesced timer sends for an open wait due within the
|
|
114
|
+
* near-due window, whatever chain the wait is in (`armNearDueTimers` in
|
|
115
|
+
* `delivery.ts`, and the QuickJS engine's exit sweep).
|
|
116
|
+
*
|
|
117
|
+
* Without a key every such delivery sent one timer for every near-due wait,
|
|
118
|
+
* and nothing deduplicated them: a fan-out whose waits came due one
|
|
119
|
+
* delivery at a time sent a timer per wait per delivery. The key collapses
|
|
120
|
+
* the re-arms of one wait, for one `resumeAt`, sent within the same second
|
|
121
|
+
* of the sender's clock, into one message on every World (world-vercel
|
|
122
|
+
* keeps a key for a day, world-local while its message lives, world-postgres
|
|
123
|
+
* while its job exists).
|
|
124
|
+
*
|
|
125
|
+
* It has the shape of a hop's key ({@link waitTimerIdempotencyKey}) with the
|
|
126
|
+
* sender's second, `s<second>`, in place of the hop's deadline. The second
|
|
127
|
+
* is in it so that a re-arm can itself be re-armed: a re-arm reaches the
|
|
128
|
+
* queue with a delay of at least a second, so the delivery it may be
|
|
129
|
+
* coalesced into early, a little before its wait is due, sends its own
|
|
130
|
+
* re-arm in a later second, under a fresh key. The hop's deadline would not
|
|
131
|
+
* do: a near-due re-arm stands in for the wait's last hop, which the queue
|
|
132
|
+
* coalesced into a delivery and never delivered, and whose key it still
|
|
133
|
+
* holds, so a re-arm under that key would be dropped.
|
|
134
|
+
*/
|
|
135
|
+
export function nearDueTimerIdempotencyKey(params) {
|
|
136
|
+
const { correlationId, resumeAtMs, nowMs } = params;
|
|
137
|
+
return `wait:${correlationId}:${resumeAtMs}:s${Math.floor(nowMs / 1000)}`;
|
|
138
|
+
}
|
|
139
|
+
/** How many near-due re-arm keys {@link sendNearDueTimerOnce} remembers. */
|
|
140
|
+
export const SENT_NEAR_DUE_TIMER_KEYS_LIMIT = 10_000;
|
|
141
|
+
// On `globalThis` (see `globalSingleton`): every bundled copy of this module
|
|
142
|
+
// in the process shares the keys it sent.
|
|
143
|
+
const sentNearDueTimerKeys = globalSingleton('@workflow/core//sentNearDueTimerKeys', 1, () => ({ keys: new Set() }));
|
|
144
|
+
/**
|
|
145
|
+
* Sends a near-due re-arm (`send`) unless this process already sent one
|
|
146
|
+
* under `key` ({@link nearDueTimerIdempotencyKey}), and says whether it
|
|
147
|
+
* sent. Every coalesced re-run of a busy run's delivery arms every near-due
|
|
148
|
+
* wait, and the queue would drop each repeat by its key anyway: this skips
|
|
149
|
+
* the send itself, which a suspending delivery otherwise makes once per
|
|
150
|
+
* near-due wait. A failed send is forgotten, so a later delivery retries it.
|
|
151
|
+
* Bounded to the {@link SENT_NEAR_DUE_TIMER_KEYS_LIMIT} newest keys.
|
|
152
|
+
*/
|
|
153
|
+
export async function sendNearDueTimerOnce(key, send) {
|
|
154
|
+
const { keys } = sentNearDueTimerKeys;
|
|
155
|
+
if (keys.has(key))
|
|
156
|
+
return false;
|
|
157
|
+
keys.add(key);
|
|
158
|
+
try {
|
|
159
|
+
await send();
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
keys.delete(key);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
while (keys.size > SENT_NEAR_DUE_TIMER_KEYS_LIMIT) {
|
|
166
|
+
const oldest = keys.values().next().value;
|
|
167
|
+
if (oldest === undefined)
|
|
168
|
+
break;
|
|
169
|
+
keys.delete(oldest);
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2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zIGZvcmdvdHRlbiwgc28gYSBsYXRlciBkZWxpdmVyeSByZXRyaWVzIGl0LlxuICogQm91bmRlZCB0byB0aGUge0BsaW5rIFNFTlRfTkVBUl9EVUVfVElNRVJfS0VZU19MSU1JVH0gbmV3ZXN0IGtleXMuXG4gKi9cbmV4cG9ydCBhc3luYyBmdW5jdGlvbiBzZW5kTmVhckR1ZVRpbWVyT25jZShcbiAga2V5OiBzdHJpbmcsXG4gIHNlbmQ6ICgpID0+IFByb21pc2U8dm9pZD5cbik6IFByb21pc2U8Ym9vbGVhbj4ge1xuICBjb25zdCB7IGtleXMgfSA9IHNlbnROZWFyRHVlVGltZXJLZXlzO1xuICBpZiAoa2V5cy5oYXMoa2V5KSkgcmV0dXJuIGZhbHNlO1xuICBrZXlzLmFkZChrZXkpO1xuICB0cnkge1xuICAgIGF3YWl0IHNlbmQoKTtcbiAgfSBjYXRjaCAoZXJyb3IpIHtcbiAgICBrZXlzLmRlbGV0ZShrZXkpO1xuICAgIHRocm93IGVycm9yO1xuICB9XG4gIHdoaWxlIChrZXlzLnNpemUgPiBTRU5UX05FQVJfRFVFX1RJTUVSX0tFWVNfTElNSVQpIHtcbiAgICBjb25zdCBvbGRlc3QgPSBrZXlzLnZhbHVlcygpLm5leHQoKS52YWx1ZTtcbiAgICBpZiAob2xkZXN0ID09PSB1bmRlZmluZWQpIGJyZWFrO1xuICAgIGtleXMuZGVsZXRlKG9sZGVzdCk7XG4gIH1cbiAgcmV0dXJuIHRydWU7XG59XG4iXX0=
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type Event, type RunInput, type WorkflowRun } from '@workflow/world';
|
|
2
|
+
/**
|
|
3
|
+
* The start Hook of a run created with `start(workflow, args, { experimental_hook })`.
|
|
4
|
+
*
|
|
5
|
+
* The admission that creates the run also creates this Hook, under an id
|
|
6
|
+
* derived from the run's id, so it exists (and can be resumed) before the
|
|
7
|
+
* workflow body runs, and no `hook_created` is ever written for it. The
|
|
8
|
+
* workflow's `createHook({ token })` with this token binds to `hookId`
|
|
9
|
+
* instead of minting a new one.
|
|
10
|
+
*/
|
|
11
|
+
export interface RunStartHook {
|
|
12
|
+
readonly token: string;
|
|
13
|
+
readonly hookId: string;
|
|
14
|
+
/**
|
|
15
|
+
* `start({ experimental_hook: { experimental_minRetention } })`'s deadline, when set.
|
|
16
|
+
* Only decides whether a disposal still has to be written when the run
|
|
17
|
+
* ends (a retained token is not released by the run's end), exactly as a
|
|
18
|
+
* `hook_created`'s `tokenRetentionUntil` does for an ordinary Hook.
|
|
19
|
+
*/
|
|
20
|
+
readonly tokenRetentionUntil?: Date;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The run's start Hook, or `undefined` for a run started without one.
|
|
24
|
+
*
|
|
25
|
+
* Read, in order, from the log's `run_created.eventData.startHook` (the first
|
|
26
|
+
* event of the log, immutable), the queue message's `runInput.startHook` (the
|
|
27
|
+
* log may not hold `run_created` yet), and `workflowRun.startHook`. Every
|
|
28
|
+
* replay must bind the same token, so sources that are present must agree;
|
|
29
|
+
* one that disagrees is a World bug and throws rather than binding a
|
|
30
|
+
* different id on some replays.
|
|
31
|
+
*
|
|
32
|
+
* Pure and synchronous: no I/O, and for a run without a start Hook it reads
|
|
33
|
+
* three fields and returns.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveRunStartHook({ events, workflowRun, runInput, }: {
|
|
36
|
+
events: readonly Event[] | undefined;
|
|
37
|
+
workflowRun: Pick<WorkflowRun, 'runId'> & {
|
|
38
|
+
startHook?: unknown;
|
|
39
|
+
};
|
|
40
|
+
runInput?: Pick<RunInput, 'startHook'> | undefined;
|
|
41
|
+
}): RunStartHook | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Mint a hook correlation id, redrawing on the one id this run must never
|
|
44
|
+
* mint: its start Hook's. The draw is a pure function of the run's ULID
|
|
45
|
+
* sequence, so the redraw (if any) is the same on every replay. Run ids
|
|
46
|
+
* tagged by their World never collide with a minted id at all, so the loop
|
|
47
|
+
* almost never runs twice.
|
|
48
|
+
*/
|
|
49
|
+
export declare function mintHookCorrelationId(generateUlid: () => string, startHook: Pick<RunStartHook, 'hookId'> | undefined): string;
|
|
50
|
+
//# sourceMappingURL=start-hook-binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-hook-binding.d.ts","sourceRoot":"","sources":["../../src/runtime/start-hook-binding.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EACV,KAAK,QAAQ,EAEb,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC;CACrC;AAyBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,MAAM,EACN,WAAW,EACX,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,CAAC;IACrC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAClE,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC;CACpD,GAAG,YAAY,GAAG,SAAS,CAyC3B;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,MAAM,EAC1B,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,SAAS,GAClD,MAAM,CAMR"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { WorkflowRuntimeError } from '@workflow/errors';
|
|
2
|
+
import { startHookId, } from '@workflow/world';
|
|
3
|
+
function sourceOf(value) {
|
|
4
|
+
if (value === null || typeof value !== 'object')
|
|
5
|
+
return undefined;
|
|
6
|
+
const { token, tokenRetentionUntil } = value;
|
|
7
|
+
if (typeof token !== 'string' || token.length === 0)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (tokenRetentionUntil instanceof Date ||
|
|
10
|
+
typeof tokenRetentionUntil === 'string' ||
|
|
11
|
+
typeof tokenRetentionUntil === 'number') {
|
|
12
|
+
const at = new Date(tokenRetentionUntil);
|
|
13
|
+
if (!Number.isNaN(+at))
|
|
14
|
+
return { token, tokenRetentionUntil: at };
|
|
15
|
+
}
|
|
16
|
+
return { token };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The run's start Hook, or `undefined` for a run started without one.
|
|
20
|
+
*
|
|
21
|
+
* Read, in order, from the log's `run_created.eventData.startHook` (the first
|
|
22
|
+
* event of the log, immutable), the queue message's `runInput.startHook` (the
|
|
23
|
+
* log may not hold `run_created` yet), and `workflowRun.startHook`. Every
|
|
24
|
+
* replay must bind the same token, so sources that are present must agree;
|
|
25
|
+
* one that disagrees is a World bug and throws rather than binding a
|
|
26
|
+
* different id on some replays.
|
|
27
|
+
*
|
|
28
|
+
* Pure and synchronous: no I/O, and for a run without a start Hook it reads
|
|
29
|
+
* three fields and returns.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveRunStartHook({ events, workflowRun, runInput, }) {
|
|
32
|
+
const runCreated = events?.find((e) => e.eventType === 'run_created');
|
|
33
|
+
const sources = [
|
|
34
|
+
[
|
|
35
|
+
'run_created',
|
|
36
|
+
sourceOf(runCreated && 'eventData' in runCreated
|
|
37
|
+
? runCreated.eventData
|
|
38
|
+
?.startHook
|
|
39
|
+
: undefined),
|
|
40
|
+
],
|
|
41
|
+
['runInput', sourceOf(runInput?.startHook)],
|
|
42
|
+
['run', sourceOf(workflowRun.startHook)],
|
|
43
|
+
];
|
|
44
|
+
let found;
|
|
45
|
+
let from;
|
|
46
|
+
for (const [source, candidate] of sources) {
|
|
47
|
+
if (candidate === undefined)
|
|
48
|
+
continue;
|
|
49
|
+
if (found === undefined) {
|
|
50
|
+
found = candidate;
|
|
51
|
+
from = source;
|
|
52
|
+
}
|
|
53
|
+
else if (candidate.token !== found.token) {
|
|
54
|
+
throw new WorkflowRuntimeError(`Workflow run "${workflowRun.runId}" has conflicting start Hook tokens: ${from} and ${source} carry different ones.`);
|
|
55
|
+
}
|
|
56
|
+
else if (found.tokenRetentionUntil === undefined &&
|
|
57
|
+
candidate.tokenRetentionUntil !== undefined) {
|
|
58
|
+
found = { ...found, tokenRetentionUntil: candidate.tokenRetentionUntil };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (found === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
return {
|
|
64
|
+
token: found.token,
|
|
65
|
+
hookId: startHookId(workflowRun.runId),
|
|
66
|
+
...(found.tokenRetentionUntil !== undefined
|
|
67
|
+
? { tokenRetentionUntil: found.tokenRetentionUntil }
|
|
68
|
+
: {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Mint a hook correlation id, redrawing on the one id this run must never
|
|
73
|
+
* mint: its start Hook's. The draw is a pure function of the run's ULID
|
|
74
|
+
* sequence, so the redraw (if any) is the same on every replay. Run ids
|
|
75
|
+
* tagged by their World never collide with a minted id at all, so the loop
|
|
76
|
+
* almost never runs twice.
|
|
77
|
+
*/
|
|
78
|
+
export function mintHookCorrelationId(generateUlid, startHook) {
|
|
79
|
+
let id = `hook_${generateUlid()}`;
|
|
80
|
+
while (startHook !== undefined && id === startHook.hookId) {
|
|
81
|
+
id = `hook_${generateUlid()}`;
|
|
82
|
+
}
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhcnQtaG9vay1iaW5kaW5nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3J1bn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ydCBIb29rJ3MuIFRoZSBkcmF3IGlzIGEgcHVyZSBmdW5jdGlvbiBvZiB0aGUgcnVuJ3MgVUxJRFxuICogc2VxdWVuY2UsIHNvIHRoZSByZWRyYXcgKGlmIGFueSkgaXMgdGhlIHNhbWUgb24gZXZlcnkgcmVwbGF5LiBSdW4gaWRzXG4gKiB0YWdnZWQgYnkgdGhlaXIgV29ybGQgbmV2ZXIgY29sbGlkZSB3aXRoIGEgbWludGVkIGlkIGF0IGFsbCwgc28gdGhlIGxvb3BcbiAqIGFsbW9zdCBuZXZlciBydW5zIHR3aWNlLlxuICovXG5leHBvcnQgZnVuY3Rpb24gbWludEhvb2tDb3JyZWxhdGlvbklkKFxuICBnZW5lcmF0ZVVsaWQ6ICgpID0+IHN0cmluZyxcbiAgc3RhcnRIb29rOiBQaWNrPFJ1blN0YXJ0SG9vaywgJ2hvb2tJZCc+IHwgdW5kZWZpbmVkXG4pOiBzdHJpbmcge1xuICBsZXQgaWQgPSBgaG9va18ke2dlbmVyYXRlVWxpZCgpfWA7XG4gIHdoaWxlIChzdGFydEhvb2sgIT09IHVuZGVmaW5lZCAmJiBpZCA9PT0gc3RhcnRIb29rLmhvb2tJZCkge1xuICAgIGlkID0gYGhvb2tfJHtnZW5lcmF0ZVVsaWQoKX1gO1xuICB9XG4gIHJldHVybiBpZDtcbn1cbiJdfQ==
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
|
+
import type { RunInput, WorkflowRun } from '@workflow/world';
|
|
3
|
+
/**
|
|
4
|
+
* Whether a delivery may take the turbo fast path for this `runInput`. The
|
|
5
|
+
* queued copy of a `start({ experimental_hook })` candidate may be refused by the
|
|
6
|
+
* `run_started` it writes, so nothing of its may run before that write
|
|
7
|
+
* returns: turbo, which backgrounds `run_started` and starts inline step
|
|
8
|
+
* bodies first, is off for it on every engine.
|
|
9
|
+
*/
|
|
10
|
+
export declare function admitsTurboStart(runInput: RunInput | undefined): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The queued copy of a `start({ experimental_hook })` candidate the World refused: another
|
|
13
|
+
* run owns the token (`HookConflictError`), or the World will never admit the
|
|
14
|
+
* request (`START_HOOK_ADMISSION_REJECTED`). Nothing of the candidate ran and
|
|
15
|
+
* it never becomes a run, so the delivery acknowledges. Returns whether it
|
|
16
|
+
* did; every other error, including the rest of `WorkflowWorldError`, is left
|
|
17
|
+
* to the caller's ordinary handling. A refusal is recorded on the invocation
|
|
18
|
+
* span, which otherwise ends OK and says nothing about it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ackRefusedStartHookCandidate(err: unknown, runInput: RunInput | undefined, runId: string, span?: Span): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The queued copy of a `start({ experimental_hook })` candidate whose `run_started` the
|
|
23
|
+
* World accepted, on the invocation span: the candidate owns the token,
|
|
24
|
+
* whether this write admitted it or replayed the admission its `run_created`
|
|
25
|
+
* won.
|
|
26
|
+
*
|
|
27
|
+
* Acceptance means the run the World returned echoes the requested token in
|
|
28
|
+
* `run.startHook`, not merely that the write succeeded: a World that ignores
|
|
29
|
+
* `startHook` (a backend that predates it) creates an ordinary run, and
|
|
30
|
+
* running that run's code would make the start non-idempotent. That answer
|
|
31
|
+
* throws a World contract error before any workflow code runs, which fails
|
|
32
|
+
* the run.
|
|
33
|
+
*/
|
|
34
|
+
export declare function recordAcceptedStartHookCandidate(runInput: RunInput | undefined, run: Pick<WorkflowRun, 'runId'> & {
|
|
35
|
+
startHook?: {
|
|
36
|
+
token?: string;
|
|
37
|
+
};
|
|
38
|
+
}, span?: Span,
|
|
39
|
+
/**
|
|
40
|
+
* `run_load` when the run was read rather than returned by this delivery's
|
|
41
|
+
* own `run_started` (a redelivery after that write committed), so the span
|
|
42
|
+
* does not count it as another admission.
|
|
43
|
+
*/
|
|
44
|
+
trigger?: StartHookTrigger): void;
|
|
45
|
+
type StartHookTrigger = 'run_started' | 'run_load';
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=start-hook-delivery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start-hook-delivery.d.ts","sourceRoot":"","sources":["../../src/runtime/start-hook-delivery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAO/C,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI7D;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,CAExE;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,IAAI,GACV,OAAO,CAuCT;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gCAAgC,CAC9C,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpE,IAAI,CAAC,EAAE,IAAI;AACX;;;;GAIG;AACH,OAAO,GAAE,gBAAgC,GACxC,IAAI,CAeN;AAED,KAAK,gBAAgB,GAAG,aAAa,GAAG,UAAU,CAAC"}
|