@voltro/workflow 0.70.0 → 0.71.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1341 -111
- package/dist/cluster-BRSoL1tb.js +489 -0
- package/dist/cluster.d.ts +563 -6
- package/dist/cluster.js +2 -2
- package/dist/clusterDiagnostics-jpkNVay6.js +379 -0
- package/dist/clusterTestSuite.js +4 -4
- package/dist/index.d.ts +1036 -94
- package/dist/index.js +4 -4
- package/dist/{primitives-CqHxfASq.js → primitives-DsMsMr5S.js} +141 -122
- package/dist/primitives.js +2 -2
- package/dist/src-OEBqLBJl.js +4842 -0
- package/package.json +4 -4
- package/dist/cluster-CSycI4sz.js +0 -329
- package/dist/clusterDiagnostics-CNtl5LX9.js +0 -20
- package/dist/src-TRpoU54e.js +0 -2666
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/workflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.1",
|
|
4
4
|
"description": "Durable workflows for Voltro — the workflow() descriptor + step() / awaitSignal primitives over @effect/cluster, with a browser-safe define subpath.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"@effect/cluster": "^0.60.2",
|
|
52
52
|
"@effect/sql": "^0.52.1",
|
|
53
53
|
"@effect/workflow": "^0.19.1",
|
|
54
|
-
"@voltro/database": "0.
|
|
55
|
-
"@voltro/logger": "0.
|
|
56
|
-
"@voltro/protocol": "0.
|
|
54
|
+
"@voltro/database": "0.71.1",
|
|
55
|
+
"@voltro/logger": "0.71.1",
|
|
56
|
+
"@voltro/protocol": "0.71.1"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"effect": "^3.22.1",
|
package/dist/cluster-CSycI4sz.js
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
import { n as e, t } from "./clusterDiagnostics-CNtl5LX9.js";
|
|
2
|
-
import { Context as n, Duration as r, Effect as i, Layer as a, Option as o } from "effect";
|
|
3
|
-
import { ClusterCron as s, ClusterSchema as c, ClusterWorkflowEngine as l, EntityAddress as u, EntityId as d, EntityType as f, MessageStorage as p, RunnerAddress as m, ShardId as h, Sharding as g, ShardingConfig as _, SingleRunner as v, SqlMessageStorage as y, SqlRunnerStorage as b } from "@effect/cluster";
|
|
4
|
-
import { SqlClient as x } from "@effect/sql";
|
|
5
|
-
import { fnv1a64 as S, resolveMigrationLockSchema as C } from "@voltro/database/sql";
|
|
6
|
-
import { createLogger as ee } from "@voltro/logger";
|
|
7
|
-
//#region src/clusterMigrationGate.ts
|
|
8
|
-
var w = 6322741009312601n, T = () => {
|
|
9
|
-
let e = C();
|
|
10
|
-
return e === void 0 ? w : S(`voltro_cluster_migration_lock:${e}`) & 9223372036854775807n;
|
|
11
|
-
}, E = () => {
|
|
12
|
-
let e = `voltro_cluster_migration_${w.toString(36)}`, t = C();
|
|
13
|
-
if (t === void 0) return e;
|
|
14
|
-
let n = `${e}_${t}`;
|
|
15
|
-
return /^[A-Za-z0-9_]+$/.test(t) && n.length <= 64 ? n : `${e}_h${S(`voltro_cluster_migration_lock:${t}`).toString(16)}`;
|
|
16
|
-
}, D = () => {
|
|
17
|
-
let e = Number(process.env.VOLTRO_CLUSTER_MIGRATION_LOCK_TIMEOUT_MS);
|
|
18
|
-
return Number.isFinite(e) && e > 0 ? e : 6e4;
|
|
19
|
-
}, O = 250, k = (e) => e[0]?.[0], A = (e, t) => e.onDialectOrElse({
|
|
20
|
-
sqlite: () => i.void,
|
|
21
|
-
mysql: () => t.executeValues(`SELECT GET_LOCK('${E()}', ${Math.ceil(D() / 1e3)})`, []).pipe(i.flatMap((e) => k(e) === 1 || k(e) === "1" ? i.void : i.die(/* @__PURE__ */ Error(`could not acquire cluster migration lock '${E()}' (GET_LOCK timed out)`)))),
|
|
22
|
-
mssql: () => t.executeValues(`DECLARE @res int; EXEC @res = sp_getapplock @Resource = '${E()}', @LockMode = 'Exclusive', @LockOwner = 'Session', @LockTimeout = ${D()}; SELECT @res`, []).pipe(i.flatMap((e) => Number(k(e) ?? -999) >= 0 ? i.void : i.die(/* @__PURE__ */ Error(`could not acquire cluster migration lock '${E()}' (sp_getapplock ${String(k(e))})`)))),
|
|
23
|
-
orElse: () => {
|
|
24
|
-
let e = T().toString(), n = Date.now(), r = t.executeValues(`SELECT pg_try_advisory_lock(${e}::bigint)`, []).pipe(i.flatMap((e) => {
|
|
25
|
-
let t = k(e);
|
|
26
|
-
return t === !0 || t === "t" || t === 1 ? i.void : Date.now() - n >= D() ? i.die(/* @__PURE__ */ Error(`could not acquire the cluster migration advisory lock within ${Math.round(D() / 1e3)}s. Another runner is migrating the cluster schema, or a prior boot wedged while holding it. (Raise VOLTRO_CLUSTER_MIGRATION_LOCK_TIMEOUT_MS, or inspect pg_locks for the holder.)`)) : i.sleep(`${O} millis`).pipe(i.zipRight(r));
|
|
27
|
-
}));
|
|
28
|
-
return r;
|
|
29
|
-
}
|
|
30
|
-
}), j = (e, t) => e.onDialectOrElse({
|
|
31
|
-
sqlite: () => i.void,
|
|
32
|
-
mysql: () => i.asVoid(t.executeValues(`SELECT RELEASE_LOCK('${E()}')`, [])),
|
|
33
|
-
mssql: () => i.asVoid(t.executeValues(`EXEC sp_releaseapplock @Resource = '${E()}', @LockOwner = 'Session'`, [])),
|
|
34
|
-
orElse: () => i.asVoid(t.executeValues(`SELECT pg_advisory_unlock(${T().toString()}::bigint)`, []))
|
|
35
|
-
}), M = (e, t) => e.onDialectOrElse({
|
|
36
|
-
sqlite: () => !0,
|
|
37
|
-
orElse: () => !1
|
|
38
|
-
}) ? t : i.scoped(i.gen(function* () {
|
|
39
|
-
let n = yield* e.reserve;
|
|
40
|
-
return yield* i.acquireRelease(A(e, n), () => j(e, n).pipe(i.orDie)), yield* t;
|
|
41
|
-
})), N = (e) => e === "sql" ? ["cluster_messages", "cluster_runners"] : ["cluster_messages"], P = (e, t) => e.onDialectOrElse({
|
|
42
|
-
pg: () => e`SELECT (to_regclass(${t}) IS NOT NULL) AS present`,
|
|
43
|
-
mysql: () => e`SELECT (COUNT(*) > 0) AS present FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ${t}`,
|
|
44
|
-
mssql: () => e`SELECT CASE WHEN OBJECT_ID(${t}, 'U') IS NULL THEN 0 ELSE 1 END AS present`,
|
|
45
|
-
orElse: () => e`SELECT (COUNT(*) > 0) AS present FROM sqlite_master WHERE type = 'table' AND name = ${t}`
|
|
46
|
-
}).pipe(i.map((e) => {
|
|
47
|
-
let t = e[0]?.present;
|
|
48
|
-
return t === !0 || t === 1 || t === "1" || t === "t" || typeof t == "bigint" && t === 1n;
|
|
49
|
-
}), i.catchAll(() => i.succeed(!1))), te = (e, t) => i.forEach(N(t), (t) => P(e, t), { concurrency: 1 }).pipe(i.map((e) => e.every(Boolean))), F = (e, t) => i.scoped(i.asVoid(a.build(t.pipe(a.provide(_.layerDefaults), a.provide(a.succeed(x.SqlClient, e)))))), ne = (e, t) => F(e, y.layer).pipe(i.zipRight(t === "sql" ? F(e, b.layer) : i.void)), I = (e) => a.effect(x.SqlClient, i.gen(function* () {
|
|
50
|
-
let t = yield* x.SqlClient;
|
|
51
|
-
return (yield* te(t, e.runnerStorage)) || (yield* M(t, ne(t, e.runnerStorage))), t;
|
|
52
|
-
})), L = (e) => {
|
|
53
|
-
if (e instanceof Date) return Number.isNaN(e.getTime()) ? null : e;
|
|
54
|
-
if (typeof e == "string" || typeof e == "number") {
|
|
55
|
-
let t = typeof e == "string" && /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e) ? `${e.replace(" ", "T")}Z` : e, n = new Date(t);
|
|
56
|
-
return Number.isNaN(n.getTime()) ? null : n;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
}, R = (e) => e === !0 || e === 1 || e === "1" || e instanceof Uint8Array && e[0] === 1, z = (e, t) => {
|
|
60
|
-
let n = e.lastIndexOf(":");
|
|
61
|
-
if (n < 0) return;
|
|
62
|
-
let r = e.slice(0, n), i = Number(e.slice(n + 1)), a = t.indexOf(r);
|
|
63
|
-
if (!(a < 0 || !Number.isInteger(i))) return (a + 1) * 1e6 + i;
|
|
64
|
-
}, B = (e) => i.gen(function* () {
|
|
65
|
-
let n = yield* x.SqlClient, r = e.shardGroups ?? ["default"], a = e.dialectId ?? "", o = a.startsWith("postgres") || a === "pg", s = (e) => e.pipe(i.catchAll(() => i.succeed([]))), c = n.onDialectOrElse({
|
|
66
|
-
pg: () => n.literal("NOW()"),
|
|
67
|
-
mysql: () => n.literal("NOW()"),
|
|
68
|
-
mssql: () => n.literal("GETDATE()"),
|
|
69
|
-
orElse: () => n.literal("CURRENT_TIMESTAMP")
|
|
70
|
-
}), l = (e, t) => {
|
|
71
|
-
let n = L(e.last_read), r = L(e.server_now), i = n !== null && r !== null ? Math.max(0, r.getTime() - n.getTime()) : null;
|
|
72
|
-
return {
|
|
73
|
-
tag: typeof e.tag == "string" ? e.tag : null,
|
|
74
|
-
entityType: String(e.entity_type ?? ""),
|
|
75
|
-
entityId: String(e.entity_id ?? ""),
|
|
76
|
-
shardId: String(e.shard_id ?? ""),
|
|
77
|
-
processed: R(e.processed),
|
|
78
|
-
lastRead: i === null ? null : new Date(t - i)
|
|
79
|
-
};
|
|
80
|
-
}, u = (e) => n.onDialectOrElse({
|
|
81
|
-
pg: () => n.literal(`NOW() - INTERVAL '${e} seconds'`),
|
|
82
|
-
mysql: () => n.literal(`NOW() - INTERVAL ${e} SECOND`),
|
|
83
|
-
mssql: () => n.literal(`DATEADD(SECOND, -${e}, GETDATE())`),
|
|
84
|
-
orElse: () => n.literal(`DATETIME('now', '-${e} seconds')`)
|
|
85
|
-
}), d = n.onDialectOrElse({
|
|
86
|
-
pg: () => n.literal("FALSE"),
|
|
87
|
-
orElse: () => n.literal("0")
|
|
88
|
-
}), f = (e) => {
|
|
89
|
-
let t = Date.now();
|
|
90
|
-
return s(n`
|
|
91
|
-
SELECT tag, entity_type, entity_id, shard_id, processed, last_read, ${c} AS server_now
|
|
92
|
-
FROM cluster_messages
|
|
93
|
-
WHERE entity_id = ${e}
|
|
94
|
-
ORDER BY rowid ASC
|
|
95
|
-
`).pipe(i.map((e) => e.map((e) => l(e, t))));
|
|
96
|
-
}, p = (e = t) => {
|
|
97
|
-
let r = Math.max(1, Math.ceil(e / 1e3)), a = Date.now();
|
|
98
|
-
return s(n`
|
|
99
|
-
SELECT tag, entity_type, entity_id, shard_id, processed, last_read, ${c} AS server_now
|
|
100
|
-
FROM cluster_messages
|
|
101
|
-
WHERE processed = ${d}
|
|
102
|
-
AND last_read IS NOT NULL
|
|
103
|
-
AND last_read < ${u(r)}
|
|
104
|
-
AND (deliver_at IS NULL OR deliver_at <= ${a})
|
|
105
|
-
ORDER BY last_read ASC
|
|
106
|
-
`).pipe(i.map((e) => e.flatMap((e) => {
|
|
107
|
-
let t = l(e, a);
|
|
108
|
-
return t.lastRead === null ? [] : [{
|
|
109
|
-
...t,
|
|
110
|
-
unreadForMs: Math.max(0, a - t.lastRead.getTime())
|
|
111
|
-
}];
|
|
112
|
-
})));
|
|
113
|
-
}, m = (t) => s(n`
|
|
114
|
-
SELECT shard_id, address, acquired_at FROM cluster_locks WHERE ${n.in("shard_id", t)}
|
|
115
|
-
`).pipe(i.map((t) => t.map((t) => {
|
|
116
|
-
let n = t, r = String(n.address ?? ""), i = String(n.shard_id ?? "");
|
|
117
|
-
return {
|
|
118
|
-
shardId: i,
|
|
119
|
-
mode: "row",
|
|
120
|
-
holder: r,
|
|
121
|
-
own: r === e.ownAddress || (e.hasShard?.(i) ?? !1),
|
|
122
|
-
since: L(n.acquired_at)
|
|
123
|
-
};
|
|
124
|
-
}))), h = (t) => {
|
|
125
|
-
let a = /* @__PURE__ */ new Map();
|
|
126
|
-
for (let e of t) {
|
|
127
|
-
let t = z(e, r);
|
|
128
|
-
t !== void 0 && a.set(t, e);
|
|
129
|
-
}
|
|
130
|
-
return a.size === 0 ? i.succeed([]) : i.gen(function* () {
|
|
131
|
-
return (yield* s(n`
|
|
132
|
-
SELECT l.objid, a.pid, a.client_addr, a.application_name, a.state, a.state_change, a.backend_start, a.wait_event_type
|
|
133
|
-
FROM pg_locks l
|
|
134
|
-
JOIN pg_stat_activity a ON a.pid = l.pid
|
|
135
|
-
WHERE l.locktype = 'advisory' AND l.granted AND l.classid = 0 AND ${n.in("l.objid", [...a.keys()])}
|
|
136
|
-
`)).flatMap((t) => {
|
|
137
|
-
let n = t, r = a.get(Number(n.objid));
|
|
138
|
-
if (r === void 0) return [];
|
|
139
|
-
let i = Number(n.pid), o = n.client_addr === null || n.client_addr === void 0 ? "local socket" : String(n.client_addr), s = e.hasShard?.(r) ?? !1;
|
|
140
|
-
return [{
|
|
141
|
-
shardId: r,
|
|
142
|
-
mode: "advisory",
|
|
143
|
-
holder: s ? `this runner (pid ${i})` : `pid ${i} from ${o}`,
|
|
144
|
-
own: s,
|
|
145
|
-
since: L(n.state_change),
|
|
146
|
-
detail: {
|
|
147
|
-
pid: i,
|
|
148
|
-
clientAddr: n.client_addr ?? null,
|
|
149
|
-
applicationName: n.application_name ?? null,
|
|
150
|
-
state: n.state ?? null,
|
|
151
|
-
waitEventType: n.wait_event_type ?? null,
|
|
152
|
-
backendStart: L(n.backend_start)?.toISOString() ?? null
|
|
153
|
-
}
|
|
154
|
-
}];
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
return {
|
|
159
|
-
ownAddress: e.ownAddress,
|
|
160
|
-
shardLockMode: e.shardLockMode,
|
|
161
|
-
messagesFor: f,
|
|
162
|
-
unreadMessages: p,
|
|
163
|
-
shardLockHolders: (t) => t.length === 0 || e.runnerStorage !== "sql" ? i.succeed([]) : e.shardLockMode === "row" ? m(t) : e.shardLockMode === "advisory" && o ? h(t) : i.succeed([]),
|
|
164
|
-
runners: () => e.runnerStorage === "sql" ? s(n`SELECT address, last_heartbeat, healthy FROM cluster_runners ORDER BY last_heartbeat DESC`).pipe(i.map((e) => e.map((e) => {
|
|
165
|
-
let t = e;
|
|
166
|
-
return {
|
|
167
|
-
address: String(t.address ?? ""),
|
|
168
|
-
lastHeartbeat: L(t.last_heartbeat),
|
|
169
|
-
healthy: R(t.healthy)
|
|
170
|
-
};
|
|
171
|
-
}))) : i.succeed([]),
|
|
172
|
-
discardMessages: (e) => {
|
|
173
|
-
let t = e.unreadForMs === void 0 ? n.literal("") : n`AND last_read IS NOT NULL AND last_read < ${u(Math.max(1, Math.ceil(e.unreadForMs / 1e3)))}`;
|
|
174
|
-
return i.gen(function* () {
|
|
175
|
-
let r = (yield* n`
|
|
176
|
-
SELECT id FROM cluster_messages
|
|
177
|
-
WHERE entity_type = ${e.entityType} AND entity_id = ${e.entityId}
|
|
178
|
-
AND processed = ${d}
|
|
179
|
-
${t}
|
|
180
|
-
`).map((e) => e.id).filter((e) => e != null);
|
|
181
|
-
return r.length === 0 ? 0 : (yield* n`DELETE FROM cluster_replies WHERE ${n.in("request_id", r)}`, yield* n`DELETE FROM cluster_messages WHERE ${n.in("id", r)}`, r.length);
|
|
182
|
-
}).pipe(n.withTransaction, i.catchAll(() => i.succeed(0)));
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}), V = ee({ scope: "voltro:workflow" }), H = 34e3, U = (e) => {
|
|
186
|
-
let t = e.runnerListenHost ?? process.env.POD_IP ?? process.env.VOLTRO_WORKFLOW_RUNNER_HOST ?? "localhost";
|
|
187
|
-
return {
|
|
188
|
-
host: t,
|
|
189
|
-
port: e.runnerListenPort ?? 34e3,
|
|
190
|
-
localhostRisk: e.runnerStorage === "sql" && (t === "localhost" || t === "127.0.0.1")
|
|
191
|
-
};
|
|
192
|
-
}, W = (e) => {
|
|
193
|
-
let t = e.sqliteFamily ? "memory" : "sql", n = e.override ?? process.env.VOLTRO_WORKFLOW_RUNNER_STORAGE;
|
|
194
|
-
if (n === void 0 || n.trim() === "") return t;
|
|
195
|
-
let r = n.trim().toLowerCase();
|
|
196
|
-
if (r !== "memory" && r !== "sql") throw Error(`VOLTRO_WORKFLOW_RUNNER_STORAGE must be 'memory' or 'sql', got '${n}'.`);
|
|
197
|
-
if (r === "sql" && e.sqliteFamily) throw Error("VOLTRO_WORKFLOW_RUNNER_STORAGE='sql' is unsupported on sqlite / turso — @effect/cluster has no sqlite advisory-lock branch. Use 'memory'.");
|
|
198
|
-
return r;
|
|
199
|
-
}, G = (e = process.env.VOLTRO_WORKFLOW_SHARD_LOCK) => {
|
|
200
|
-
if (e === void 0 || e.trim() === "") return "auto";
|
|
201
|
-
let t = e.trim().toLowerCase();
|
|
202
|
-
if (t === "auto" || t === "row" || t === "advisory") return t;
|
|
203
|
-
throw Error(`VOLTRO_WORKFLOW_SHARD_LOCK must be 'auto', 'row', or 'advisory', got '${e}'.`);
|
|
204
|
-
}, K = i.gen(function* () {
|
|
205
|
-
let e = yield* (yield* x.SqlClient)`SELECT @@wsrep_on AS wsrep`.pipe(i.catchAll(() => i.succeed([])));
|
|
206
|
-
if (e.length === 0) return !1;
|
|
207
|
-
let t = e[0].wsrep;
|
|
208
|
-
return t === 1 || t === "1" || t === !0 || t === "ON" || t === "on";
|
|
209
|
-
}), q = (e) => i.gen(function* () {
|
|
210
|
-
return e.runnerStorage === "memory" ? !1 : e.mode === "row" ? !0 : e.mode === "advisory" || e.dialectId !== "mysql" && e.dialectId !== "mariadb" ? !1 : yield* K;
|
|
211
|
-
}), J = (e) => ({
|
|
212
|
-
coordination: e.disableAdvisory ? "row-based" : "advisory",
|
|
213
|
-
dialect: e.dialectId ?? "unknown",
|
|
214
|
-
mode: e.mode,
|
|
215
|
-
...e.disableAdvisory && e.mode === "auto" ? { reason: "wsrep/Galera cluster detected" } : {}
|
|
216
|
-
}), Y = () => {
|
|
217
|
-
let e = (e) => {
|
|
218
|
-
if (e === void 0) return;
|
|
219
|
-
let t = Number(e);
|
|
220
|
-
return Number.isFinite(t) && t > 0 ? t : void 0;
|
|
221
|
-
}, t = e(process.env.VOLTRO_WORKFLOW_FAILOVER_LEASE), n = e(process.env.VOLTRO_WORKFLOW_FAILOVER_HEARTBEAT), r = e(process.env.VOLTRO_WORKFLOW_POLL_INTERVAL);
|
|
222
|
-
return {
|
|
223
|
-
...t === void 0 ? {} : { failoverLeaseSeconds: t },
|
|
224
|
-
...n === void 0 ? {} : { failoverHeartbeatSeconds: n },
|
|
225
|
-
...r === void 0 ? {} : { messagePollSeconds: r }
|
|
226
|
-
};
|
|
227
|
-
}, X = i.flatMap(g.Sharding, (e) => e.pollStorage), Z = /* @__PURE__ */ new Set(), re = (t) => {
|
|
228
|
-
let n = U({
|
|
229
|
-
runnerStorage: t.runnerStorage,
|
|
230
|
-
runnerListenHost: t.runnerListenHost,
|
|
231
|
-
runnerListenPort: t.runnerListenPort
|
|
232
|
-
}), s = n.host, c = n.port;
|
|
233
|
-
n.localhostRisk && !Z.has(s) && (Z.add(s), V.warn("runner host is not routable from other pods with SQL cluster storage — a workflow cannot resume on another pod after a reschedule. Inject POD_IP via the K8s downward API (fieldRef: status.podIP) or set runnerListenHost / VOLTRO_WORKFLOW_RUNNER_HOST.", { runnerHost: s }));
|
|
234
|
-
let u = I({ runnerStorage: t.runnerStorage }).pipe(a.provide(t.sqlClientLayer)), d = t.shardLockMode ?? G(), f = a.unwrapEffect(q({
|
|
235
|
-
dialectId: t.dialectId,
|
|
236
|
-
runnerStorage: t.runnerStorage,
|
|
237
|
-
mode: d
|
|
238
|
-
}).pipe(i.map((n) => {
|
|
239
|
-
t.runnerStorage === "sql" && V.info("shard-lock coordination", J({
|
|
240
|
-
disableAdvisory: n,
|
|
241
|
-
dialectId: t.dialectId,
|
|
242
|
-
mode: d
|
|
243
|
-
}));
|
|
244
|
-
let l = a.effect(e, i.flatMap(g.Sharding, (e) => B({
|
|
245
|
-
ownAddress: m.make(s, c).toString(),
|
|
246
|
-
shardLockMode: t.runnerStorage === "sql" ? n ? "row" : "advisory" : "none",
|
|
247
|
-
runnerStorage: t.runnerStorage,
|
|
248
|
-
dialectId: t.dialectId,
|
|
249
|
-
hasShard: (t) => e.hasShardId(h.ShardId.fromString(t))
|
|
250
|
-
}))), u = v.layer({
|
|
251
|
-
runnerStorage: t.runnerStorage,
|
|
252
|
-
shardingConfig: {
|
|
253
|
-
runnerAddress: o.some(m.make(s, c)),
|
|
254
|
-
runnerListenAddress: o.some(m.make(s, c)),
|
|
255
|
-
...n ? { shardLockDisableAdvisory: !0 } : {},
|
|
256
|
-
...t.failoverLeaseSeconds === void 0 ? {} : { shardLockExpiration: r.seconds(t.failoverLeaseSeconds) },
|
|
257
|
-
...t.failoverHeartbeatSeconds === void 0 ? {} : { shardLockRefreshInterval: r.seconds(t.failoverHeartbeatSeconds) },
|
|
258
|
-
...t.messagePollSeconds === void 0 ? {} : { entityMessagePollInterval: r.seconds(t.messagePollSeconds) }
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
return l.pipe(a.provideMerge(u));
|
|
262
|
-
}))).pipe(a.provide(u)), p = t.extraShardingLayers ?? [];
|
|
263
|
-
return (p.length === 0 ? l.layer : a.mergeAll(l.layer, ...p)).pipe(a.provideMerge(f));
|
|
264
|
-
}, ie = (e) => s.make({
|
|
265
|
-
name: e.name,
|
|
266
|
-
cron: e.cron,
|
|
267
|
-
execute: i.promise(() => e.execute()),
|
|
268
|
-
skipIfOlderThan: e.skipIfOlderThan ?? r.days(1)
|
|
269
|
-
}), Q = (e, t) => `${e}/${t}`, ae = (e, t, r) => {
|
|
270
|
-
let i = d.make(t), a = n.get(e.annotations, c.ShardGroup)(i);
|
|
271
|
-
return new u.EntityAddress({
|
|
272
|
-
entityType: f.EntityType.make(`Workflow/${e.name}`),
|
|
273
|
-
entityId: i,
|
|
274
|
-
shardId: r.getShardId(i, a)
|
|
275
|
-
});
|
|
276
|
-
}, oe = (e) => {
|
|
277
|
-
let t = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : void 0, n = t(e);
|
|
278
|
-
if (n === "Failure" || n !== "Success") return "failed";
|
|
279
|
-
let r = e.value, i = t(r);
|
|
280
|
-
if (i === "Suspended") return "suspended";
|
|
281
|
-
if (i === "Complete") {
|
|
282
|
-
let e = r.exit;
|
|
283
|
-
return t(e) === "Success" ? "succeeded" : "failed";
|
|
284
|
-
}
|
|
285
|
-
return "failed";
|
|
286
|
-
}, se = (e) => $(e.workflow, e.executionId, e.failedActivities), ce = (e) => $(e.workflow, e.executionId, e.resetActivities), $ = (e, t, n) => i.gen(function* () {
|
|
287
|
-
let r = yield* g.Sharding, a = yield* p.MessageStorage, s = ae(e, t, r), c = yield* a.requestIdForPrimaryKey({
|
|
288
|
-
address: s,
|
|
289
|
-
tag: "run",
|
|
290
|
-
id: ""
|
|
291
|
-
}).pipe(i.orElseSucceed(() => o.none()));
|
|
292
|
-
if (o.isNone(c)) return {
|
|
293
|
-
redriven: !1,
|
|
294
|
-
runReplyCleared: !1,
|
|
295
|
-
activitiesReset: 0,
|
|
296
|
-
reason: "no-journal"
|
|
297
|
-
};
|
|
298
|
-
let l = (yield* a.repliesForUnfiltered([c.value]).pipe(i.orElseSucceed(() => []))).filter((e) => e._tag === "WithExit").at(-1);
|
|
299
|
-
if (l === void 0) return {
|
|
300
|
-
redriven: !1,
|
|
301
|
-
runReplyCleared: !1,
|
|
302
|
-
activitiesReset: 0,
|
|
303
|
-
reason: "no-reply"
|
|
304
|
-
};
|
|
305
|
-
if (oe(l.exit) === "succeeded") return {
|
|
306
|
-
redriven: !1,
|
|
307
|
-
runReplyCleared: !1,
|
|
308
|
-
activitiesReset: 0,
|
|
309
|
-
reason: "succeeded"
|
|
310
|
-
};
|
|
311
|
-
let u = 0;
|
|
312
|
-
for (let e of n) {
|
|
313
|
-
let t = yield* a.requestIdForPrimaryKey({
|
|
314
|
-
address: s,
|
|
315
|
-
tag: "activity",
|
|
316
|
-
id: Q(e.name, e.attempt)
|
|
317
|
-
}).pipe(i.orElseSucceed(() => o.none()));
|
|
318
|
-
o.isSome(t) && (yield* r.reset(t.value)) && (u += 1);
|
|
319
|
-
}
|
|
320
|
-
let d = yield* r.reset(c.value);
|
|
321
|
-
return yield* r.pollStorage, {
|
|
322
|
-
redriven: !0,
|
|
323
|
-
runReplyCleared: d,
|
|
324
|
-
activitiesReset: u,
|
|
325
|
-
reason: null
|
|
326
|
-
};
|
|
327
|
-
});
|
|
328
|
-
//#endregion
|
|
329
|
-
export { H as a, X as c, W as d, q as f, ie as i, Y as l, B as m, se as n, K as o, re as p, ce as r, G as s, Q as t, U as u };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Context as e, Effect as t } from "effect";
|
|
2
|
-
//#region src/clusterDiagnostics.ts
|
|
3
|
-
var n = 6e5, r = class extends e.Tag("@voltro/workflow/ClusterDiagnostics")() {}, i = (e, n, r = Date.now()) => t.flatMap(e.messagesFor(n), (n) => {
|
|
4
|
-
if (n.length === 0) return t.succeed(void 0);
|
|
5
|
-
let i = [...new Set(n.filter((e) => !e.processed).map((e) => e.shardId))], a = i.length === 0 ? t.succeed([]) : e.shardLockHolders(i);
|
|
6
|
-
return t.map(a, (t) => ({
|
|
7
|
-
runner: e.ownAddress,
|
|
8
|
-
shardLockMode: e.shardLockMode,
|
|
9
|
-
messages: n.map((e) => ({
|
|
10
|
-
tag: e.tag,
|
|
11
|
-
shardId: e.shardId,
|
|
12
|
-
processed: e.processed,
|
|
13
|
-
lastRead: e.lastRead === null ? null : e.lastRead.toISOString(),
|
|
14
|
-
unreadForMs: !e.processed && e.lastRead !== null ? Math.max(0, r - e.lastRead.getTime()) : null
|
|
15
|
-
})),
|
|
16
|
-
shardLocks: t
|
|
17
|
-
}));
|
|
18
|
-
});
|
|
19
|
-
//#endregion
|
|
20
|
-
export { r as n, i as r, n as t };
|