@tenetkit/pg 0.32.0 → 0.33.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/dist/postgres/claims.js +6 -6
- package/dist/postgres/locks.js +3 -3
- package/dist/postgres/pg-helpers.js +31 -31
- package/dist/postgres/run-schema.js +13 -37
- package/dist/postgres/schema.d.ts +6 -7
- package/dist/postgres/schema.js +64 -66
- package/dist/postgres/session-storage.js +6 -6
- package/dist/postgres/session-store.js +14 -14
- package/dist/postgres/store-admit.js +2 -2
- package/dist/postgres/store-cancel.js +6 -6
- package/dist/postgres/store-fan-out.js +3 -3
- package/dist/postgres/store-model-response.js +9 -9
- package/dist/postgres/store-ops.js +29 -29
- package/dist/postgres/store-program.js +1 -1
- package/dist/postgres/store-suspend.js +5 -5
- package/dist/postgres/store.js +15 -15
- package/package.json +2 -2
|
@@ -17,7 +17,7 @@ import { handoffSessionEntry, isHandoffCommit, sameHandoffCheckpoint, sameHandof
|
|
|
17
17
|
import { lockRunHierarchy } from "./locks.js";
|
|
18
18
|
export const postgresOperations = (input) => {
|
|
19
19
|
const { sql, hub, run, runNoTxn, requireRun, requireClaim, nextId } = input;
|
|
20
|
-
const fenced = (claim, effect) => run(sql `SELECT run_id FROM
|
|
20
|
+
const fenced = (claim, effect) => run(sql `SELECT run_id FROM tenetkit_runs WHERE run_id = ${claim.runId} FOR UPDATE`.pipe(Effect.andThen(requireClaim(claim)), Effect.andThen(effect)));
|
|
21
21
|
return {
|
|
22
22
|
recordOperation: (op) => fenced(op, Effect.gen(function* () {
|
|
23
23
|
const loaded = yield* requireRun(op.runId);
|
|
@@ -25,13 +25,13 @@ export const postgresOperations = (input) => {
|
|
|
25
25
|
return yield* RunTerminal.make({ runId: loaded.runId, status: loaded.status });
|
|
26
26
|
}
|
|
27
27
|
const existing = yield* sql `
|
|
28
|
-
SELECT * FROM
|
|
28
|
+
SELECT * FROM tenetkit_run_operations
|
|
29
29
|
WHERE run_id = ${op.runId} AND operation_key = ${op.operationKey}
|
|
30
30
|
`;
|
|
31
31
|
const prior = existing[0];
|
|
32
32
|
if (prior !== undefined) {
|
|
33
33
|
const consumed = yield* sql `
|
|
34
|
-
SELECT entry_id FROM
|
|
34
|
+
SELECT entry_id FROM tenetkit_run_steering
|
|
35
35
|
WHERE run_id = ${op.runId} AND consumed_operation_id = ${prior.operation_id}
|
|
36
36
|
ORDER BY sequence
|
|
37
37
|
`;
|
|
@@ -44,7 +44,7 @@ export const postgresOperations = (input) => {
|
|
|
44
44
|
}
|
|
45
45
|
const steeringEntryIds = op.steeringEntryIds ?? [];
|
|
46
46
|
const pending = yield* sql `
|
|
47
|
-
SELECT entry_id FROM
|
|
47
|
+
SELECT entry_id FROM tenetkit_run_steering
|
|
48
48
|
WHERE run_id = ${op.runId} AND consumed_operation_id IS NULL AND discarded_reason IS NULL
|
|
49
49
|
ORDER BY sequence
|
|
50
50
|
`;
|
|
@@ -59,7 +59,7 @@ export const postgresOperations = (input) => {
|
|
|
59
59
|
catch: (error) => RuntimeUnavailable.make({ message: String(error) }),
|
|
60
60
|
});
|
|
61
61
|
yield* sql `
|
|
62
|
-
INSERT INTO
|
|
62
|
+
INSERT INTO tenetkit_run_operations (
|
|
63
63
|
run_id, operation_id, operation_key, kind, status, input_digest, input_json,
|
|
64
64
|
result_json, error_json, replay_policy, attempt, owner_worker_id, lease_expires_at, started_at, finished_at
|
|
65
65
|
) VALUES (
|
|
@@ -70,7 +70,7 @@ export const postgresOperations = (input) => {
|
|
|
70
70
|
`;
|
|
71
71
|
if (op.checkpoint !== undefined || op.continuation !== undefined) {
|
|
72
72
|
yield* sql `
|
|
73
|
-
UPDATE
|
|
73
|
+
UPDATE tenetkit_runs SET
|
|
74
74
|
driver_checkpoint_json = COALESCE(${op.checkpoint === undefined ? null : encodeJson(ExecutionCheckpoint, op.checkpoint)}, driver_checkpoint_json),
|
|
75
75
|
executable_ref_json = ${encodeExecutableRef(executableRef)},
|
|
76
76
|
continuation_json = CASE WHEN ${op.continuation === undefined ? 0 : 1} = 1
|
|
@@ -81,7 +81,7 @@ export const postgresOperations = (input) => {
|
|
|
81
81
|
}
|
|
82
82
|
for (const entryId of steeringEntryIds) {
|
|
83
83
|
yield* sql `
|
|
84
|
-
UPDATE
|
|
84
|
+
UPDATE tenetkit_run_steering SET consumed_operation_id = ${operationId}
|
|
85
85
|
WHERE run_id = ${op.runId} AND entry_id = ${entryId}
|
|
86
86
|
AND consumed_operation_id IS NULL AND discarded_reason IS NULL
|
|
87
87
|
`;
|
|
@@ -97,19 +97,19 @@ export const postgresOperations = (input) => {
|
|
|
97
97
|
yield* appendEvent(hub, yield* requireRun(op.runId), event);
|
|
98
98
|
}
|
|
99
99
|
const rows = yield* sql `
|
|
100
|
-
SELECT * FROM
|
|
100
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${operationId}
|
|
101
101
|
`;
|
|
102
102
|
return toOperationRecord(rows[0]);
|
|
103
103
|
})),
|
|
104
104
|
startOperation: (op) => fenced(op, Effect.gen(function* () {
|
|
105
105
|
yield* requireRun(op.runId);
|
|
106
106
|
yield* sql `
|
|
107
|
-
UPDATE
|
|
107
|
+
UPDATE tenetkit_run_operations
|
|
108
108
|
SET status = 'running', started_at = NOW()
|
|
109
109
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'requested'
|
|
110
110
|
`;
|
|
111
111
|
const rows = yield* sql `
|
|
112
|
-
SELECT * FROM
|
|
112
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
113
113
|
`;
|
|
114
114
|
const row = rows[0];
|
|
115
115
|
if (row === undefined)
|
|
@@ -119,7 +119,7 @@ export const postgresOperations = (input) => {
|
|
|
119
119
|
completeOperation: (op) => fenced(op, Effect.gen(function* () {
|
|
120
120
|
const loaded = yield* requireRun(op.runId);
|
|
121
121
|
const existing = yield* sql `
|
|
122
|
-
SELECT * FROM
|
|
122
|
+
SELECT * FROM tenetkit_run_operations
|
|
123
123
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
124
124
|
FOR UPDATE
|
|
125
125
|
`;
|
|
@@ -147,7 +147,7 @@ export const postgresOperations = (input) => {
|
|
|
147
147
|
}
|
|
148
148
|
for (const entryId of new Set(op.steeringEntryIds ?? [])) {
|
|
149
149
|
const rows = yield* sql `
|
|
150
|
-
SELECT consumed_operation_id FROM
|
|
150
|
+
SELECT consumed_operation_id FROM tenetkit_run_steering
|
|
151
151
|
WHERE run_id = ${op.runId} AND entry_id = ${entryId}
|
|
152
152
|
`;
|
|
153
153
|
if (rows[0]?.consumed_operation_id !== op.operationId) {
|
|
@@ -172,7 +172,7 @@ export const postgresOperations = (input) => {
|
|
|
172
172
|
}
|
|
173
173
|
if (op.outcome._tag === "Succeeded") {
|
|
174
174
|
yield* sql `
|
|
175
|
-
UPDATE
|
|
175
|
+
UPDATE tenetkit_run_operations
|
|
176
176
|
SET status = 'succeeded', result_json = ${encodeJsonValue(op.outcome.value)}, finished_at = NOW()
|
|
177
177
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
178
178
|
AND status IN ('requested', 'running')
|
|
@@ -180,7 +180,7 @@ export const postgresOperations = (input) => {
|
|
|
180
180
|
}
|
|
181
181
|
else if (op.outcome._tag === "Failed") {
|
|
182
182
|
yield* sql `
|
|
183
|
-
UPDATE
|
|
183
|
+
UPDATE tenetkit_run_operations
|
|
184
184
|
SET status = 'failed', error_json = ${encodeJsonValue(op.outcome.error)}, finished_at = NOW()
|
|
185
185
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
186
186
|
AND status IN ('requested', 'running')
|
|
@@ -188,13 +188,13 @@ export const postgresOperations = (input) => {
|
|
|
188
188
|
}
|
|
189
189
|
else {
|
|
190
190
|
yield* sql `
|
|
191
|
-
UPDATE
|
|
191
|
+
UPDATE tenetkit_run_operations SET status = 'unknown', finished_at = NOW()
|
|
192
192
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
193
193
|
AND status IN ('requested', 'running')
|
|
194
194
|
`;
|
|
195
195
|
}
|
|
196
196
|
yield* sql `
|
|
197
|
-
UPDATE
|
|
197
|
+
UPDATE tenetkit_runs SET
|
|
198
198
|
driver_checkpoint_json = COALESCE(${op.checkpoint === undefined ? null : encodeJson(ExecutionCheckpoint, op.checkpoint)}, driver_checkpoint_json),
|
|
199
199
|
executable_ref_json = ${encodeExecutableRef(executableRef)},
|
|
200
200
|
continuation_json = CASE WHEN ${op.continuation === undefined ? 0 : 1} = 1
|
|
@@ -207,7 +207,7 @@ export const postgresOperations = (input) => {
|
|
|
207
207
|
yield* appendEvent(hub, yield* requireRun(op.runId), { _tag: "OperationUnknown", operationId: op.operationId }, loaded.cancellationRequested ? "cancelling" : "needs-resolution");
|
|
208
208
|
}
|
|
209
209
|
const rows = yield* sql `
|
|
210
|
-
SELECT * FROM
|
|
210
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
211
211
|
`;
|
|
212
212
|
return toOperationRecord(rows[0]);
|
|
213
213
|
})),
|
|
@@ -215,7 +215,7 @@ export const postgresOperations = (input) => {
|
|
|
215
215
|
expireRunningOperation: (op) => fenced(op, Effect.gen(function* () {
|
|
216
216
|
const loaded = yield* requireRun(op.runId);
|
|
217
217
|
const rows = yield* sql `
|
|
218
|
-
SELECT * FROM
|
|
218
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
219
219
|
`;
|
|
220
220
|
const row = rows[0];
|
|
221
221
|
if (row === undefined)
|
|
@@ -225,29 +225,29 @@ export const postgresOperations = (input) => {
|
|
|
225
225
|
}
|
|
226
226
|
if (canBlindRetry(row.replay_policy)) {
|
|
227
227
|
yield* sql `
|
|
228
|
-
UPDATE
|
|
228
|
+
UPDATE tenetkit_run_operations
|
|
229
229
|
SET status = 'requested', started_at = NULL, finished_at = NULL, owner_worker_id = NULL, lease_expires_at = NULL
|
|
230
230
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'running'
|
|
231
231
|
`;
|
|
232
232
|
const next = yield* sql `
|
|
233
|
-
SELECT * FROM
|
|
233
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
234
234
|
`;
|
|
235
235
|
return { record: toOperationRecord(next[0]), outcome: "retried" };
|
|
236
236
|
}
|
|
237
237
|
yield* sql `
|
|
238
|
-
UPDATE
|
|
238
|
+
UPDATE tenetkit_run_operations SET status = 'unknown', finished_at = NOW()
|
|
239
239
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'running'
|
|
240
240
|
`;
|
|
241
241
|
yield* appendEvent(hub, loaded, { _tag: "OperationUnknown", operationId: op.operationId }, loaded.cancellationRequested ? "cancelling" : "needs-resolution");
|
|
242
242
|
const next = yield* sql `
|
|
243
|
-
SELECT * FROM
|
|
243
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
244
244
|
`;
|
|
245
245
|
return { record: toOperationRecord(next[0]), outcome: "unknown" };
|
|
246
246
|
})),
|
|
247
247
|
getOperation: (op) => runNoTxn(Effect.gen(function* () {
|
|
248
248
|
yield* requireRun(op.runId);
|
|
249
249
|
const rows = yield* sql `
|
|
250
|
-
SELECT * FROM
|
|
250
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
251
251
|
`;
|
|
252
252
|
const row = rows[0];
|
|
253
253
|
if (row === undefined)
|
|
@@ -257,7 +257,7 @@ export const postgresOperations = (input) => {
|
|
|
257
257
|
getOperationByKey: (op) => runNoTxn(Effect.gen(function* () {
|
|
258
258
|
yield* requireRun(op.runId);
|
|
259
259
|
const rows = yield* sql `
|
|
260
|
-
SELECT * FROM
|
|
260
|
+
SELECT * FROM tenetkit_run_operations WHERE run_id = ${op.runId} AND operation_key = ${op.operationKey}
|
|
261
261
|
`;
|
|
262
262
|
return rows[0] === undefined ? undefined : toOperationRecord(rows[0]);
|
|
263
263
|
})),
|
|
@@ -271,7 +271,7 @@ export const postgresOperations = (input) => {
|
|
|
271
271
|
return;
|
|
272
272
|
}
|
|
273
273
|
const rows = yield* sql `
|
|
274
|
-
SELECT * FROM
|
|
274
|
+
SELECT * FROM tenetkit_run_operations
|
|
275
275
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId}
|
|
276
276
|
FOR UPDATE
|
|
277
277
|
`;
|
|
@@ -296,7 +296,7 @@ export const postgresOperations = (input) => {
|
|
|
296
296
|
return yield* conflict();
|
|
297
297
|
if (op.resolution._tag === "Succeeded") {
|
|
298
298
|
yield* sql `
|
|
299
|
-
UPDATE
|
|
299
|
+
UPDATE tenetkit_run_operations SET status = 'succeeded', result_json = ${encodeJsonValue(op.resolution.value)},
|
|
300
300
|
resolution_idempotency_key = ${op.idempotencyKey}, resolution_json = ${resolutionJson},
|
|
301
301
|
owner_worker_id = NULL, lease_expires_at = NULL, finished_at = NOW()
|
|
302
302
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'unknown'
|
|
@@ -304,7 +304,7 @@ export const postgresOperations = (input) => {
|
|
|
304
304
|
}
|
|
305
305
|
else if (op.resolution._tag === "Failed") {
|
|
306
306
|
yield* sql `
|
|
307
|
-
UPDATE
|
|
307
|
+
UPDATE tenetkit_run_operations SET status = 'failed', error_json = ${encodeJsonValue(op.resolution.error)},
|
|
308
308
|
resolution_idempotency_key = ${op.idempotencyKey}, resolution_json = ${resolutionJson},
|
|
309
309
|
owner_worker_id = NULL, lease_expires_at = NULL, finished_at = NOW()
|
|
310
310
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'unknown'
|
|
@@ -312,14 +312,14 @@ export const postgresOperations = (input) => {
|
|
|
312
312
|
}
|
|
313
313
|
else {
|
|
314
314
|
yield* sql `
|
|
315
|
-
UPDATE
|
|
315
|
+
UPDATE tenetkit_run_operations SET status = 'requested', result_json = NULL, error_json = NULL,
|
|
316
316
|
resolution_idempotency_key = ${op.idempotencyKey}, resolution_json = ${resolutionJson},
|
|
317
317
|
owner_worker_id = NULL, lease_expires_at = NULL, started_at = NULL, finished_at = NULL
|
|
318
318
|
WHERE run_id = ${op.runId} AND operation_id = ${op.operationId} AND status = 'unknown'
|
|
319
319
|
`;
|
|
320
320
|
}
|
|
321
321
|
yield* sql `
|
|
322
|
-
UPDATE
|
|
322
|
+
UPDATE tenetkit_runs SET status = CASE WHEN cancellation_requested THEN 'cancelling' ELSE 'queued' END, owner_worker_id = NULL, lease_expires_at = NULL, updated_at = NOW()
|
|
323
323
|
WHERE run_id = ${op.runId} AND status = 'needs-resolution'
|
|
324
324
|
`;
|
|
325
325
|
yield* settleAdmittedCancellation(hub, op.runId);
|
|
@@ -8,7 +8,7 @@ import { completeRun, requireRun } from "./pg-helpers.js";
|
|
|
8
8
|
import { suspend } from "./store-suspend.js";
|
|
9
9
|
import { admitProgramChild } from "tenetkit/runtime/driver/sql/store-admit";
|
|
10
10
|
export const programStoreMethods = (input) => {
|
|
11
|
-
const fenced = (claim, effect) => input.run(input.sql `SELECT run_id FROM
|
|
11
|
+
const fenced = (claim, effect) => input.run(input.sql `SELECT run_id FROM tenetkit_runs WHERE run_id = ${claim.runId} FOR UPDATE`.pipe(Effect.andThen(requireExecutionClaim(claim)), Effect.andThen(effect)));
|
|
12
12
|
return {
|
|
13
13
|
admitProgramChild: (operation) => fenced(operation, admitProgramChild(input.hub, operation)),
|
|
14
14
|
admitProgramChildAndSuspend: (operation) => fenced(operation, admitProgramChild(input.hub, operation).pipe(Effect.tap(() => suspend(input.hub, operation)))),
|
|
@@ -29,7 +29,7 @@ export const suspend = Function.dual(2, (hub, input) => Effect.gen(function* ()
|
|
|
29
29
|
catch: (error) => RuntimeUnavailable.make({ message: String(error) }),
|
|
30
30
|
});
|
|
31
31
|
yield* sql `
|
|
32
|
-
UPDATE
|
|
32
|
+
UPDATE tenetkit_runs SET
|
|
33
33
|
driver_checkpoint_json = COALESCE(${input.checkpoint === undefined ? null : encodeJson(ExecutionCheckpoint, input.checkpoint)}, driver_checkpoint_json),
|
|
34
34
|
executable_ref_json = ${encodeExecutableRef(executableRef)},
|
|
35
35
|
suspension_json = ${encodeJson(ExecutionSuspension, input.suspension)},
|
|
@@ -40,7 +40,7 @@ export const suspend = Function.dual(2, (hub, input) => Effect.gen(function* ()
|
|
|
40
40
|
WHERE run_id = ${input.runId}
|
|
41
41
|
`;
|
|
42
42
|
yield* sql `
|
|
43
|
-
INSERT INTO
|
|
43
|
+
INSERT INTO tenetkit_run_waits (
|
|
44
44
|
run_id, wait_id, reason, status, response_json, due_at, owner_worker_id, lease_expires_at, opened_at, closed_at
|
|
45
45
|
) VALUES (
|
|
46
46
|
${loaded.runId}, ${input.wait.waitId}, ${encodeReason(input.wait.reason)}, 'open', NULL, NULL, NULL, NULL, NOW(), NULL
|
|
@@ -67,7 +67,7 @@ export const suspend = Function.dual(2, (hub, input) => Effect.gen(function* ()
|
|
|
67
67
|
const groupId = groupIdFromSuspension(input.suspension);
|
|
68
68
|
if (groupId !== undefined) {
|
|
69
69
|
const rows = yield* sql `
|
|
70
|
-
SELECT parent_run_id, status FROM
|
|
70
|
+
SELECT parent_run_id, status FROM tenetkit_fan_outs WHERE fan_out_id = ${groupId}
|
|
71
71
|
`;
|
|
72
72
|
const group = rows[0];
|
|
73
73
|
if (group?.parent_run_id === loaded.runId && group.status !== "running") {
|
|
@@ -77,11 +77,11 @@ export const suspend = Function.dual(2, (hub, input) => Effect.gen(function* ()
|
|
|
77
77
|
payload: resultFromInspection(yield* inspectFanOut(groupId).pipe(Effect.mapError(() => RuntimeUnavailable.make({ message: `child group ${groupId} disappeared` })))),
|
|
78
78
|
};
|
|
79
79
|
yield* sql `
|
|
80
|
-
UPDATE
|
|
80
|
+
UPDATE tenetkit_run_waits SET status = 'signaled', response_json = ${encodeJson(WaitResolution, resolution)}, closed_at = NOW()
|
|
81
81
|
WHERE run_id = ${loaded.runId} AND wait_id = ${input.wait.waitId} AND status = 'open'
|
|
82
82
|
`;
|
|
83
83
|
yield* appendEvent(hub, yield* requireRun(loaded.runId), { _tag: "RunResumed", waitId: input.wait.waitId, resolution }, "running");
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
yield* sql `UPDATE
|
|
86
|
+
yield* sql `UPDATE tenetkit_runs SET owner_worker_id = NULL, lease_expires_at = NULL WHERE run_id = ${loaded.runId}`;
|
|
87
87
|
}));
|
package/dist/postgres/store.js
CHANGED
|
@@ -90,7 +90,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
90
90
|
});
|
|
91
91
|
const registrations = yield* narrow(executable, yield* loadRegistrations(parent.runId)).pipe(Effect.mapError((error) => RuntimeUnavailable.make({ message: String(error) })));
|
|
92
92
|
const existing = yield* sql `
|
|
93
|
-
SELECT * FROM
|
|
93
|
+
SELECT * FROM tenetkit_runs
|
|
94
94
|
WHERE address = ${input.message.to}
|
|
95
95
|
AND session_id = ${input.message.sessionId}
|
|
96
96
|
AND idempotency_key = ${input.message.idempotencyKey}
|
|
@@ -132,7 +132,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
132
132
|
});
|
|
133
133
|
yield* associateRegistrations(runId, registrations);
|
|
134
134
|
yield* sql `
|
|
135
|
-
INSERT INTO
|
|
135
|
+
INSERT INTO tenetkit_run_links (parent_run_id, child_run_id, invocation_id, readiness, terminal_event_id, created_at, settled_at)
|
|
136
136
|
VALUES (${parent.runId}, ${runId}, ${input.invocationId}, ${childReadiness}, NULL, NOW(), NULL)
|
|
137
137
|
`;
|
|
138
138
|
yield* appendEvent(transactionHub, parent, {
|
|
@@ -152,7 +152,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
152
152
|
return { runId, messageId: input.message.id, acceptedSequence: 0, duplicate: false };
|
|
153
153
|
}
|
|
154
154
|
const started = (yield* loadRun(runId));
|
|
155
|
-
yield* sql `UPDATE
|
|
155
|
+
yield* sql `UPDATE tenetkit_runs SET attempt_fence = 1, attempt = 1, status = 'running' WHERE run_id = ${runId}`;
|
|
156
156
|
yield* appendEvent(transactionHub, { ...started, attempt: 1 }, { _tag: "RunAttemptStarted", attempt: 1 }, "running");
|
|
157
157
|
return { runId, messageId: input.message.id, acceptedSequence: 0, duplicate: false };
|
|
158
158
|
})),
|
|
@@ -189,7 +189,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
189
189
|
const responded = [...loaded.respondedWaitIds, input.waitId];
|
|
190
190
|
const resolution = input.resolution;
|
|
191
191
|
const closed = yield* sql `
|
|
192
|
-
UPDATE
|
|
192
|
+
UPDATE tenetkit_run_waits SET status = 'responded', response_json = ${encodeJson(WaitResolution, resolution)}, closed_at = NOW()
|
|
193
193
|
WHERE run_id = ${loaded.runId} AND wait_id = ${input.waitId} AND status = 'open'
|
|
194
194
|
RETURNING wait_id
|
|
195
195
|
`;
|
|
@@ -200,12 +200,12 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
200
200
|
return yield* ResponseConflict.make({ runId: loaded.runId, waitId: input.waitId });
|
|
201
201
|
}
|
|
202
202
|
yield* sql `
|
|
203
|
-
UPDATE
|
|
203
|
+
UPDATE tenetkit_runs
|
|
204
204
|
SET responded_wait_ids_json = ${encodeJson(StringArray, responded)}, updated_at = NOW()
|
|
205
205
|
WHERE run_id = ${loaded.runId}
|
|
206
206
|
`;
|
|
207
207
|
yield* sql `
|
|
208
|
-
UPDATE
|
|
208
|
+
UPDATE tenetkit_program_operations SET status = 'reserved'
|
|
209
209
|
WHERE run_id = ${loaded.runId} AND wait_id = ${input.waitId} AND status = 'waiting'
|
|
210
210
|
`;
|
|
211
211
|
const current = (yield* loadRun(loaded.runId));
|
|
@@ -220,7 +220,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
220
220
|
const responded = [...loaded.respondedWaitIds, response.waitId];
|
|
221
221
|
const resolution = input.decision;
|
|
222
222
|
const closed = yield* sql `
|
|
223
|
-
UPDATE
|
|
223
|
+
UPDATE tenetkit_run_waits SET status = 'responded', response_json = ${encodeJson(WaitResolution, resolution)}, closed_at = NOW()
|
|
224
224
|
WHERE run_id = ${loaded.runId} AND wait_id = ${response.waitId} AND status = 'open'
|
|
225
225
|
RETURNING wait_id
|
|
226
226
|
`;
|
|
@@ -228,12 +228,12 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
228
228
|
return yield* ApprovalStale.make({ runId: loaded.runId, approvalId: input.approvalId });
|
|
229
229
|
}
|
|
230
230
|
yield* sql `
|
|
231
|
-
UPDATE
|
|
231
|
+
UPDATE tenetkit_runs
|
|
232
232
|
SET responded_wait_ids_json = ${encodeJson(StringArray, responded)}, updated_at = NOW()
|
|
233
233
|
WHERE run_id = ${loaded.runId}
|
|
234
234
|
`;
|
|
235
235
|
yield* sql `
|
|
236
|
-
UPDATE
|
|
236
|
+
UPDATE tenetkit_program_operations SET status = 'reserved'
|
|
237
237
|
WHERE run_id = ${loaded.runId} AND wait_id = ${response.waitId} AND status = 'waiting'
|
|
238
238
|
`;
|
|
239
239
|
const current = (yield* loadRun(loaded.runId));
|
|
@@ -255,7 +255,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
255
255
|
...(input.payload === undefined ? {} : { payload: input.payload }),
|
|
256
256
|
};
|
|
257
257
|
yield* sql `
|
|
258
|
-
UPDATE
|
|
258
|
+
UPDATE tenetkit_run_waits SET status = 'signaled', response_json = ${encodeJson(WaitResolution, resolution)}, closed_at = NOW()
|
|
259
259
|
WHERE run_id = ${loaded.runId} AND wait_id = ${loaded.activeWaitId} AND status = 'open'
|
|
260
260
|
`;
|
|
261
261
|
yield* appendEvent(transactionHub, loaded, { _tag: "RunResumed", waitId: loaded.activeWaitId, resolution }, "running");
|
|
@@ -298,11 +298,11 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
298
298
|
return;
|
|
299
299
|
}
|
|
300
300
|
const runningFanOut = yield* sql `
|
|
301
|
-
SELECT fan_out_id FROM
|
|
301
|
+
SELECT fan_out_id FROM tenetkit_fan_outs WHERE parent_run_id = ${loaded.runId} AND status = 'running' LIMIT 1
|
|
302
302
|
`;
|
|
303
303
|
if (runningFanOut.length > 0) {
|
|
304
304
|
yield* sql `
|
|
305
|
-
UPDATE
|
|
305
|
+
UPDATE tenetkit_runs SET status = 'waiting', owner_worker_id = NULL, lease_expires_at = NULL,
|
|
306
306
|
suspension_json = NULL,
|
|
307
307
|
pending_outcome_json = ${encodeJson(PendingRunOutcome, { _tag: "Failed", error: input.error })}
|
|
308
308
|
WHERE run_id = ${loaded.runId}
|
|
@@ -336,7 +336,7 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
336
336
|
const responded = [...loaded.respondedWaitIds, input.waitId];
|
|
337
337
|
const resolution = input.resolution;
|
|
338
338
|
const closed = yield* sql `
|
|
339
|
-
UPDATE
|
|
339
|
+
UPDATE tenetkit_run_waits SET status = 'responded', response_json = ${encodeJson(WaitResolution, resolution)}, closed_at = NOW()
|
|
340
340
|
WHERE run_id = ${loaded.runId} AND wait_id = ${input.waitId} AND status = 'open'
|
|
341
341
|
RETURNING wait_id
|
|
342
342
|
`;
|
|
@@ -347,12 +347,12 @@ export const makePostgresServices = (options) => Effect.gen(function* () {
|
|
|
347
347
|
return yield* ResponseConflict.make({ runId: loaded.runId, waitId: input.waitId });
|
|
348
348
|
}
|
|
349
349
|
yield* sql `
|
|
350
|
-
UPDATE
|
|
350
|
+
UPDATE tenetkit_runs
|
|
351
351
|
SET responded_wait_ids_json = ${encodeJson(StringArray, responded)}, updated_at = NOW()
|
|
352
352
|
WHERE run_id = ${loaded.runId}
|
|
353
353
|
`;
|
|
354
354
|
yield* sql `
|
|
355
|
-
UPDATE
|
|
355
|
+
UPDATE tenetkit_program_operations SET status = 'reserved'
|
|
356
356
|
WHERE run_id = ${loaded.runId} AND wait_id = ${input.waitId} AND status = 'waiting'
|
|
357
357
|
`;
|
|
358
358
|
const current = (yield* loadRun(loaded.runId));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@effect/sql-pg": "4.0.0-rc.109",
|
|
40
|
-
"tenetkit": "0.
|
|
40
|
+
"tenetkit": "0.33.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@effect/vitest": "4.0.0-rc.109",
|