@voltro/workflow 0.84.0 → 0.86.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 +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -151
- package/dist/admission.js +140 -0
- package/dist/admissionDrainer.js +705 -0
- package/dist/admissionGate.js +115 -0
- package/dist/admissionStore.js +347 -0
- package/dist/admissionSubmission.js +297 -0
- package/dist/admissionTables.js +137 -0
- package/dist/admissionTransaction.js +21 -0
- package/dist/awaitEvent.js +82 -0
- package/dist/budgetHold.js +136 -0
- package/dist/cancelOnPlan.js +75 -0
- package/dist/cancelOnSweep.js +188 -0
- package/dist/cancelPendingStart.js +50 -0
- package/dist/cluster.d.ts +304 -280
- package/dist/cluster.js +8 -2
- package/dist/clusterCron.js +11 -0
- package/dist/clusterDiagnostics.js +20 -0
- package/dist/clusterDiagnosticsSql.js +145 -0
- package/dist/clusterLayer.js +110 -0
- package/dist/clusterMigrationGate.js +61 -0
- package/dist/clusterRunnerLayer.js +21 -0
- package/dist/clusterTestSuite.d.ts +11 -11
- package/dist/clusterTestSuite.js +257 -257
- package/dist/controlMonitor.js +13 -0
- package/dist/controlRequest.js +367 -0
- package/dist/executionRefusal.js +162 -0
- package/dist/failureHandoff.js +183 -0
- package/dist/failureMessage.js +12 -0
- package/dist/failureRecovery.js +50 -0
- package/dist/failureReportStore.js +60 -0
- package/dist/flowControl.js +142 -0
- package/dist/forwardStartReceipts.js +41 -0
- package/dist/inMemoryLayer.js +7 -0
- package/dist/inMemoryRecorder.js +56 -0
- package/dist/index.d.ts +456 -360
- package/dist/index.js +49 -5
- package/dist/inspectWorkflow.js +101 -0
- package/dist/journalEncryption.js +147 -0
- package/dist/messages.js +92 -0
- package/dist/nondeterminism.js +51 -0
- package/dist/parentClosure.js +141 -0
- package/dist/parentClosureRecovery.js +54 -0
- package/dist/pendingSubmission.js +85 -0
- package/dist/prepareSubmissionDispatch.js +17 -0
- package/dist/preparedExecution.js +14 -0
- package/dist/primitives.d.ts +56 -31
- package/dist/primitives.js +225 -2
- package/dist/queuedCancellationRequest.js +364 -0
- package/dist/queuedControl.js +21 -0
- package/dist/recorder.js +11 -0
- package/dist/residentExecutionEvidence.js +64 -0
- package/dist/retryPolicy.js +57 -0
- package/dist/runEventsTable.js +17 -0
- package/dist/runGeneration.js +345 -0
- package/dist/runRecording.js +615 -0
- package/dist/runStepsTable.js +28 -0
- package/dist/runnerStorageGuard.js +29 -0
- package/dist/runsTable.js +42 -0
- package/dist/scheduleDeclaration.js +44 -0
- package/dist/signalHint.js +23 -0
- package/dist/signals.js +70 -0
- package/dist/signalsSuspending.js +57 -0
- package/dist/sqliteWorkflowOwnership.js +26 -0
- package/dist/stalenessSweep.js +191 -0
- package/dist/startContextsTable.js +20 -0
- package/dist/startReceipt.js +143 -0
- package/dist/submissionRecovery.js +122 -0
- package/dist/submissionRejection.js +10 -0
- package/dist/submissionRetry.js +71 -0
- package/dist/suspensionUnavailable.js +9 -0
- package/dist/updates.js +87 -0
- package/dist/watermarkTable.js +9 -0
- package/dist/webCrypto.js +17 -0
- package/dist/workflowDelivery.js +24 -0
- package/dist/workflowJournal.js +124 -0
- package/dist/workflowJournalReset.js +111 -0
- package/dist/workflowReadSelections.js +12 -0
- package/dist/workflowRestartDispatch.js +29 -0
- package/dist/workflowRestartObservation.js +60 -0
- package/dist/workflowRestartPreparation.js +109 -0
- package/dist/workflowRestartReservation.js +426 -0
- package/dist/workflowResumeDispatch.js +29 -0
- package/package.json +6 -9
- package/dist/cluster-i3frC3Da.js +0 -646
- package/dist/clusterDiagnostics-CGUtnJkX.js +0 -2084
- package/dist/journalEncryption--n5VDdYO.js +0 -148
- package/dist/primitives-Btjhjm8P.js +0 -483
- package/dist/src-DP-lKqaG.js +0 -3867
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { resolveAdmissionKeys as e } from "./admission.js";
|
|
2
|
+
import { decodePendingPayload as t, evaluateAdmission as n, persistDefer as r, recordAdmission as i } from "./admissionStore.js";
|
|
3
|
+
import { and as a, eq as o } from "@voltro/database";
|
|
4
|
+
//#region src/admissionGate.ts
|
|
5
|
+
var s = async (t) => {
|
|
6
|
+
let { store: a, control: o, now: s } = t, l = e(o, t.payload), u = await n({
|
|
7
|
+
store: a,
|
|
8
|
+
control: o,
|
|
9
|
+
keys: l,
|
|
10
|
+
paused: t.paused,
|
|
11
|
+
now: s,
|
|
12
|
+
reconsidering: !1
|
|
13
|
+
});
|
|
14
|
+
if (u.kind === "drop") return await i({
|
|
15
|
+
store: a,
|
|
16
|
+
control: o,
|
|
17
|
+
keys: l,
|
|
18
|
+
outcome: "dropped",
|
|
19
|
+
mode: "rateLimit",
|
|
20
|
+
reason: `rate limit reached; retry after ${u.retryAfterMs}ms`,
|
|
21
|
+
collapsed: 1,
|
|
22
|
+
waitedMs: 0,
|
|
23
|
+
executionId: null,
|
|
24
|
+
runId: null,
|
|
25
|
+
tenantId: t.tenantId,
|
|
26
|
+
now: s
|
|
27
|
+
}), {
|
|
28
|
+
kind: "dropped",
|
|
29
|
+
retryAfterMs: u.retryAfterMs
|
|
30
|
+
};
|
|
31
|
+
if (u.kind === "skip") return await i({
|
|
32
|
+
store: a,
|
|
33
|
+
control: o,
|
|
34
|
+
keys: l,
|
|
35
|
+
outcome: "skipped",
|
|
36
|
+
mode: "singleton",
|
|
37
|
+
reason: `singleton key held by ${u.incumbent.executionId}`,
|
|
38
|
+
collapsed: 1,
|
|
39
|
+
waitedMs: 0,
|
|
40
|
+
executionId: u.incumbent.executionId,
|
|
41
|
+
runId: u.incumbent.runId || null,
|
|
42
|
+
tenantId: t.tenantId,
|
|
43
|
+
now: s
|
|
44
|
+
}), {
|
|
45
|
+
kind: "skipped",
|
|
46
|
+
executionId: u.incumbent.executionId,
|
|
47
|
+
runId: u.incumbent.runId
|
|
48
|
+
};
|
|
49
|
+
if (u.kind === "defer") return {
|
|
50
|
+
kind: "queued",
|
|
51
|
+
intentId: await r({
|
|
52
|
+
store: a,
|
|
53
|
+
control: o,
|
|
54
|
+
decision: u,
|
|
55
|
+
payload: t.payload,
|
|
56
|
+
callerContext: t.callerContext,
|
|
57
|
+
tenantId: t.tenantId,
|
|
58
|
+
now: s,
|
|
59
|
+
...t.queuedAppVersion === void 0 ? {} : { queuedAppVersion: t.queuedAppVersion },
|
|
60
|
+
...t.queuedSchemaFingerprint === void 0 ? {} : { queuedSchemaFingerprint: t.queuedSchemaFingerprint }
|
|
61
|
+
}),
|
|
62
|
+
mode: u.mode,
|
|
63
|
+
dueAt: u.dueAt
|
|
64
|
+
};
|
|
65
|
+
let d = t.payload, f = [], p = 1;
|
|
66
|
+
if (o.batch !== void 0 && l.batchKey !== void 0) {
|
|
67
|
+
let e = await c(a, o.workflowName, l.batchKey, o.batch.maxSize);
|
|
68
|
+
d = { items: [...e.map((e) => e.payload), t.payload] }, f = e.map((e) => e.id), p = e.length + 1;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
kind: "start",
|
|
72
|
+
ledgerId: await i({
|
|
73
|
+
store: a,
|
|
74
|
+
control: o,
|
|
75
|
+
keys: l,
|
|
76
|
+
outcome: "admitted",
|
|
77
|
+
mode: t.waiting ? "immediate" : null,
|
|
78
|
+
reason: u.reason,
|
|
79
|
+
collapsed: p,
|
|
80
|
+
waitedMs: 0,
|
|
81
|
+
executionId: null,
|
|
82
|
+
runId: null,
|
|
83
|
+
tenantId: t.tenantId,
|
|
84
|
+
now: s
|
|
85
|
+
}),
|
|
86
|
+
keys: l,
|
|
87
|
+
payload: d,
|
|
88
|
+
consume: f,
|
|
89
|
+
collapsed: p,
|
|
90
|
+
...u.evict === void 0 ? {} : { evict: {
|
|
91
|
+
executionId: u.evict.executionId,
|
|
92
|
+
runId: u.evict.runId
|
|
93
|
+
} }
|
|
94
|
+
};
|
|
95
|
+
}, c = async (e, n, r, i) => (await e.query({
|
|
96
|
+
table: "_voltro_workflow_pending",
|
|
97
|
+
predicate: a(o("workflowName", n), o("controlKey", r), o("mode", "batch")),
|
|
98
|
+
order: [{
|
|
99
|
+
column: "firstSeenAt",
|
|
100
|
+
direction: "asc"
|
|
101
|
+
}],
|
|
102
|
+
take: i,
|
|
103
|
+
skip: void 0,
|
|
104
|
+
projection: void 0
|
|
105
|
+
})).map((r) => ({
|
|
106
|
+
id: String(r.id),
|
|
107
|
+
payload: t(e, n, r.payload)
|
|
108
|
+
})), l = async (e, t, n, r) => {
|
|
109
|
+
await e.update("_voltro_workflow_admissions", t, {
|
|
110
|
+
executionId: n,
|
|
111
|
+
runId: r
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { s as admitStart, l as linkExecution };
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { openErrorText as e, sealErrorText as t } from "./journalEncryption.js";
|
|
2
|
+
import { withAdmissionTransaction as n } from "./admissionTransaction.js";
|
|
3
|
+
import { comparePendingOrder as r, decideAdmission as i } from "./admission.js";
|
|
4
|
+
import { settlePendingStartReceipts as a } from "./startReceipt.js";
|
|
5
|
+
import { and as o, eq as s, gt as c, isNull as l, or as u } from "@voltro/database";
|
|
6
|
+
import { createHash as d, randomUUID as f } from "node:crypto";
|
|
7
|
+
//#region src/admissionStore.ts
|
|
8
|
+
var p = "_voltro_workflow_pending", m = "_voltro_workflow_admissions", h = "_voltro_workflow_pauses", g = (e) => o(l("releasedAt"), u(l("executionId"), c("expiresAt", new Date(e)))), _ = (e, t, n) => e.encodeWorkflowPayload === void 0 ? n : e.encodeWorkflowPayload(t, n), v = (e, t, n) => e.decodeWorkflowPayload === void 0 ? n : e.decodeWorkflowPayload(t, n), y = 864e5, b = (e, t, n) => `wfp_${d("sha256").update(`${e}\u0000${t}\u0000${n}`).digest("hex").slice(0, 40)}`, x = (e) => {
|
|
9
|
+
if (e instanceof Date) return e.getTime();
|
|
10
|
+
if (typeof e == "number") return e;
|
|
11
|
+
let t = Date.parse(String(e));
|
|
12
|
+
return Number.isNaN(t) ? 0 : t;
|
|
13
|
+
}, S = (e, t) => {
|
|
14
|
+
let n = typeof e == "number" ? e : Number(e);
|
|
15
|
+
return Number.isFinite(n) ? Math.trunc(n) : t;
|
|
16
|
+
}, C = (t) => ({
|
|
17
|
+
id: String(t.id),
|
|
18
|
+
tenantId: t.tenantId === null || t.tenantId === void 0 ? null : String(t.tenantId),
|
|
19
|
+
workflowName: String(t.workflowName),
|
|
20
|
+
controlKey: String(t.controlKey ?? ""),
|
|
21
|
+
mode: String(t.mode),
|
|
22
|
+
payload: t.payload,
|
|
23
|
+
callerContext: t.callerContext ?? null,
|
|
24
|
+
queuedAppVersion: t.queuedAppVersion === null || t.queuedAppVersion === void 0 ? null : String(t.queuedAppVersion),
|
|
25
|
+
queuedSchemaFingerprint: t.queuedSchemaFingerprint === null || t.queuedSchemaFingerprint === void 0 ? null : String(t.queuedSchemaFingerprint),
|
|
26
|
+
priority: S(t.priority, 0),
|
|
27
|
+
dueAt: x(t.dueAt),
|
|
28
|
+
deadlineAt: t.deadlineAt === null || t.deadlineAt === void 0 ? void 0 : x(t.deadlineAt),
|
|
29
|
+
collapsed: S(t.collapsed, 1),
|
|
30
|
+
firstSeenAt: x(t.firstSeenAt),
|
|
31
|
+
attempts: S(t.attempts, 0),
|
|
32
|
+
lastError: t.lastError === null || t.lastError === void 0 ? null : e(String(t.lastError)),
|
|
33
|
+
deadLetteredAt: t.deadLetteredAt === null || t.deadLetteredAt === void 0 ? void 0 : x(t.deadLetteredAt)
|
|
34
|
+
}), w = (e, t, n, r) => ({
|
|
35
|
+
table: e,
|
|
36
|
+
predicate: t,
|
|
37
|
+
order: n,
|
|
38
|
+
take: r,
|
|
39
|
+
skip: void 0,
|
|
40
|
+
projection: void 0
|
|
41
|
+
}), T = async (e) => {
|
|
42
|
+
let t = await e.query(w(h, void 0, [], 1e3));
|
|
43
|
+
return new Set(t.map((e) => String(e.id)));
|
|
44
|
+
}, E = async (e, t, n, r) => {
|
|
45
|
+
await e.upsert(h, {
|
|
46
|
+
id: t,
|
|
47
|
+
pausedAt: /* @__PURE__ */ new Date(),
|
|
48
|
+
pausedBy: n,
|
|
49
|
+
reason: r
|
|
50
|
+
}, {
|
|
51
|
+
conflictColumns: ["id"],
|
|
52
|
+
update: [
|
|
53
|
+
"pausedAt",
|
|
54
|
+
"pausedBy",
|
|
55
|
+
"reason"
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}, D = async (e, t) => e.delete(h, t), O = async (e) => {
|
|
59
|
+
let { store: t, control: n, keys: r, now: i } = e, a = { paused: e.paused }, l = [];
|
|
60
|
+
n.debounce !== void 0 && r.debounceKey !== void 0 && l.push((async () => {
|
|
61
|
+
let e = (await t.query(w(p, o(s("workflowName", n.workflowName), s("controlKey", r.debounceKey), s("mode", "debounce")), [], 1)))[0];
|
|
62
|
+
if (e === void 0) return;
|
|
63
|
+
let i = e.deadlineAt === null || e.deadlineAt === void 0 ? void 0 : x(e.deadlineAt);
|
|
64
|
+
a.debouncePending = {
|
|
65
|
+
firstSeenAt: x(e.firstSeenAt),
|
|
66
|
+
collapsed: S(e.collapsed, 1),
|
|
67
|
+
...i === void 0 ? {} : { deadlineAt: i }
|
|
68
|
+
};
|
|
69
|
+
})()), n.batch !== void 0 && r.batchKey !== void 0 && l.push((async () => {
|
|
70
|
+
let e = await t.query(w(p, o(s("workflowName", n.workflowName), s("controlKey", r.batchKey), s("mode", "batch")), [{
|
|
71
|
+
column: "firstSeenAt",
|
|
72
|
+
direction: "asc"
|
|
73
|
+
}], n.batch.maxSize + 1));
|
|
74
|
+
e.length !== 0 && (a.batchPending = {
|
|
75
|
+
count: e.length,
|
|
76
|
+
firstSeenAt: x(e[0].firstSeenAt)
|
|
77
|
+
});
|
|
78
|
+
})()), n.singleton !== void 0 && r.singletonKey !== void 0 && l.push((async () => {
|
|
79
|
+
let e = await k(t, n.workflowName, r.singletonKey, i);
|
|
80
|
+
e === "unacknowledged" ? a.singletonUnacknowledged = !0 : e !== void 0 && (a.singletonHolder = e);
|
|
81
|
+
})()), n.concurrency !== void 0 && r.concurrencyKey !== void 0 && l.push((async () => {
|
|
82
|
+
let e = n.concurrency.pool === void 0 ? [s("workflowName", n.workflowName)] : [], c = await t.query(w(m, o(...e, s("concurrencyKey", r.concurrencyKey), g(i)), [], n.concurrency.limit));
|
|
83
|
+
a.inFlight = c.length;
|
|
84
|
+
})());
|
|
85
|
+
let u = n.rateLimit ?? n.throttle, d = r.rateLimitKey ?? r.throttleKey;
|
|
86
|
+
return u !== void 0 && d !== void 0 && l.push((async () => {
|
|
87
|
+
let e = await t.query(w(m, o(s("workflowName", n.workflowName), s("rateKey", d), s("outcome", "admitted"), c("admittedAt", new Date(i - u.periodMs))), [{
|
|
88
|
+
column: "admittedAt",
|
|
89
|
+
direction: "desc"
|
|
90
|
+
}], u.limit));
|
|
91
|
+
a.recentAdmissions = e.map((e) => x(e.admittedAt));
|
|
92
|
+
})()), await Promise.all(l), a;
|
|
93
|
+
}, k = async (e, t, n, r) => {
|
|
94
|
+
if ((await e.query(w("_voltro_workflow_admissions", o(s("workflowName", t), s("singletonKey", n), g(r), l("executionId")), [], 1))).length > 0) return "unacknowledged";
|
|
95
|
+
let i = (await e.query(w(m, o(s("workflowName", t), s("singletonKey", n), g(r)), [{
|
|
96
|
+
column: "admittedAt",
|
|
97
|
+
direction: "desc"
|
|
98
|
+
}], 1)))[0];
|
|
99
|
+
if (i === void 0) return;
|
|
100
|
+
let a = i.executionId;
|
|
101
|
+
if (a != null) return {
|
|
102
|
+
executionId: String(a),
|
|
103
|
+
runId: i.runId === null || i.runId === void 0 ? "" : String(i.runId),
|
|
104
|
+
admittedAt: x(i.admittedAt)
|
|
105
|
+
};
|
|
106
|
+
}, A = async (e) => {
|
|
107
|
+
let { store: t, control: n, decision: r, now: i } = e, o = M(r.mode, r.keys);
|
|
108
|
+
if (r.collapse === "hold") {
|
|
109
|
+
let a = e.existingId ?? b(n.workflowName, r.mode, o);
|
|
110
|
+
if (r.dueAt <= i) return a;
|
|
111
|
+
let c = await t.query(w(p, s("id", a), [], 1));
|
|
112
|
+
return c[0] === void 0 || x(c[0].dueAt) === r.dueAt || await t.update(p, a, {
|
|
113
|
+
dueAt: new Date(r.dueAt),
|
|
114
|
+
updatedAt: new Date(i)
|
|
115
|
+
}), a;
|
|
116
|
+
}
|
|
117
|
+
if (r.collapse === "replace") {
|
|
118
|
+
let s = b(n.workflowName, r.mode, o);
|
|
119
|
+
return await a(t, {
|
|
120
|
+
pendingId: s,
|
|
121
|
+
workflowName: n.workflowName,
|
|
122
|
+
tenantId: e.tenantId,
|
|
123
|
+
terminal: {
|
|
124
|
+
kind: "superseded",
|
|
125
|
+
at: i
|
|
126
|
+
}
|
|
127
|
+
}), await t.upsert(p, {
|
|
128
|
+
id: s,
|
|
129
|
+
tenantId: e.tenantId,
|
|
130
|
+
workflowName: n.workflowName,
|
|
131
|
+
controlKey: o,
|
|
132
|
+
mode: r.mode,
|
|
133
|
+
payload: _(t, n.workflowName, e.payload),
|
|
134
|
+
callerContext: e.callerContext ?? null,
|
|
135
|
+
queuedAppVersion: e.queuedAppVersion ?? null,
|
|
136
|
+
queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
|
|
137
|
+
priority: r.keys.priority,
|
|
138
|
+
dueAt: new Date(r.dueAt),
|
|
139
|
+
deadlineAt: r.deadlineAt === void 0 ? null : new Date(r.deadlineAt),
|
|
140
|
+
collapsed: 1,
|
|
141
|
+
firstSeenAt: new Date(i),
|
|
142
|
+
updatedAt: new Date(i),
|
|
143
|
+
attempts: 0,
|
|
144
|
+
lastError: null,
|
|
145
|
+
deadLetteredAt: null
|
|
146
|
+
}, {
|
|
147
|
+
conflictColumns: ["id"],
|
|
148
|
+
update: (a) => ({
|
|
149
|
+
payload: _(t, n.workflowName, e.payload),
|
|
150
|
+
callerContext: e.callerContext ?? null,
|
|
151
|
+
queuedAppVersion: e.queuedAppVersion ?? null,
|
|
152
|
+
queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
|
|
153
|
+
priority: r.keys.priority,
|
|
154
|
+
dueAt: new Date(r.dueAt),
|
|
155
|
+
deadlineAt: r.deadlineAt === void 0 ? a.deadlineAt ?? null : new Date(r.deadlineAt),
|
|
156
|
+
collapsed: S(a.collapsed, 1) + 1,
|
|
157
|
+
updatedAt: new Date(i),
|
|
158
|
+
attempts: 0,
|
|
159
|
+
lastError: null,
|
|
160
|
+
deadLetteredAt: null
|
|
161
|
+
})
|
|
162
|
+
}), s;
|
|
163
|
+
}
|
|
164
|
+
let c = await t.insert(p, {
|
|
165
|
+
id: `wfpi_${f()}`,
|
|
166
|
+
tenantId: e.tenantId,
|
|
167
|
+
workflowName: n.workflowName,
|
|
168
|
+
controlKey: o,
|
|
169
|
+
mode: r.mode,
|
|
170
|
+
payload: _(t, n.workflowName, e.payload),
|
|
171
|
+
callerContext: e.callerContext ?? null,
|
|
172
|
+
queuedAppVersion: e.queuedAppVersion ?? null,
|
|
173
|
+
queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
|
|
174
|
+
priority: r.keys.priority,
|
|
175
|
+
dueAt: new Date(r.dueAt),
|
|
176
|
+
deadlineAt: r.deadlineAt === void 0 ? null : new Date(r.deadlineAt),
|
|
177
|
+
collapsed: 1,
|
|
178
|
+
firstSeenAt: new Date(i),
|
|
179
|
+
updatedAt: new Date(i),
|
|
180
|
+
attempts: 0,
|
|
181
|
+
lastError: null,
|
|
182
|
+
deadLetteredAt: null
|
|
183
|
+
});
|
|
184
|
+
return String(c.id);
|
|
185
|
+
}, j = async (e) => {
|
|
186
|
+
let t = await e.store.insert(p, {
|
|
187
|
+
id: `wfpi_${f()}`,
|
|
188
|
+
tenantId: e.tenantId,
|
|
189
|
+
workflowName: e.workflowName,
|
|
190
|
+
controlKey: "",
|
|
191
|
+
mode: "delayed",
|
|
192
|
+
payload: _(e.store, e.workflowName, e.payload),
|
|
193
|
+
callerContext: e.callerContext ?? null,
|
|
194
|
+
queuedAppVersion: e.queuedAppVersion ?? null,
|
|
195
|
+
queuedSchemaFingerprint: e.queuedSchemaFingerprint ?? null,
|
|
196
|
+
priority: 0,
|
|
197
|
+
dueAt: new Date(e.at),
|
|
198
|
+
deadlineAt: null,
|
|
199
|
+
collapsed: 1,
|
|
200
|
+
firstSeenAt: new Date(e.now),
|
|
201
|
+
updatedAt: new Date(e.now),
|
|
202
|
+
attempts: 0,
|
|
203
|
+
lastError: null,
|
|
204
|
+
deadLetteredAt: null
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
intentId: String(t.id),
|
|
208
|
+
dueAt: e.at
|
|
209
|
+
};
|
|
210
|
+
}, M = (e, t) => {
|
|
211
|
+
switch (e) {
|
|
212
|
+
case "debounce": return t.debounceKey ?? "";
|
|
213
|
+
case "batch": return t.batchKey ?? "";
|
|
214
|
+
case "throttle": return t.throttleKey ?? "";
|
|
215
|
+
case "concurrency": return t.concurrencyKey ?? "";
|
|
216
|
+
case "singleton": return t.singletonKey ?? "";
|
|
217
|
+
default: return "";
|
|
218
|
+
}
|
|
219
|
+
}, N = async (e) => {
|
|
220
|
+
let { control: t, keys: n, now: r } = e, i = t.timeouts?.finishMs ?? 864e5, a = await e.store.insert(m, {
|
|
221
|
+
id: `wfad_${f()}`,
|
|
222
|
+
tenantId: e.tenantId,
|
|
223
|
+
workflowName: t.workflowName,
|
|
224
|
+
outcome: e.outcome,
|
|
225
|
+
mode: e.mode,
|
|
226
|
+
reason: e.reason,
|
|
227
|
+
collapsed: e.collapsed,
|
|
228
|
+
waitedMs: e.waitedMs,
|
|
229
|
+
executionId: e.executionId,
|
|
230
|
+
runId: e.runId,
|
|
231
|
+
singletonKey: n.singletonKey ?? null,
|
|
232
|
+
concurrencyKey: n.concurrencyKey ?? null,
|
|
233
|
+
concurrencyReservation: t.concurrency === void 0 ? null : {
|
|
234
|
+
pool: t.concurrency.pool ?? null,
|
|
235
|
+
key: n.concurrencyKey ?? null,
|
|
236
|
+
limit: t.concurrency.limit
|
|
237
|
+
},
|
|
238
|
+
rateKey: n.rateLimitKey ?? n.throttleKey ?? null,
|
|
239
|
+
admittedAt: new Date(r),
|
|
240
|
+
expiresAt: e.outcome === "admitted" ? new Date(r + i) : null,
|
|
241
|
+
releasedAt: e.outcome === "admitted" ? null : new Date(r)
|
|
242
|
+
});
|
|
243
|
+
return String(a.id);
|
|
244
|
+
}, P = async (e, t, n) => {
|
|
245
|
+
let r = !1;
|
|
246
|
+
for (;;) {
|
|
247
|
+
let i = await e.query(w(m, o(s("executionId", t), s("outcome", "admitted"), l("releasedAt")), [], 10));
|
|
248
|
+
if (i.length === 0) return r;
|
|
249
|
+
for (let t of i) if (await e.update("_voltro_workflow_admissions", String(t.id), { releasedAt: new Date(n) }) === null) throw Error("Admission lease disappeared during release");
|
|
250
|
+
r = !0;
|
|
251
|
+
}
|
|
252
|
+
}, F = async (e, t, n) => (await I(e, t, n)).due, I = async (e, t, n) => {
|
|
253
|
+
let i = (await e.query(w(p, l("deadLetteredAt"), [{
|
|
254
|
+
column: "priority",
|
|
255
|
+
direction: "desc"
|
|
256
|
+
}, {
|
|
257
|
+
column: "firstSeenAt",
|
|
258
|
+
direction: "asc"
|
|
259
|
+
}], n))).map(C), a;
|
|
260
|
+
for (let e of i) e.dueAt <= t || (a === void 0 || e.dueAt < a) && (a = e.dueAt);
|
|
261
|
+
return {
|
|
262
|
+
due: i.filter((e) => e.dueAt <= t).sort(r),
|
|
263
|
+
nextDueAt: a
|
|
264
|
+
};
|
|
265
|
+
}, L = async (e, t) => (await e.query(w(p, void 0, [{
|
|
266
|
+
column: "firstSeenAt",
|
|
267
|
+
direction: "asc"
|
|
268
|
+
}], t))).map(C), R = async (e, t) => e.delete(p, t), z = async (e, t, r, i) => n(e, (e) => B(e, t, r, i)), B = async (e, t, n, r) => {
|
|
269
|
+
let i = (await e.query(w(p, s("id", t), [], 1)))[0];
|
|
270
|
+
if (i === void 0) return !1;
|
|
271
|
+
let o = C(i);
|
|
272
|
+
if (await e.insert(m, {
|
|
273
|
+
id: `wfa_${f()}`,
|
|
274
|
+
tenantId: o.tenantId,
|
|
275
|
+
workflowName: o.workflowName,
|
|
276
|
+
outcome: "discarded",
|
|
277
|
+
mode: o.mode,
|
|
278
|
+
reason: n,
|
|
279
|
+
collapsed: o.collapsed,
|
|
280
|
+
waitedMs: Math.max(0, r - o.firstSeenAt),
|
|
281
|
+
executionId: null,
|
|
282
|
+
runId: null,
|
|
283
|
+
singletonKey: null,
|
|
284
|
+
concurrencyKey: o.controlKey === "" ? null : o.controlKey,
|
|
285
|
+
rateKey: null,
|
|
286
|
+
admittedAt: new Date(r),
|
|
287
|
+
expiresAt: null,
|
|
288
|
+
releasedAt: new Date(r)
|
|
289
|
+
}), await a(e, {
|
|
290
|
+
pendingId: t,
|
|
291
|
+
workflowName: o.workflowName,
|
|
292
|
+
tenantId: o.tenantId,
|
|
293
|
+
terminal: {
|
|
294
|
+
kind: "cancelled",
|
|
295
|
+
at: r
|
|
296
|
+
}
|
|
297
|
+
}), !await e.delete("_voltro_workflow_pending", t)) throw Error("Pending intent disappeared during discard");
|
|
298
|
+
return !0;
|
|
299
|
+
}, V = (e, t = Math.random) => {
|
|
300
|
+
let n = Math.min(1e3 * 2 ** Math.max(0, e - 1), 3e5);
|
|
301
|
+
return Math.round(n / 2 + t() * (n / 2));
|
|
302
|
+
}, H = async (e, n, r, i) => {
|
|
303
|
+
let a = n.attempts + 1;
|
|
304
|
+
await e.update(p, n.id, {
|
|
305
|
+
attempts: a,
|
|
306
|
+
lastError: t(n.workflowName, r.slice(0, 500)),
|
|
307
|
+
dueAt: new Date(i + V(a)),
|
|
308
|
+
updatedAt: new Date(i)
|
|
309
|
+
});
|
|
310
|
+
}, U = async (e, n, r, i) => await e.update(p, n.id, {
|
|
311
|
+
attempts: n.attempts + 1,
|
|
312
|
+
lastError: t(n.workflowName, r.slice(0, 500)),
|
|
313
|
+
deadLetteredAt: new Date(i),
|
|
314
|
+
updatedAt: new Date(i)
|
|
315
|
+
}) !== null, W = async (e, t, n) => {
|
|
316
|
+
let r = (await e.query(w(p, s("id", t), [], 1)))[0];
|
|
317
|
+
return r === void 0 || r.deadLetteredAt === null || r.deadLetteredAt === void 0 ? !1 : await e.update(p, t, {
|
|
318
|
+
attempts: 0,
|
|
319
|
+
lastError: null,
|
|
320
|
+
deadLetteredAt: null,
|
|
321
|
+
dueAt: new Date(n),
|
|
322
|
+
updatedAt: new Date(n)
|
|
323
|
+
}) !== null;
|
|
324
|
+
}, G = async (e) => {
|
|
325
|
+
let t = await O({
|
|
326
|
+
store: e.store,
|
|
327
|
+
control: e.control,
|
|
328
|
+
keys: e.keys,
|
|
329
|
+
now: e.now,
|
|
330
|
+
paused: e.paused
|
|
331
|
+
});
|
|
332
|
+
return i({
|
|
333
|
+
control: e.control,
|
|
334
|
+
keys: e.keys,
|
|
335
|
+
state: t,
|
|
336
|
+
now: e.now,
|
|
337
|
+
reconsidering: e.reconsidering
|
|
338
|
+
});
|
|
339
|
+
}, K = async (e, t, n = 1e3) => {
|
|
340
|
+
let r = await e.query(w(m, void 0, [{
|
|
341
|
+
column: "admittedAt",
|
|
342
|
+
direction: "asc"
|
|
343
|
+
}], n)), i = t.getTime(), a = r.filter((e) => e.releasedAt != null && x(e.admittedAt) < i);
|
|
344
|
+
return await Promise.all(a.map((t) => e.delete(m, String(t.id)))), a.length;
|
|
345
|
+
};
|
|
346
|
+
//#endregion
|
|
347
|
+
export { m as ADMISSIONS_TABLE, y as DEFAULT_LEASE_MS, h as PAUSES_TABLE, p as PENDING_TABLE, g as admissionLeaseHeldPredicate, L as allIntents, U as deadLetterIntent, v as decodePendingPayload, R as deleteIntent, z as discardIntent, B as discardIntentInTransaction, F as dueIntents, _ as encodePendingPayload, G as evaluateAdmission, H as noteIntentAttempt, j as parkDelayedStart, E as pauseWorkflow, b as pendingSlotId, I as pendingWindow, A as persistDefer, K as pruneAdmissions, O as readAdmissionState, T as readPausedWorkflows, N as recordAdmission, P as releaseLease, D as resumeWorkflow, V as retryBackoffMs, W as retryDeadLetterIntent, C as toPendingIntent };
|