@voltro/workflow 0.81.0 → 0.82.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/CHANGELOG.md +1520 -6
- package/README.md +4 -0
- package/dist/cluster-MboOAwcv.js +604 -0
- package/dist/cluster.d.ts +553 -26
- package/dist/cluster.js +2 -2
- package/dist/clusterDiagnostics-Dc7yBP3b.js +2069 -0
- package/dist/clusterTestSuite.d.ts +2 -0
- package/dist/clusterTestSuite.js +309 -117
- package/dist/index.d.ts +257 -115
- package/dist/index.js +5 -4
- package/dist/journalEncryption--n5VDdYO.js +148 -0
- package/dist/primitives-Btjhjm8P.js +483 -0
- package/dist/primitives.d.ts +28 -72
- package/dist/primitives.js +1 -1
- package/dist/{src-D_GRCNhv.js → src-BAN5Xovf.js} +1015 -2129
- package/package.json +4 -4
- package/dist/cluster-D7VuRhM0.js +0 -500
- package/dist/clusterDiagnostics-Cwt-WFec.js +0 -395
- package/dist/primitives-BJBn8tiH.js +0 -448
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
import { Activity as e, Activity as t, DurableClock as n, DurableClock as r, DurableQueue as i, DurableQueue as a, DurableRateLimiter as o, DurableRateLimiter as s, Workflow as c, Workflow as l, WorkflowEngine as u } from "@effect/workflow";
|
|
2
|
-
import { Cause as d, Context as f, Cron as p, Duration as m, Effect as h, Either as g, Exit as ee, FiberRef as _, Option as v, Schedule as y, Schema as te } from "effect";
|
|
3
|
-
import { attachWorkflowAccess as ne, resolveWorkflowAccess as b } from "@voltro/protocol";
|
|
4
|
-
//#region src/preparedExecution.ts
|
|
5
|
-
var x = Symbol.for("@voltro/workflow/PreparedExecution"), S = (e, t) => {
|
|
6
|
-
Object.defineProperty(e, x, {
|
|
7
|
-
value: t,
|
|
8
|
-
enumerable: !0
|
|
9
|
-
});
|
|
10
|
-
}, re = (e) => typeof e == "object" && !!e && typeof e[x] == "function", ie = (e, t, n, r) => h.suspend(() => {
|
|
11
|
-
if (n.length === 0) return h.die(/* @__PURE__ */ Error("Prepared workflow execution requires a non-empty identity"));
|
|
12
|
-
let i = e[x];
|
|
13
|
-
return typeof i == "function" ? i(t, n, r?.discard ?? !0) : h.die(/* @__PURE__ */ Error("Workflow definition has no prepared-execution capability"));
|
|
14
|
-
}), C = (e) => e !== void 0 && (e.debounce !== void 0 || e.singleton !== void 0 || e.concurrency !== void 0 || e.throttle !== void 0 || e.rateLimit !== void 0 || e.batch !== void 0 || e.timeouts?.startMs !== void 0 || e.timeouts?.finishMs !== void 0), w = (e) => e?.cancelOn !== void 0 && e.cancelOn.length > 0, ae = [
|
|
15
|
-
"debounce",
|
|
16
|
-
"batch",
|
|
17
|
-
"throttle",
|
|
18
|
-
"concurrency"
|
|
19
|
-
], T = (e) => {
|
|
20
|
-
if (e === void 0) return [];
|
|
21
|
-
let t = [];
|
|
22
|
-
return e.debounce !== void 0 && t.push("debounce"), e.batch !== void 0 && t.push("batch"), e.throttle !== void 0 && t.push("throttle"), e.concurrency !== void 0 && t.push("concurrency"), t;
|
|
23
|
-
}, E = (e, t, n) => {
|
|
24
|
-
let r;
|
|
25
|
-
try {
|
|
26
|
-
r = m.toMillis(m.decode(e));
|
|
27
|
-
} catch {
|
|
28
|
-
throw Error(`workflow '${n}': ${t} is not a duration Effect can read (got ${JSON.stringify(e)}). Use a spelled-out unit ('15 minutes', '1 hour', '30 seconds'), a number of milliseconds, or a Duration — the abbreviated forms ('15m', '1h') are NOT accepted.`);
|
|
29
|
-
}
|
|
30
|
-
if (!Number.isFinite(r) || r <= 0) throw Error(`workflow '${n}': ${t} must be a positive finite duration, got ${String(e)}`);
|
|
31
|
-
return r;
|
|
32
|
-
}, D = (e, t, n) => {
|
|
33
|
-
if (!Number.isInteger(e) || e <= 0) throw Error(`workflow '${n}': ${t} must be a positive integer, got ${String(e)}`);
|
|
34
|
-
return e;
|
|
35
|
-
}, O = (e, t, n) => {
|
|
36
|
-
if (typeof e != "function") throw Error(`workflow '${n}': ${t} must be a function of the payload`);
|
|
37
|
-
return e;
|
|
38
|
-
}, k = (e) => {
|
|
39
|
-
let t = e?.ast?.propertySignatures;
|
|
40
|
-
if (!Array.isArray(t)) return !1;
|
|
41
|
-
let n = t.find((e) => e.name === "items");
|
|
42
|
-
return n !== void 0 && n.type?._tag === "TupleType";
|
|
43
|
-
}, A = (e) => {
|
|
44
|
-
let { workflowName: t, control: n } = e;
|
|
45
|
-
if (n === void 0) return;
|
|
46
|
-
let r = { workflowName: t };
|
|
47
|
-
if (n.debounce !== void 0) {
|
|
48
|
-
let e = n.debounce, i = E(e.period, "debounce.period", t), a = e.timeout === void 0 ? void 0 : E(e.timeout, "debounce.timeout", t);
|
|
49
|
-
if (a !== void 0 && a < i) throw Error(`workflow '${t}': debounce.timeout (${a}ms) is shorter than debounce.period (${i}ms), so the burst can never be collapsed — the run would be admitted before the quiet period could ever elapse. Raise the timeout or lower the period.`);
|
|
50
|
-
r.debounce = {
|
|
51
|
-
key: O(e.key, "debounce.key", t),
|
|
52
|
-
periodMs: i,
|
|
53
|
-
...a === void 0 ? {} : { timeoutMs: a }
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (n.singleton !== void 0) {
|
|
57
|
-
let e = n.singleton;
|
|
58
|
-
if (e.mode !== "skip" && e.mode !== "cancel") throw Error(`workflow '${t}': singleton.mode must be 'skip' or 'cancel'. There is no default — 'skip' discards the incoming request and 'cancel' discards the running one, and choosing for you would silently throw away work either way.`);
|
|
59
|
-
r.singleton = {
|
|
60
|
-
key: O(e.key, "singleton.key", t),
|
|
61
|
-
mode: e.mode
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (n.concurrency !== void 0) {
|
|
65
|
-
let e = n.concurrency;
|
|
66
|
-
if (e.pool !== void 0 && (typeof e.pool != "string" || e.pool.trim() === "")) throw Error(`workflow '${t}': concurrency.pool must be a non-empty name — it is the identity other workflows declare to share this budget, and an empty one would silently merge every empty-named pool in the deployment into one.`);
|
|
67
|
-
r.concurrency = {
|
|
68
|
-
limit: D(e.limit, "concurrency.limit", t),
|
|
69
|
-
...e.key === void 0 ? {} : { key: O(e.key, "concurrency.key", t) },
|
|
70
|
-
...e.pool === void 0 ? {} : { pool: e.pool.trim() }
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (n.throttle !== void 0) {
|
|
74
|
-
let e = n.throttle;
|
|
75
|
-
r.throttle = {
|
|
76
|
-
limit: D(e.limit, "throttle.limit", t),
|
|
77
|
-
periodMs: E(e.period, "throttle.period", t),
|
|
78
|
-
...e.key === void 0 ? {} : { key: O(e.key, "throttle.key", t) }
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (n.rateLimit !== void 0) {
|
|
82
|
-
let e = n.rateLimit;
|
|
83
|
-
r.rateLimit = {
|
|
84
|
-
limit: D(e.limit, "rateLimit.limit", t),
|
|
85
|
-
periodMs: E(e.period, "rateLimit.period", t),
|
|
86
|
-
...e.key === void 0 ? {} : { key: O(e.key, "rateLimit.key", t) }
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (n.batch !== void 0) {
|
|
90
|
-
let i = n.batch;
|
|
91
|
-
if (e.payloadSchema !== void 0 && !k(e.payloadSchema)) throw Error(`workflow '${t}': batch is declared, so the workflow's own \`payload\` must be the BATCH shape — \`Schema.Struct({ items: Schema.Array(Item) })\` — while callers start it with a SINGLE item. Declare the item's schema as \`batch.item\`. Checked here rather than at admission because a decode failure on the batching replica is a failure nobody is watching.`);
|
|
92
|
-
r.batch = {
|
|
93
|
-
...i.key === void 0 ? {} : { key: O(i.key, "batch.key", t) },
|
|
94
|
-
maxSize: D(i.maxSize, "batch.maxSize", t),
|
|
95
|
-
timeoutMs: E(i.timeout, "batch.timeout", t),
|
|
96
|
-
...i.item === void 0 ? {} : { item: i.item }
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (n.priority !== void 0) {
|
|
100
|
-
if (typeof n.priority != "function") throw Error(`workflow '${t}': priority must be a function of the payload`);
|
|
101
|
-
r.priority = n.priority;
|
|
102
|
-
}
|
|
103
|
-
if (n.timeouts !== void 0) {
|
|
104
|
-
let e = n.timeouts, i = e.start === void 0 ? void 0 : E(e.start, "timeouts.start", t), a = e.finish === void 0 ? void 0 : E(e.finish, "timeouts.finish", t);
|
|
105
|
-
(i !== void 0 || a !== void 0) && (r.timeouts = {
|
|
106
|
-
...i === void 0 ? {} : { startMs: i },
|
|
107
|
-
...a === void 0 ? {} : { finishMs: a }
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
if (r.debounce !== void 0 && r.batch !== void 0) throw Error(`workflow '${t}': debounce and batch cannot both be declared. Both collect starts and admit one run, but debounce's timer RESETS on every arrival (collapse a burst, latest payload wins) while batch's does not (accumulate items until maxSize or timeout). Pick the one you mean.`);
|
|
111
|
-
if (r.throttle !== void 0 && r.rateLimit !== void 0) throw Error(`workflow '${t}': throttle and rateLimit cannot both be declared. throttle QUEUES the excess and rateLimit DROPS it; declaring both means the drop fires first and the queue is never reached. Pick whether surplus work is late or gone.`);
|
|
112
|
-
if (n.onFailure !== void 0) {
|
|
113
|
-
if (typeof n.onFailure != "string" || n.onFailure.length === 0) throw Error(`workflow '${t}': onFailure must be the NAME of another workflow. A function cannot be used — the failure may be noticed by a different replica, minutes later, after the process that held the closure is gone.`);
|
|
114
|
-
if (n.onFailure === t) throw Error(`workflow '${t}': onFailure points at itself. A workflow that fails would then start another copy of itself, which would fail, forever — one run per failure until something else breaks. Point it at a separate notifier workflow.`);
|
|
115
|
-
r.onFailure = n.onFailure;
|
|
116
|
-
}
|
|
117
|
-
if (n.encryptSteps === !0 && (r.encryptSteps = !0), n.cancelOn !== void 0) {
|
|
118
|
-
if (!Array.isArray(n.cancelOn)) throw Error(`workflow '${t}': cancelOn must be an array of { event, schema, match }`);
|
|
119
|
-
let e = n.cancelOn.map((e, n) => {
|
|
120
|
-
let r = `cancelOn[${n}]`;
|
|
121
|
-
if (typeof e?.event != "string" || e.event.length === 0) throw Error(`workflow '${t}': ${r}.event must be a non-empty event name, exactly as ctx.events.publish writes it.`);
|
|
122
|
-
if (e.schema === void 0 || typeof e.schema.ast != "object") throw Error(`workflow '${t}': ${r}.schema must be a Schema for the event payload. It is decoded before \`match\` runs, so the predicate reads the domain type rather than raw JSON.`);
|
|
123
|
-
if (typeof e.match != "function") throw Error(`workflow '${t}': ${r}.match is required. Omitting it would mean "cancel every live run of this workflow whenever '${e.event}' is published" — write \`match: () => true\` if that is what you mean, so it is visible in review.`);
|
|
124
|
-
let i = e.within === void 0 ? void 0 : E(e.within, `${r}.within`, t);
|
|
125
|
-
return {
|
|
126
|
-
event: e.event,
|
|
127
|
-
schema: e.schema,
|
|
128
|
-
match: e.match,
|
|
129
|
-
...i === void 0 ? {} : { withinMs: i },
|
|
130
|
-
reason: e.reason ?? `cancelOn:${e.event}`
|
|
131
|
-
};
|
|
132
|
-
});
|
|
133
|
-
e.length > 0 && (r.cancelOn = e);
|
|
134
|
-
}
|
|
135
|
-
if (r.timeouts?.startMs !== void 0 && T(r).length === 0) throw Error(`workflow '${t}': timeouts.start bounds how long a run may sit in the ADMISSION queue, but this workflow declares no control that can defer one (debounce, batch, throttle, concurrency). It would never fire. Use timeouts.finish to bound the run itself.`);
|
|
136
|
-
return r;
|
|
137
|
-
}, oe = (e) => {
|
|
138
|
-
let t = /* @__PURE__ */ new Map();
|
|
139
|
-
for (let n of e) {
|
|
140
|
-
let e = n?.concurrency;
|
|
141
|
-
if (e?.pool === void 0) continue;
|
|
142
|
-
let r = t.get(e.pool);
|
|
143
|
-
if (r === void 0) t.set(e.pool, {
|
|
144
|
-
limit: e.limit,
|
|
145
|
-
workflows: [n.workflowName]
|
|
146
|
-
});
|
|
147
|
-
else if (r.limit !== e.limit) throw Error(`concurrency pool '${e.pool}': '${n.workflowName}' declares limit ${e.limit}, but ${r.workflows.map((e) => `'${e}'`).join(", ")} declare${r.workflows.length === 1 ? "s" : ""} limit ${r.limit}. A pool is ONE budget — every member must declare the same number, or the enforced limit would depend on which workflow's start arrived first. Align the limits, or give the workflows different pool names if they were never meant to share.`);
|
|
148
|
-
else r.workflows.push(n.workflowName);
|
|
149
|
-
}
|
|
150
|
-
}, j = class extends f.Tag("@voltro/WorkflowRunRecorder")() {}, M = _.unsafeMake(void 0), N = _.unsafeMake(void 0), P = _.unsafeMake(void 0), se = h.gen(function* () {
|
|
151
|
-
let e = yield* _.get(N), t = yield* _.get(P);
|
|
152
|
-
return e === void 0 || t === void 0 ? void 0 : {
|
|
153
|
-
executionId: e,
|
|
154
|
-
step: t
|
|
155
|
-
};
|
|
156
|
-
}), ce = _.unsafeMake(void 0), F = _.unsafeMake(void 0), I = _.unsafeMake([]), le = () => _.get(M), L = () => _.get(N), R = class extends f.Tag("@voltro/WorkflowStepInterceptor")() {}, z = 864e5, B = /* @__PURE__ */ new Set([
|
|
157
|
-
"skip",
|
|
158
|
-
"buffer",
|
|
159
|
-
"cancelOther"
|
|
160
|
-
]), V = /* @__PURE__ */ new Set([
|
|
161
|
-
"skip",
|
|
162
|
-
"latest",
|
|
163
|
-
"all"
|
|
164
|
-
]), H = (e, t) => {
|
|
165
|
-
if (t === void 0) return;
|
|
166
|
-
if (typeof t.timezone != "string" || t.timezone.trim() === "") throw Error(`workflow '${e}': schedule.timezone is required (e.g. "UTC", "Europe/Berlin") — never server-local, which differs between your machine and the container.`);
|
|
167
|
-
let n = p.parse(t.cron, t.timezone);
|
|
168
|
-
if (g.isLeft(n)) throw Error(`workflow '${e}': schedule.cron "${t.cron}" (tz="${t.timezone}") is not a valid cron expression — ${String(n.left)}`);
|
|
169
|
-
let r = t.onOverlap ?? "skip";
|
|
170
|
-
if (!B.has(r)) throw Error(`workflow '${e}': schedule.onOverlap must be 'skip' | 'buffer' | 'cancelOther', got ${JSON.stringify(r)}`);
|
|
171
|
-
let i = t.backfill ?? "skip";
|
|
172
|
-
if (!V.has(i)) throw Error(`workflow '${e}': schedule.backfill must be 'skip' | 'latest' | 'all', got ${JSON.stringify(i)}`);
|
|
173
|
-
let a = z;
|
|
174
|
-
return t.maxRuntime !== void 0 && (a = U(t.maxRuntime, e)), {
|
|
175
|
-
cron: t.cron,
|
|
176
|
-
timezone: t.timezone,
|
|
177
|
-
...t.payload === void 0 ? {} : { payload: t.payload },
|
|
178
|
-
onOverlap: r,
|
|
179
|
-
backfill: i,
|
|
180
|
-
maxRuntimeMs: a
|
|
181
|
-
};
|
|
182
|
-
}, U = (e, t) => {
|
|
183
|
-
let n;
|
|
184
|
-
try {
|
|
185
|
-
n = m.toMillis(m.decode(e));
|
|
186
|
-
} catch {
|
|
187
|
-
throw Error(`workflow '${t}': schedule.maxRuntime is not a duration Effect can read (got ${JSON.stringify(e)}). Use '2 hours', a number of milliseconds, or a Duration.`);
|
|
188
|
-
}
|
|
189
|
-
if (!Number.isFinite(n) || n <= 0) throw Error(`workflow '${t}': schedule.maxRuntime must be a positive finite duration`);
|
|
190
|
-
return n;
|
|
191
|
-
}, W = "__voltroWorkflowSchedule", ue = (e) => {
|
|
192
|
-
if (typeof e != "object" || !e) return;
|
|
193
|
-
let t = e[W];
|
|
194
|
-
return t === void 0 ? void 0 : t;
|
|
195
|
-
}, de = (e) => {
|
|
196
|
-
let t = /* @__PURE__ */ new Map();
|
|
197
|
-
for (let n of e) t.set(n.stepName, (t.get(n.stepName) ?? 0) + 1);
|
|
198
|
-
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = (e) => !r.has(e) && (r.add(e), !0);
|
|
199
|
-
return {
|
|
200
|
-
reach: (e) => {
|
|
201
|
-
let r = (n.get(e) ?? 0) + 1;
|
|
202
|
-
n.set(e, r);
|
|
203
|
-
let a = t.get(e) ?? 0;
|
|
204
|
-
if (a !== 0 && !(r <= a) && i(`extra:${e}`)) return {
|
|
205
|
-
kind: "extra-step-occurrence",
|
|
206
|
-
stepName: e,
|
|
207
|
-
recorded: a,
|
|
208
|
-
reached: r,
|
|
209
|
-
detail: `step '${e}' was reached ${r} time(s) on this attempt but this run only ever recorded ${a} — the body may have changed how often it runs this step (a loop bound), so the journal replays a result for an iteration the code no longer means.`
|
|
210
|
-
};
|
|
211
|
-
},
|
|
212
|
-
settle: () => {
|
|
213
|
-
let e = [];
|
|
214
|
-
for (let [r, a] of t) (n.get(r) ?? 0) > 0 || i(`unreached:${r}`) && e.push({
|
|
215
|
-
kind: "unreached-step",
|
|
216
|
-
stepName: r,
|
|
217
|
-
recorded: a,
|
|
218
|
-
reached: 0,
|
|
219
|
-
detail: `step '${r}' ran on an earlier attempt of this run but the current code never reaches it — the step was renamed, removed, or moved behind a branch, so its journaled result is orphaned and any step that replaced it executed fresh.`
|
|
220
|
-
});
|
|
221
|
-
return e;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
}, G = _.unsafeMake(void 0), K = (e) => ({
|
|
225
|
-
kind: e.kind,
|
|
226
|
-
stepName: e.stepName,
|
|
227
|
-
recorded: e.recorded,
|
|
228
|
-
reached: e.reached,
|
|
229
|
-
detail: e.detail
|
|
230
|
-
}), q = (e) => h.gen(function* () {
|
|
231
|
-
if (e.length === 0) return;
|
|
232
|
-
let t = yield* _.get(M), n = yield* h.serviceOption(j);
|
|
233
|
-
if (t === void 0 || n._tag !== "Some") return;
|
|
234
|
-
let r = n.value;
|
|
235
|
-
for (let n of e) yield* h.promise(() => r.recordEvent({
|
|
236
|
-
runId: t,
|
|
237
|
-
eventType: "nondeterminism-suspected",
|
|
238
|
-
payload: K(n)
|
|
239
|
-
}).then(() => void 0).catch(() => void 0));
|
|
240
|
-
}), fe = (e) => {
|
|
241
|
-
if (typeof e != "object" || !e) return;
|
|
242
|
-
let t = e.retryAfterMillis;
|
|
243
|
-
if (typeof t == "number" && Number.isFinite(t) && t >= 0) return m.millis(t);
|
|
244
|
-
let n = e.retryAfter;
|
|
245
|
-
if (typeof n == "number" && Number.isFinite(n) && n >= 0) return m.seconds(n);
|
|
246
|
-
}, J = (e) => m.decode(e), pe = (e) => typeof e == "object" && e && "_tag" in e ? String(e._tag) : void 0, me = (e) => e !== void 0 && (e.maxAttempts ?? 3) > 1, he = (e) => {
|
|
247
|
-
if (e.retryable) return e.retryable;
|
|
248
|
-
if (e.retryableErrors && e.retryableErrors.length > 0) {
|
|
249
|
-
let t = new Set(e.retryableErrors);
|
|
250
|
-
return (e) => {
|
|
251
|
-
let n = pe(e);
|
|
252
|
-
return n !== void 0 && t.has(n);
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
return () => !0;
|
|
256
|
-
}, ge = (e) => {
|
|
257
|
-
let t = e.baseDelay ?? "200 millis", n = e.strategy ?? "exponential", r = e.maxAttempts ?? 3, i = n === "linear" ? y.linear(J(e.step ?? t)) : n === "fixed" ? y.spaced(J(t)) : y.exponential(J(t), e.factor ?? 2);
|
|
258
|
-
if (e.maxDelay !== void 0) {
|
|
259
|
-
let t = J(e.maxDelay);
|
|
260
|
-
i = y.modifyDelay(i, (e, n) => m.min(n, t));
|
|
261
|
-
}
|
|
262
|
-
(e.jitter ?? !0) === !0 && (i = y.jittered(i));
|
|
263
|
-
let a = y.intersect(i, y.recurs(Math.max(0, r - 1)));
|
|
264
|
-
return e.maxElapsed !== void 0 && (a = y.upTo(J(e.maxElapsed))(a)), a;
|
|
265
|
-
}, _e = (e, t) => {
|
|
266
|
-
let n = m.toMillis(J(e.baseDelay ?? "200 millis")), r = e.strategy ?? "exponential", i = r === "fixed" ? n : r === "linear" ? n + m.toMillis(J(e.step ?? e.baseDelay ?? "200 millis")) * (t - 1) : n * (e.factor ?? 2) ** (t - 1);
|
|
267
|
-
return e.maxDelay !== void 0 && (i = Math.min(i, m.toMillis(J(e.maxDelay)))), (e.jitter ?? !0) === !0 && (i *= Math.random()), i;
|
|
268
|
-
}, ve = (e, t, n, r) => h.gen(function* () {
|
|
269
|
-
let i = t.maxAttempts ?? 3, a = t.maxElapsed === void 0 ? Infinity : m.toMillis(J(t.maxElapsed)), o = yield* h.sync(() => Date.now()), s = 0;
|
|
270
|
-
for (;;) {
|
|
271
|
-
let c = yield* h.exit(e);
|
|
272
|
-
if (ee.isSuccess(c)) return c.value;
|
|
273
|
-
let l = c.cause, u = d.failureOption(l), f = v.isSome(u) ? u.value : d.squash(l);
|
|
274
|
-
s += 1;
|
|
275
|
-
let p = (yield* h.sync(() => Date.now())) - o;
|
|
276
|
-
if (s >= i || !n(f) || p >= a) return yield* h.failCause(l);
|
|
277
|
-
r?.(f);
|
|
278
|
-
let g = fe(f), _ = g === void 0 ? _e(t, s) : m.toMillis(g);
|
|
279
|
-
yield* h.sleep(m.millis(_));
|
|
280
|
-
}
|
|
281
|
-
}), ye = (e, t, n) => {
|
|
282
|
-
if (!me(t)) return e;
|
|
283
|
-
let r = he(t);
|
|
284
|
-
if (t.respectRetryAfter === !0) return ve(e, t, r, n);
|
|
285
|
-
let i = ge(t), a = n ? h.tapError(e, (e) => h.sync(() => {
|
|
286
|
-
r(e) && n(e);
|
|
287
|
-
})) : e;
|
|
288
|
-
return h.retry(a, {
|
|
289
|
-
schedule: i,
|
|
290
|
-
while: r
|
|
291
|
-
});
|
|
292
|
-
}, Y = Symbol.for("voltro.workflow.workerLayer"), X = Symbol.for("voltro.workflow.version"), Z = "__voltroWorkflowMessages", Q = "__voltroWorkflowFlowControl", be = (e) => typeof e == "object" && !!e && e[Y] === !0, xe = (e) => typeof e == "object" && e && e[X] !== void 0 ? e[X] : {
|
|
293
|
-
version: "1",
|
|
294
|
-
compatibleWith: ["1"],
|
|
295
|
-
patches: []
|
|
296
|
-
}, Se = ((e) => {
|
|
297
|
-
let t = c.make(e), n = e.suspendOnFailure === !0 ? t.annotate(c.SuspendOnFailure, !0) : t;
|
|
298
|
-
S(n, (t, r, i) => h.gen(function* () {
|
|
299
|
-
let a = n.payloadSchema.make(t), o = yield* u.WorkflowEngine;
|
|
300
|
-
return yield* h.annotateCurrentSpan({ executionId: r }), yield* o.execute(n, {
|
|
301
|
-
executionId: r,
|
|
302
|
-
payload: a,
|
|
303
|
-
discard: i,
|
|
304
|
-
suspendedRetrySchedule: e.suspendedRetrySchedule
|
|
305
|
-
});
|
|
306
|
-
}).pipe(h.withSpan(`${e.name}.execute`, { captureStackTrace: !1 })));
|
|
307
|
-
let r = String(e.version ?? "1"), i = {
|
|
308
|
-
version: r,
|
|
309
|
-
compatibleWith: (e.compatibleWith ?? [r]).map(String),
|
|
310
|
-
patches: [...e.patches ?? []]
|
|
311
|
-
}, a = {
|
|
312
|
-
signals: { ...e.messages?.signals ?? {} },
|
|
313
|
-
updates: { ...e.messages?.updates ?? {} }
|
|
314
|
-
};
|
|
315
|
-
Object.defineProperty(n, X, {
|
|
316
|
-
value: i,
|
|
317
|
-
enumerable: !1
|
|
318
|
-
}), Object.defineProperty(n, Z, {
|
|
319
|
-
value: a,
|
|
320
|
-
enumerable: !1
|
|
321
|
-
}), ne(n, b(e.name, e));
|
|
322
|
-
let o = A({
|
|
323
|
-
workflowName: e.name,
|
|
324
|
-
payloadSchema: e.payload,
|
|
325
|
-
control: e
|
|
326
|
-
});
|
|
327
|
-
o !== void 0 && Object.defineProperty(n, Q, {
|
|
328
|
-
value: o,
|
|
329
|
-
enumerable: !1
|
|
330
|
-
});
|
|
331
|
-
let s = H(e.name, e.schedule);
|
|
332
|
-
return s !== void 0 && Object.defineProperty(n, W, {
|
|
333
|
-
value: s,
|
|
334
|
-
enumerable: !1
|
|
335
|
-
}), n;
|
|
336
|
-
}), Ce = (e) => {
|
|
337
|
-
if (typeof e != "object" || !e) return;
|
|
338
|
-
let t = e[Q];
|
|
339
|
-
return t === void 0 ? void 0 : t;
|
|
340
|
-
}, we = i.make, Te = i.process, Ee = ((...e) => {
|
|
341
|
-
let t = i.worker(...e);
|
|
342
|
-
return Object.defineProperty(t, Y, {
|
|
343
|
-
value: !0,
|
|
344
|
-
enumerable: !1
|
|
345
|
-
}), t;
|
|
346
|
-
}), De = o.rateLimit, $ = (e) => h.gen(function* () {
|
|
347
|
-
let t = yield* M, r = yield* h.serviceOption(j), i = m.toMillis(m.decode(e.duration));
|
|
348
|
-
if (t !== void 0 && r._tag === "Some") {
|
|
349
|
-
let a = r.value, o = new Date(Date.now() + i).toISOString(), s = yield* F;
|
|
350
|
-
yield* h.promise(() => a.recordEvent({
|
|
351
|
-
runId: t,
|
|
352
|
-
eventType: "timer-set",
|
|
353
|
-
payload: {
|
|
354
|
-
name: e.name,
|
|
355
|
-
durationMs: i,
|
|
356
|
-
scheduledWakeAt: o,
|
|
357
|
-
...s === void 0 ? {} : { tenantId: s }
|
|
358
|
-
}
|
|
359
|
-
}).catch(() => {}));
|
|
360
|
-
let c = Date.now();
|
|
361
|
-
yield* n.sleep(e), yield* h.promise(() => a.recordEvent({
|
|
362
|
-
runId: t,
|
|
363
|
-
eventType: "timer-fired",
|
|
364
|
-
payload: {
|
|
365
|
-
name: e.name,
|
|
366
|
-
actualDurationMs: Date.now() - c,
|
|
367
|
-
...s === void 0 ? {} : { tenantId: s }
|
|
368
|
-
}
|
|
369
|
-
}).catch(() => {}));
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
yield* n.sleep(e);
|
|
373
|
-
}), Oe = (t) => h.gen(function* () {
|
|
374
|
-
let n = (yield* e.make({
|
|
375
|
-
name: `sleepUntil:${t.name}`,
|
|
376
|
-
success: te.Number,
|
|
377
|
-
execute: h.sync(() => t.until instanceof Date ? t.until.getTime() : t.until)
|
|
378
|
-
})) - Date.now();
|
|
379
|
-
n <= 0 || (yield* $({
|
|
380
|
-
name: t.name,
|
|
381
|
-
duration: `${n} millis`
|
|
382
|
-
}));
|
|
383
|
-
}), ke = (t, n, r, i) => h.gen(function* () {
|
|
384
|
-
let a = yield* M, o = yield* e.CurrentAttempt, s = yield* h.serviceOption(j), c = yield* h.serviceOption(R), l = c._tag === "Some" ? c.value.interceptor(n, {
|
|
385
|
-
runId: a ?? "unrecorded",
|
|
386
|
-
stepName: t,
|
|
387
|
-
attempt: o
|
|
388
|
-
}) : n, u, f;
|
|
389
|
-
if (a !== void 0 && s._tag === "Some") {
|
|
390
|
-
f = s.value;
|
|
391
|
-
let e = i === void 0 ? void 0 : (({ retryable: e, ...t }) => t)(i);
|
|
392
|
-
try {
|
|
393
|
-
u = yield* h.promise(() => f.startStep({
|
|
394
|
-
runId: a,
|
|
395
|
-
stepName: t,
|
|
396
|
-
attempt: o,
|
|
397
|
-
stepInput: r,
|
|
398
|
-
...e === void 0 ? {} : { retryPolicy: e }
|
|
399
|
-
}));
|
|
400
|
-
} catch {
|
|
401
|
-
u = void 0;
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
let p = Date.now();
|
|
405
|
-
return yield* h.locally(ye(l, i), P, t).pipe(h.tap((e) => u && f ? h.promise(async () => {
|
|
406
|
-
try {
|
|
407
|
-
await f.endStepSuccess({
|
|
408
|
-
stepRecordId: u,
|
|
409
|
-
output: e,
|
|
410
|
-
durationMs: Date.now() - p
|
|
411
|
-
});
|
|
412
|
-
} catch {}
|
|
413
|
-
}) : h.void), h.tapErrorCause((e) => u && f && !d.isInterruptedOnly(e) ? h.promise(async () => {
|
|
414
|
-
try {
|
|
415
|
-
let t = d.failureOption(e), n = Array.from(d.failures(e)), r = Array.from(d.defects(e)), i = t._tag === "Some" ? t.value : r[0] ?? d.squash(e), a = i?.message ?? String(i), o = i && typeof i == "object" && "_tag" in i ? String(i._tag) : null;
|
|
416
|
-
await f.endStepFailure({
|
|
417
|
-
stepRecordId: u,
|
|
418
|
-
errorTag: o,
|
|
419
|
-
errorMessage: a,
|
|
420
|
-
errorCause: {
|
|
421
|
-
pretty: d.pretty(e),
|
|
422
|
-
failures: n,
|
|
423
|
-
defects: r
|
|
424
|
-
},
|
|
425
|
-
durationMs: Date.now() - p
|
|
426
|
-
});
|
|
427
|
-
} catch {}
|
|
428
|
-
}) : h.void));
|
|
429
|
-
}), Ae = (e) => h.gen(function* () {
|
|
430
|
-
let t = yield* _.get(G);
|
|
431
|
-
if (t === void 0) return;
|
|
432
|
-
let n = t.reach(e);
|
|
433
|
-
n !== void 0 && (yield* q([n]));
|
|
434
|
-
}), je = (e, t) => {
|
|
435
|
-
let n = e;
|
|
436
|
-
return {
|
|
437
|
-
...e,
|
|
438
|
-
commit: () => h.zipRight(Ae(t), n)
|
|
439
|
-
};
|
|
440
|
-
}, Me = (t) => {
|
|
441
|
-
let { input: n, retry: r, ...i } = t;
|
|
442
|
-
return je(e.make({
|
|
443
|
-
...i,
|
|
444
|
-
execute: ke(i.name, i.execute, n, r)
|
|
445
|
-
}), i.name);
|
|
446
|
-
}, Ne = (e) => h.map(_.get(I), (t) => t.includes(e)), Pe = c.withCompensation, Fe = e.idempotencyKey;
|
|
447
|
-
//#endregion
|
|
448
|
-
export { ue as A, se as B, l as C, q as D, K as E, M as F, T as G, le as H, P as I, A as J, w as K, F as L, N as M, ce as N, z as O, I as P, j as R, Se as S, de as T, ae as U, L as V, oe as W, ie as X, S as Y, re as Z, Oe as _, r as a, t as b, s as c, be as d, Ne as f, $ as g, De as h, Y as i, H as j, W as k, Ce as l, Ee as m, Z as n, we as o, Te as p, C as q, X as r, a as s, Q as t, xe as u, Me as v, G as w, Pe as x, Fe as y, R as z };
|