@fungi.computer/watchdog 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +334 -2
- package/dist/d1.d.ts +36 -0
- package/dist/d1.js +41 -0
- package/dist/effect.d.ts +336 -0
- package/dist/effect.js +140 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +41 -0
- package/dist/internal/async-runtime.d.ts +17 -0
- package/dist/internal/async-runtime.js +39 -0
- package/dist/internal/async-sql.d.ts +15 -0
- package/dist/internal/async-sql.js +66 -0
- package/dist/internal/async-store.d.ts +58 -0
- package/dist/internal/async-store.js +235 -0
- package/dist/internal/identities.d.ts +3 -0
- package/dist/internal/identities.js +8 -0
- package/dist/internal/lane.d.ts +3 -0
- package/dist/internal/lane.js +6 -0
- package/dist/internal/promise-watchdog-host.d.ts +4 -0
- package/dist/internal/promise-watchdog-host.js +25 -0
- package/dist/internal/runtime.d.ts +3 -0
- package/dist/internal/runtime.js +199 -0
- package/dist/internal/sqlite-store.d.ts +107 -0
- package/dist/internal/sqlite-store.js +478 -0
- package/dist/internal/watchdog-error.d.ts +12 -0
- package/dist/internal/watchdog-error.js +17 -0
- package/dist/node-sqlite.d.ts +17 -0
- package/dist/node-sqlite.js +63 -0
- package/dist/postgres.d.ts +22 -0
- package/dist/postgres.js +31 -0
- package/docs/api/README.md +17 -0
- package/docs/api/d1.md +162 -0
- package/docs/api/effect.md +875 -0
- package/docs/api/index.md +421 -0
- package/docs/api/node-sqlite.md +57 -0
- package/docs/api/postgres.md +102 -0
- package/package.json +78 -3
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
<!-- Generated by Botanical API docs (TypeDoc + typedoc-plugin-markdown). Do not edit. -->
|
|
2
|
+
|
|
3
|
+
[**@fungi.computer/watchdog**](README.md)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
[@fungi.computer/watchdog](README.md) / effect
|
|
8
|
+
|
|
9
|
+
# effect
|
|
10
|
+
|
|
11
|
+
## Type Aliases
|
|
12
|
+
|
|
13
|
+
### WatchdogQueuedJob
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
type WatchdogQueuedJob = Schema.Schema.Type<typeof WatchdogQueuedJobSchema>;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Generic durable work waiting for execution.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### WatchdogSettledJob
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
type WatchdogSettledJob = Schema.Schema.Type<typeof WatchdogSettledJobSchema>;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Generic durable work with a terminal outcome.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### WatchdogSettledRecord
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
type WatchdogSettledRecord = Readonly<{
|
|
37
|
+
sequence: number;
|
|
38
|
+
job: WatchdogSettledJob;
|
|
39
|
+
}>;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
One bounded terminal-job recovery record with its durable ordering cursor.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### WatchdogRunningJob
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
type WatchdogRunningJob = Schema.Schema.Type<typeof WatchdogRunningJobSchema>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Generic durable work held by Watchdog's private claim.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
### WatchdogStoredJob
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
type WatchdogStoredJob = Schema.Schema.Type<typeof WatchdogStoredJobSchema>;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Any publicly readable lifecycle state for a generic job.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### WatchdogExecutionDecision
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
type WatchdogExecutionDecision = Schema.Schema.Type<
|
|
70
|
+
typeof WatchdogExecutionDecisionSchema
|
|
71
|
+
>;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Terminal decision returned by the host executor.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### WatchdogCancellationIntent
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
type WatchdogCancellationIntent = Schema.Schema.Type<
|
|
82
|
+
typeof WatchdogCancellationIntentSchema
|
|
83
|
+
>;
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Owner-issued durable cancellation intent.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
### WatchdogCancellationDecision
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
type WatchdogCancellationDecision =
|
|
94
|
+
| Readonly<{
|
|
95
|
+
status: "recorded" | "replayed";
|
|
96
|
+
intent: WatchdogCancellationIntent;
|
|
97
|
+
}>
|
|
98
|
+
| Readonly<{
|
|
99
|
+
status: "conflict" | "missing";
|
|
100
|
+
}>;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Result of recording an owner cancellation in its surrounding transaction.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
### WatchdogTransactionalProjection
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
type WatchdogTransactionalProjection = Readonly<{
|
|
111
|
+
readQueueHead: (queue) => WatchdogQueueHead;
|
|
112
|
+
readLatestSettledJob: (queue) => WatchdogSettledJob | undefined;
|
|
113
|
+
enqueueAcceptedJob: (job) => void;
|
|
114
|
+
recordCancellationIntent: (intent) => WatchdogCancellationDecision;
|
|
115
|
+
}>;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Narrow synchronous seam for owner-atomic queue inspection, ingest, and
|
|
119
|
+
cancellation.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
### WatchdogReadResult
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
type WatchdogReadResult = Schema.Schema.Type<typeof WatchdogReadResultSchema>;
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Result of reading one generic job and its cancellation state.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### WatchdogQueueHead
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
type WatchdogQueueHead = Schema.Schema.Type<typeof WatchdogQueueHeadSchema>;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Current queued or running job for one queue, excluding terminal history.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### WatchdogQueueTransition
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
type WatchdogQueueTransition = Readonly<{
|
|
147
|
+
queue: string;
|
|
148
|
+
head: WatchdogQueueHead;
|
|
149
|
+
settled?: WatchdogSettledJob;
|
|
150
|
+
}>;
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
One queue's state after a durable transition.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
### WatchdogQueueProjector
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
type WatchdogQueueProjector = (transition) => void;
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Owner projection written inside the same SQLite transaction as every queue
|
|
164
|
+
transition: ingest, claim, cancellation, settlement, recovery and purge. It must
|
|
165
|
+
be a deterministic owner-local write. A throw fails the transition exactly like
|
|
166
|
+
any other storage failure.
|
|
167
|
+
|
|
168
|
+
#### Parameters
|
|
169
|
+
|
|
170
|
+
| Parameter | Type |
|
|
171
|
+
| ------------ | ----------------------------------------------------- |
|
|
172
|
+
| `transition` | [`WatchdogQueueTransition`](#watchdogqueuetransition) |
|
|
173
|
+
|
|
174
|
+
#### Returns
|
|
175
|
+
|
|
176
|
+
`void`
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### WatchdogIngestResult
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
type WatchdogIngestResult = Schema.Schema.Type<
|
|
184
|
+
typeof WatchdogIngestResultSchema
|
|
185
|
+
>;
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Result of idempotent durable ingest.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### WatchdogCancellationResult
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
type WatchdogCancellationResult = Schema.Schema.Type<
|
|
196
|
+
typeof WatchdogCancellationResultSchema
|
|
197
|
+
>;
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Result of recording a cancellation through the asynchronous runtime.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
### EffectWatchdogExecutor
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
type EffectWatchdogExecutor = Readonly<{
|
|
208
|
+
execute: (job) => Effect.Effect<WatchdogExecutionDecision, WatchdogError>;
|
|
209
|
+
}>;
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Effect-native host executor for one generic running job.
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### WatchdogSqliteValue
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
type WatchdogSqliteValue = Schema.Schema.Type<typeof watchdogSqliteValueSchema>;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Parsed native SQLite scalar shared by the durable storage adapters.
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### WatchdogSqliteRow
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
type WatchdogSqliteRow = Schema.Schema.Type<typeof watchdogSqliteRowSchema>;
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Parsed scalar record; query-specific columns require their owner schema.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### WatchdogSqliteCursor
|
|
237
|
+
|
|
238
|
+
```ts
|
|
239
|
+
type WatchdogSqliteCursor = Readonly<{
|
|
240
|
+
toArray: () => readonly WatchdogSqliteRow[];
|
|
241
|
+
}>;
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Structural result cursor required by Watchdog's SQLite implementation.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### WatchdogSqliteOwner
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
type WatchdogSqliteOwner = Readonly<{
|
|
252
|
+
sql: Readonly<{
|
|
253
|
+
exec: (statement, ...bindings) => WatchdogSqliteCursor;
|
|
254
|
+
}>;
|
|
255
|
+
transactionSync: <A>(operation) => A;
|
|
256
|
+
}>;
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Native owner-local SQLite capability consumed by Watchdog.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
### EffectWatchdogOptions
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
type EffectWatchdogOptions = Readonly<{
|
|
267
|
+
concurrentLane?: string;
|
|
268
|
+
owner: WatchdogSqliteOwner;
|
|
269
|
+
isAlive: (job) => Effect.Effect<boolean, WatchdogError>;
|
|
270
|
+
executor: EffectWatchdogExecutor;
|
|
271
|
+
wake: Readonly<{
|
|
272
|
+
recompute: () => Effect.Effect<void, WatchdogError>;
|
|
273
|
+
}>;
|
|
274
|
+
project?: WatchdogQueueProjector;
|
|
275
|
+
}>;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Effect-native construction inputs for the deep SQLite Watchdog.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
### WatchdogLivenessUnknown
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
type WatchdogLivenessUnknown = Readonly<{
|
|
286
|
+
status: "liveness_unknown";
|
|
287
|
+
jobId: string;
|
|
288
|
+
reason: WatchdogError["cause"];
|
|
289
|
+
}>;
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
A running job's liveness probe failed. The job is left exactly as it was:
|
|
293
|
+
Watchdog neither treats it as alive nor fabricates a disappearance.
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
### WatchdogTickResult
|
|
298
|
+
|
|
299
|
+
```ts
|
|
300
|
+
type WatchdogTickResult =
|
|
301
|
+
| Readonly<{
|
|
302
|
+
status: "busy";
|
|
303
|
+
}>
|
|
304
|
+
| Readonly<{
|
|
305
|
+
status: "no_ready";
|
|
306
|
+
}>
|
|
307
|
+
| WatchdogLivenessUnknown
|
|
308
|
+
| Readonly<{
|
|
309
|
+
status: "settled";
|
|
310
|
+
job: WatchdogSettledJob;
|
|
311
|
+
}>;
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Result of one bounded deep tick.
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
### WatchdogLaneFailure
|
|
319
|
+
|
|
320
|
+
```ts
|
|
321
|
+
type WatchdogLaneFailure = Readonly<{
|
|
322
|
+
lane: string;
|
|
323
|
+
reason: string;
|
|
324
|
+
}>;
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Owner-issued terminal lane refusal; reason is an owner code, at most 200
|
|
328
|
+
characters.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
### WatchdogLaneFailureResult
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
type WatchdogLaneFailureResult = Readonly<{
|
|
336
|
+
settled: number;
|
|
337
|
+
more: boolean;
|
|
338
|
+
}>;
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
One bounded refusal batch; call again only while more is true.
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
345
|
+
### WatchdogRuntimeEffect
|
|
346
|
+
|
|
347
|
+
```ts
|
|
348
|
+
type WatchdogRuntimeEffect = Readonly<{
|
|
349
|
+
hasPendingWork: Effect.Effect<boolean, WatchdogError>;
|
|
350
|
+
ingest: (job) => Effect.Effect<WatchdogIngestResult, WatchdogError>;
|
|
351
|
+
read: (jobId) => Effect.Effect<WatchdogReadResult, WatchdogError>;
|
|
352
|
+
readQueueHead: (queue) => Effect.Effect<WatchdogQueueHead, WatchdogError>;
|
|
353
|
+
readSettled: (
|
|
354
|
+
limit,
|
|
355
|
+
afterSequence?,
|
|
356
|
+
) => Effect.Effect<readonly WatchdogSettledRecord[], WatchdogError>;
|
|
357
|
+
tick: () => Effect.Effect<WatchdogTickResult, WatchdogError>;
|
|
358
|
+
cancel: (input) => Effect.Effect<WatchdogCancellationResult, WatchdogError>;
|
|
359
|
+
failLane: (input) => Effect.Effect<WatchdogLaneFailureResult, WatchdogError>;
|
|
360
|
+
purge: (queue) => Effect.Effect<void, WatchdogError>;
|
|
361
|
+
transactional: WatchdogTransactionalProjection;
|
|
362
|
+
}>;
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Effect-native Watchdog runtime surface.
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
### ConcurrentWatchdogRuntimeEffect
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
type ConcurrentWatchdogRuntimeEffect = WatchdogRuntimeEffect &
|
|
373
|
+
Readonly<{
|
|
374
|
+
tickConcurrent: () => Effect.Effect<WatchdogTickResult, WatchdogError>;
|
|
375
|
+
}>;
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
Runtime configured with one independent host lane at construction.
|
|
379
|
+
|
|
380
|
+
## Variables
|
|
381
|
+
|
|
382
|
+
### WatchdogQueuedJobSchema
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
const WatchdogQueuedJobSchema: Struct<{
|
|
386
|
+
jobId: String;
|
|
387
|
+
queue: String;
|
|
388
|
+
lane: String;
|
|
389
|
+
priority: Int;
|
|
390
|
+
payload: Unknown;
|
|
391
|
+
recovery: optional<
|
|
392
|
+
Struct<{
|
|
393
|
+
maxRecoveries: Int;
|
|
394
|
+
}>
|
|
395
|
+
>;
|
|
396
|
+
state: Literal<"queued">;
|
|
397
|
+
}>;
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
The public queued-job grammar. Payload is deliberately uninterpreted.
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
### WatchdogSettledJobSchema
|
|
405
|
+
|
|
406
|
+
```ts
|
|
407
|
+
const WatchdogSettledJobSchema: Struct<{
|
|
408
|
+
jobId: String;
|
|
409
|
+
queue: String;
|
|
410
|
+
lane: String;
|
|
411
|
+
priority: Int;
|
|
412
|
+
payload: Unknown;
|
|
413
|
+
recovery: optional<
|
|
414
|
+
Struct<{
|
|
415
|
+
maxRecoveries: Int;
|
|
416
|
+
}>
|
|
417
|
+
>;
|
|
418
|
+
state: Literal<"settled">;
|
|
419
|
+
outcome: Literals<
|
|
420
|
+
readonly [
|
|
421
|
+
"completed",
|
|
422
|
+
"failed",
|
|
423
|
+
"cancelled",
|
|
424
|
+
"outcome_unknown",
|
|
425
|
+
"interrupted",
|
|
426
|
+
]
|
|
427
|
+
>;
|
|
428
|
+
failureReason: optionalKey<String>;
|
|
429
|
+
}>;
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
The public terminal-job grammar.
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
### WatchdogRunningJobSchema
|
|
437
|
+
|
|
438
|
+
```ts
|
|
439
|
+
const WatchdogRunningJobSchema: Struct<{
|
|
440
|
+
jobId: String;
|
|
441
|
+
queue: String;
|
|
442
|
+
lane: String;
|
|
443
|
+
priority: Int;
|
|
444
|
+
payload: Unknown;
|
|
445
|
+
recovery: optional<
|
|
446
|
+
Struct<{
|
|
447
|
+
maxRecoveries: Int;
|
|
448
|
+
}>
|
|
449
|
+
>;
|
|
450
|
+
state: Literal<"running">;
|
|
451
|
+
}>;
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
The public running-job grammar. Private claim data is deliberately absent.
|
|
455
|
+
|
|
456
|
+
---
|
|
457
|
+
|
|
458
|
+
### WatchdogStoredJobSchema
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
const WatchdogStoredJobSchema: Union<
|
|
462
|
+
readonly [
|
|
463
|
+
Struct<{
|
|
464
|
+
jobId: String;
|
|
465
|
+
queue: String;
|
|
466
|
+
lane: String;
|
|
467
|
+
priority: Int;
|
|
468
|
+
payload: Unknown;
|
|
469
|
+
recovery: optional<
|
|
470
|
+
Struct<{
|
|
471
|
+
maxRecoveries: Int;
|
|
472
|
+
}>
|
|
473
|
+
>;
|
|
474
|
+
state: Literal<"queued">;
|
|
475
|
+
}>,
|
|
476
|
+
Struct<{
|
|
477
|
+
jobId: String;
|
|
478
|
+
queue: String;
|
|
479
|
+
lane: String;
|
|
480
|
+
priority: Int;
|
|
481
|
+
payload: Unknown;
|
|
482
|
+
recovery: optional<
|
|
483
|
+
Struct<{
|
|
484
|
+
maxRecoveries: Int;
|
|
485
|
+
}>
|
|
486
|
+
>;
|
|
487
|
+
state: Literal<"running">;
|
|
488
|
+
}>,
|
|
489
|
+
Struct<{
|
|
490
|
+
jobId: String;
|
|
491
|
+
queue: String;
|
|
492
|
+
lane: String;
|
|
493
|
+
priority: Int;
|
|
494
|
+
payload: Unknown;
|
|
495
|
+
recovery: optional<
|
|
496
|
+
Struct<{
|
|
497
|
+
maxRecoveries: Int;
|
|
498
|
+
}>
|
|
499
|
+
>;
|
|
500
|
+
state: Literal<"settled">;
|
|
501
|
+
outcome: Literals<
|
|
502
|
+
readonly [
|
|
503
|
+
"completed",
|
|
504
|
+
"failed",
|
|
505
|
+
"cancelled",
|
|
506
|
+
"outcome_unknown",
|
|
507
|
+
"interrupted",
|
|
508
|
+
]
|
|
509
|
+
>;
|
|
510
|
+
failureReason: optionalKey<String>;
|
|
511
|
+
}>,
|
|
512
|
+
]
|
|
513
|
+
>;
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
The complete public job lifecycle grammar.
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
### WatchdogExecutionDecisionSchema
|
|
521
|
+
|
|
522
|
+
```ts
|
|
523
|
+
const WatchdogExecutionDecisionSchema: Union<
|
|
524
|
+
readonly [
|
|
525
|
+
Struct<{
|
|
526
|
+
kind: Literal<"completed">;
|
|
527
|
+
}>,
|
|
528
|
+
Struct<{
|
|
529
|
+
kind: Literal<"failed">;
|
|
530
|
+
reason: optionalKey<String>;
|
|
531
|
+
}>,
|
|
532
|
+
Struct<{
|
|
533
|
+
kind: Literal<"cancelled">;
|
|
534
|
+
}>,
|
|
535
|
+
Struct<{
|
|
536
|
+
kind: Literal<"outcome_unknown">;
|
|
537
|
+
}>,
|
|
538
|
+
]
|
|
539
|
+
>;
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
Terminal decisions returned by the execution adapter.
|
|
543
|
+
|
|
544
|
+
---
|
|
545
|
+
|
|
546
|
+
### WatchdogCancellationIntentSchema
|
|
547
|
+
|
|
548
|
+
```ts
|
|
549
|
+
const WatchdogCancellationIntentSchema: Struct<{
|
|
550
|
+
jobId: String;
|
|
551
|
+
cancellationId: String;
|
|
552
|
+
onlyIfQueued: optional<Boolean>;
|
|
553
|
+
}>;
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
Durable cancellation requested by the enclosing owner.
|
|
557
|
+
|
|
558
|
+
---
|
|
559
|
+
|
|
560
|
+
### WatchdogReadResultSchema
|
|
561
|
+
|
|
562
|
+
```ts
|
|
563
|
+
const WatchdogReadResultSchema: Union<readonly [Struct<{
|
|
564
|
+
status: Literal<"found">;
|
|
565
|
+
job: Union<readonly [Struct<{
|
|
566
|
+
jobId: String;
|
|
567
|
+
queue: String;
|
|
568
|
+
lane: String;
|
|
569
|
+
priority: Int;
|
|
570
|
+
payload: Unknown;
|
|
571
|
+
recovery: optional<Struct<{
|
|
572
|
+
maxRecoveries: ...;
|
|
573
|
+
}>>;
|
|
574
|
+
state: Literal<"queued">;
|
|
575
|
+
}>, Struct<{
|
|
576
|
+
jobId: String;
|
|
577
|
+
queue: String;
|
|
578
|
+
lane: String;
|
|
579
|
+
priority: Int;
|
|
580
|
+
payload: Unknown;
|
|
581
|
+
recovery: optional<Struct<{
|
|
582
|
+
maxRecoveries: ...;
|
|
583
|
+
}>>;
|
|
584
|
+
state: Literal<"running">;
|
|
585
|
+
}>, Struct<{
|
|
586
|
+
jobId: String;
|
|
587
|
+
queue: String;
|
|
588
|
+
lane: String;
|
|
589
|
+
priority: Int;
|
|
590
|
+
payload: Unknown;
|
|
591
|
+
recovery: optional<Struct<{
|
|
592
|
+
maxRecoveries: ...;
|
|
593
|
+
}>>;
|
|
594
|
+
state: Literal<"settled">;
|
|
595
|
+
outcome: Literals<readonly ["completed", "failed", "cancelled", "outcome_unknown", "interrupted"]>;
|
|
596
|
+
failureReason: optionalKey<String>;
|
|
597
|
+
}>]>;
|
|
598
|
+
cancellation: Union<readonly [Struct<{
|
|
599
|
+
status: Literal<"absent">;
|
|
600
|
+
}>, Struct<{
|
|
601
|
+
status: Literal<"present">;
|
|
602
|
+
cancellation: Struct<{
|
|
603
|
+
jobId: String;
|
|
604
|
+
cancellationId: String;
|
|
605
|
+
onlyIfQueued: optional<...>;
|
|
606
|
+
}>;
|
|
607
|
+
}>]>;
|
|
608
|
+
}>, Struct<{
|
|
609
|
+
status: Literal<"missing">;
|
|
610
|
+
}>]>;
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
Results returned by public job inspection.
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
### WatchdogQueueHeadSchema
|
|
618
|
+
|
|
619
|
+
```ts
|
|
620
|
+
const WatchdogQueueHeadSchema: Union<
|
|
621
|
+
readonly [
|
|
622
|
+
Struct<{
|
|
623
|
+
state: Literal<"idle">;
|
|
624
|
+
}>,
|
|
625
|
+
Struct<{
|
|
626
|
+
state: Literals<readonly ["queued", "running"]>;
|
|
627
|
+
jobId: String;
|
|
628
|
+
cancellationRequested: Boolean;
|
|
629
|
+
}>,
|
|
630
|
+
]
|
|
631
|
+
>;
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
Bounded current-work projection for one generic queue.
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
### WatchdogIngestResultSchema
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
const WatchdogIngestResultSchema: Union<
|
|
642
|
+
readonly [
|
|
643
|
+
Struct<{
|
|
644
|
+
status: Literal<"queued">;
|
|
645
|
+
}>,
|
|
646
|
+
Struct<{
|
|
647
|
+
status: Literal<"duplicate">;
|
|
648
|
+
}>,
|
|
649
|
+
]
|
|
650
|
+
>;
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
Results returned by idempotent public ingest.
|
|
654
|
+
|
|
655
|
+
---
|
|
656
|
+
|
|
657
|
+
### WatchdogCancellationResultSchema
|
|
658
|
+
|
|
659
|
+
```ts
|
|
660
|
+
const WatchdogCancellationResultSchema: Union<
|
|
661
|
+
readonly [
|
|
662
|
+
Struct<{
|
|
663
|
+
status: Literals<readonly ["recorded", "replayed"]>;
|
|
664
|
+
}>,
|
|
665
|
+
Struct<{
|
|
666
|
+
status: Literals<readonly ["conflict", "missing"]>;
|
|
667
|
+
}>,
|
|
668
|
+
]
|
|
669
|
+
>;
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
Results returned by durable cancellation recording.
|
|
673
|
+
|
|
674
|
+
---
|
|
675
|
+
|
|
676
|
+
### watchdogSqliteValueSchema
|
|
677
|
+
|
|
678
|
+
```ts
|
|
679
|
+
const watchdogSqliteValueSchema: Union<
|
|
680
|
+
readonly [instanceOf<ArrayBuffer, unknown>, String, Number, Null]
|
|
681
|
+
>;
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
Scalar grammar shared by native SQLite adapters and their storage owners.
|
|
685
|
+
|
|
686
|
+
---
|
|
687
|
+
|
|
688
|
+
### watchdogSqliteRowSchema
|
|
689
|
+
|
|
690
|
+
```ts
|
|
691
|
+
const watchdogSqliteRowSchema: $Record<
|
|
692
|
+
String,
|
|
693
|
+
Union<readonly [instanceOf<ArrayBuffer, unknown>, String, Number, Null]>
|
|
694
|
+
>;
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
A native row is a scalar record; each query owner decodes its own projection.
|
|
698
|
+
|
|
699
|
+
## Functions
|
|
700
|
+
|
|
701
|
+
### makeRuntime()
|
|
702
|
+
|
|
703
|
+
#### Call Signature
|
|
704
|
+
|
|
705
|
+
```ts
|
|
706
|
+
function makeRuntime(
|
|
707
|
+
options,
|
|
708
|
+
): Effect<ConcurrentWatchdogRuntimeEffect, WatchdogError>;
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
Construct two private single-flight slots over the same owner and job table.
|
|
712
|
+
|
|
713
|
+
##### Parameters
|
|
714
|
+
|
|
715
|
+
| Parameter | Type |
|
|
716
|
+
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
717
|
+
| `options` | `Readonly`\<\{ `concurrentLane?`: `string`; `owner`: [`WatchdogSqliteOwner`](#watchdogsqliteowner); `isAlive`: (`job`) => `Effect`\<`boolean`, [`WatchdogError`](index.md#watchdogerror)\>; `executor`: [`EffectWatchdogExecutor`](#effectwatchdogexecutor); `wake`: `Readonly`\<\{ `recompute`: () => `Effect.Effect`\<`void`, [`WatchdogError`](index.md#watchdogerror)\>; \}\>; `project?`: [`WatchdogQueueProjector`](#watchdogqueueprojector); \}\> & `object` |
|
|
718
|
+
|
|
719
|
+
##### Returns
|
|
720
|
+
|
|
721
|
+
`Effect`\<[`ConcurrentWatchdogRuntimeEffect`](#concurrentwatchdogruntimeeffect),
|
|
722
|
+
[`WatchdogError`](index.md#watchdogerror)\>
|
|
723
|
+
|
|
724
|
+
#### Call Signature
|
|
725
|
+
|
|
726
|
+
```ts
|
|
727
|
+
function makeRuntime(options): Effect<Readonly<{
|
|
728
|
+
hasPendingWork: Effect<boolean, WatchdogError>;
|
|
729
|
+
ingest: (job) => Effect<
|
|
730
|
+
| {
|
|
731
|
+
status: "queued";
|
|
732
|
+
}
|
|
733
|
+
| {
|
|
734
|
+
status: "duplicate";
|
|
735
|
+
}, WatchdogError>;
|
|
736
|
+
read: (jobId) => Effect<
|
|
737
|
+
| {
|
|
738
|
+
status: "found";
|
|
739
|
+
job: | {
|
|
740
|
+
jobId: string;
|
|
741
|
+
queue: string;
|
|
742
|
+
lane: string;
|
|
743
|
+
priority: number;
|
|
744
|
+
payload: unknown;
|
|
745
|
+
recovery?: {
|
|
746
|
+
maxRecoveries: ...;
|
|
747
|
+
};
|
|
748
|
+
state: "queued";
|
|
749
|
+
}
|
|
750
|
+
| {
|
|
751
|
+
jobId: string;
|
|
752
|
+
queue: string;
|
|
753
|
+
lane: string;
|
|
754
|
+
priority: number;
|
|
755
|
+
payload: unknown;
|
|
756
|
+
recovery?: {
|
|
757
|
+
maxRecoveries: ...;
|
|
758
|
+
};
|
|
759
|
+
state: "running";
|
|
760
|
+
}
|
|
761
|
+
| {
|
|
762
|
+
jobId: string;
|
|
763
|
+
queue: string;
|
|
764
|
+
lane: string;
|
|
765
|
+
priority: number;
|
|
766
|
+
payload: unknown;
|
|
767
|
+
recovery?: {
|
|
768
|
+
maxRecoveries: ...;
|
|
769
|
+
};
|
|
770
|
+
state: "settled";
|
|
771
|
+
outcome: "failed" | "completed" | "interrupted" | "cancelled" | "outcome_unknown";
|
|
772
|
+
failureReason?: string;
|
|
773
|
+
};
|
|
774
|
+
cancellation: | {
|
|
775
|
+
status: "absent";
|
|
776
|
+
}
|
|
777
|
+
| {
|
|
778
|
+
status: "present";
|
|
779
|
+
cancellation: {
|
|
780
|
+
jobId: string;
|
|
781
|
+
cancellationId: string;
|
|
782
|
+
onlyIfQueued?: ... | ... | ...;
|
|
783
|
+
};
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
| {
|
|
787
|
+
status: "missing";
|
|
788
|
+
}, WatchdogError>;
|
|
789
|
+
readQueueHead: (queue) => Effect<
|
|
790
|
+
| {
|
|
791
|
+
state: "idle";
|
|
792
|
+
}
|
|
793
|
+
| {
|
|
794
|
+
state: "running" | "queued";
|
|
795
|
+
jobId: string;
|
|
796
|
+
cancellationRequested: boolean;
|
|
797
|
+
}, WatchdogError>;
|
|
798
|
+
readSettled: (limit, afterSequence?) => Effect<readonly Readonly<{
|
|
799
|
+
sequence: number;
|
|
800
|
+
job: {
|
|
801
|
+
jobId: string;
|
|
802
|
+
queue: string;
|
|
803
|
+
lane: string;
|
|
804
|
+
priority: number;
|
|
805
|
+
payload: unknown;
|
|
806
|
+
recovery?: {
|
|
807
|
+
maxRecoveries: ...;
|
|
808
|
+
};
|
|
809
|
+
state: "settled";
|
|
810
|
+
outcome: "failed" | "completed" | "interrupted" | "cancelled" | "outcome_unknown";
|
|
811
|
+
failureReason?: string;
|
|
812
|
+
};
|
|
813
|
+
}>[], WatchdogError>;
|
|
814
|
+
tick: () => Effect<WatchdogTickResult, WatchdogError>;
|
|
815
|
+
cancel: (input) => Effect<
|
|
816
|
+
| {
|
|
817
|
+
status: "replayed" | "recorded";
|
|
818
|
+
}
|
|
819
|
+
| {
|
|
820
|
+
status: "missing" | "conflict";
|
|
821
|
+
}, WatchdogError>;
|
|
822
|
+
failLane: (input) => Effect<Readonly<{
|
|
823
|
+
settled: number;
|
|
824
|
+
more: boolean;
|
|
825
|
+
}>, WatchdogError>;
|
|
826
|
+
purge: (queue) => Effect<void, WatchdogError>;
|
|
827
|
+
transactional: WatchdogTransactionalProjection;
|
|
828
|
+
}>, WatchdogError>;
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
Construct a serial owner-local runtime.
|
|
832
|
+
|
|
833
|
+
##### Parameters
|
|
834
|
+
|
|
835
|
+
| Parameter | Type |
|
|
836
|
+
| --------- | ------------------------------------------------- |
|
|
837
|
+
| `options` | [`EffectWatchdogOptions`](#effectwatchdogoptions) |
|
|
838
|
+
|
|
839
|
+
##### Returns
|
|
840
|
+
|
|
841
|
+
`Effect`\<`Readonly`\<\{ `hasPendingWork`: `Effect`\<`boolean`,
|
|
842
|
+
[`WatchdogError`](index.md#watchdogerror)\>; `ingest`: (`job`) => `Effect`\< \|
|
|
843
|
+
\{ `status`: `"queued"`; \} \| \{ `status`: `"duplicate"`; \},
|
|
844
|
+
[`WatchdogError`](index.md#watchdogerror)\>; `read`: (`jobId`) => `Effect`\< \|
|
|
845
|
+
\{ `status`: `"found"`; `job`: \| \{ `jobId`: `string`; `queue`: `string`;
|
|
846
|
+
`lane`: `string`; `priority`: `number`; `payload`: `unknown`; `recovery?`: \{
|
|
847
|
+
`maxRecoveries`: ...; \}; `state`: `"queued"`; \} \| \{ `jobId`: `string`;
|
|
848
|
+
`queue`: `string`; `lane`: `string`; `priority`: `number`; `payload`: `unknown`;
|
|
849
|
+
`recovery?`: \{ `maxRecoveries`: ...; \}; `state`: `"running"`; \} \| \{
|
|
850
|
+
`jobId`: `string`; `queue`: `string`; `lane`: `string`; `priority`: `number`;
|
|
851
|
+
`payload`: `unknown`; `recovery?`: \{ `maxRecoveries`: ...; \}; `state`:
|
|
852
|
+
`"settled"`; `outcome`: `"failed"` \| `"completed"` \| `"interrupted"` \|
|
|
853
|
+
`"cancelled"` \| `"outcome_unknown"`; `failureReason?`: `string`; \};
|
|
854
|
+
`cancellation`: \| \{ `status`: `"absent"`; \} \| \{ `status`: `"present"`;
|
|
855
|
+
`cancellation`: \{ `jobId`: `string`; `cancellationId`: `string`;
|
|
856
|
+
`onlyIfQueued?`: ... \| ... \| ...; \}; \}; \} \| \{ `status`: `"missing"`; \},
|
|
857
|
+
[`WatchdogError`](index.md#watchdogerror)\>; `readQueueHead`: (`queue`) =>
|
|
858
|
+
`Effect`\< \| \{ `state`: `"idle"`; \} \| \{ `state`: `"running"` \| `"queued"`;
|
|
859
|
+
`jobId`: `string`; `cancellationRequested`: `boolean`; \},
|
|
860
|
+
[`WatchdogError`](index.md#watchdogerror)\>; `readSettled`: (`limit`,
|
|
861
|
+
`afterSequence?`) => `Effect`\<readonly `Readonly`\<\{ `sequence`: `number`;
|
|
862
|
+
`job`: \{ `jobId`: `string`; `queue`: `string`; `lane`: `string`; `priority`:
|
|
863
|
+
`number`; `payload`: `unknown`; `recovery?`: \{ `maxRecoveries`: ...; \};
|
|
864
|
+
`state`: `"settled"`; `outcome`: `"failed"` \| `"completed"` \| `"interrupted"`
|
|
865
|
+
\| `"cancelled"` \| `"outcome_unknown"`; `failureReason?`: `string`; \}; \}\>[],
|
|
866
|
+
[`WatchdogError`](index.md#watchdogerror)\>; `tick`: () =>
|
|
867
|
+
`Effect`\<[`WatchdogTickResult`](#watchdogtickresult),
|
|
868
|
+
[`WatchdogError`](index.md#watchdogerror)\>; `cancel`: (`input`) => `Effect`\<
|
|
869
|
+
\| \{ `status`: `"replayed"` \| `"recorded"`; \} \| \{ `status`: `"missing"` \|
|
|
870
|
+
`"conflict"`; \}, [`WatchdogError`](index.md#watchdogerror)\>; `failLane`:
|
|
871
|
+
(`input`) => `Effect`\<`Readonly`\<\{ `settled`: `number`; `more`: `boolean`;
|
|
872
|
+
\}\>, [`WatchdogError`](index.md#watchdogerror)\>; `purge`: (`queue`) =>
|
|
873
|
+
`Effect`\<`void`, [`WatchdogError`](index.md#watchdogerror)\>; `transactional`:
|
|
874
|
+
[`WatchdogTransactionalProjection`](#watchdogtransactionalprojection); \}\>,
|
|
875
|
+
[`WatchdogError`](index.md#watchdogerror)\>
|