@anatta.io/tva 0.0.0-stage → 0.2.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/README.md +50 -2
- package/dist/adapters/cloudflare/bindings.d.ts +10 -0
- package/dist/adapters/cloudflare/bindings.js +1 -0
- package/dist/adapters/cloudflare/blob-store.d.ts +39 -0
- package/dist/adapters/cloudflare/blob-store.js +95 -0
- package/dist/adapters/cloudflare/cache.d.ts +14 -0
- package/dist/adapters/cloudflare/cache.js +48 -0
- package/dist/adapters/cloudflare/faults.d.ts +7 -0
- package/dist/adapters/cloudflare/faults.js +39 -0
- package/dist/adapters/cloudflare/index.d.ts +15 -0
- package/dist/adapters/cloudflare/index.js +16 -0
- package/dist/adapters/cloudflare/journal.d.ts +110 -0
- package/dist/adapters/cloudflare/journal.js +325 -0
- package/dist/adapters/cloudflare/ledger.d.ts +14 -0
- package/dist/adapters/cloudflare/ledger.js +108 -0
- package/dist/adapters/cloudflare/logger.d.ts +22 -0
- package/dist/adapters/cloudflare/logger.js +49 -0
- package/dist/adapters/cloudflare/manifest.d.ts +81 -0
- package/dist/adapters/cloudflare/manifest.js +81 -0
- package/dist/adapters/cloudflare/pipelines.d.ts +97 -0
- package/dist/adapters/cloudflare/pipelines.js +218 -0
- package/dist/adapters/cloudflare/queue.d.ts +80 -0
- package/dist/adapters/cloudflare/queue.js +177 -0
- package/dist/adapters/cloudflare/retention.d.ts +24 -0
- package/dist/adapters/cloudflare/retention.js +103 -0
- package/dist/adapters/cloudflare/session-storage.d.ts +27 -0
- package/dist/adapters/cloudflare/session-storage.js +78 -0
- package/dist/adapters/cloudflare/toolkit.d.ts +16 -0
- package/dist/adapters/cloudflare/toolkit.js +57 -0
- package/dist/adapters/cloudflare/workflow-pipelines.d.ts +66 -0
- package/dist/adapters/cloudflare/workflow-pipelines.js +323 -0
- package/dist/adapters/journal-records.d.ts +80 -0
- package/dist/adapters/journal-records.js +75 -0
- package/dist/adapters/memory/blob-store.d.ts +9 -0
- package/dist/adapters/memory/blob-store.js +19 -0
- package/dist/adapters/memory/cache.d.ts +13 -0
- package/dist/adapters/memory/cache.js +36 -0
- package/dist/adapters/memory/clock.d.ts +1 -0
- package/dist/adapters/memory/clock.js +4 -0
- package/dist/adapters/memory/index.d.ts +11 -0
- package/dist/adapters/memory/index.js +11 -0
- package/dist/adapters/memory/journal.d.ts +35 -0
- package/dist/adapters/memory/journal.js +154 -0
- package/dist/adapters/memory/ledger.d.ts +9 -0
- package/dist/adapters/memory/ledger.js +33 -0
- package/dist/adapters/memory/logger.d.ts +16 -0
- package/dist/adapters/memory/logger.js +21 -0
- package/dist/adapters/memory/manifest.d.ts +59 -0
- package/dist/adapters/memory/manifest.js +59 -0
- package/dist/adapters/memory/pipelines.d.ts +62 -0
- package/dist/adapters/memory/pipelines.js +219 -0
- package/dist/adapters/memory/queue.d.ts +20 -0
- package/dist/adapters/memory/queue.js +102 -0
- package/dist/adapters/memory/session-storage.d.ts +20 -0
- package/dist/adapters/memory/session-storage.js +33 -0
- package/dist/adapters/memory/toolkit.d.ts +8 -0
- package/dist/adapters/memory/toolkit.js +31 -0
- package/dist/adapters/postgres/cache.d.ts +17 -0
- package/dist/adapters/postgres/cache.js +69 -0
- package/dist/adapters/postgres/config.d.ts +27 -0
- package/dist/adapters/postgres/config.js +45 -0
- package/dist/adapters/postgres/faults.d.ts +14 -0
- package/dist/adapters/postgres/faults.js +47 -0
- package/dist/adapters/postgres/index.d.ts +12 -0
- package/dist/adapters/postgres/index.js +12 -0
- package/dist/adapters/postgres/journal.d.ts +86 -0
- package/dist/adapters/postgres/journal.js +337 -0
- package/dist/adapters/postgres/ledger.d.ts +16 -0
- package/dist/adapters/postgres/ledger.js +97 -0
- package/dist/adapters/postgres/logger.d.ts +19 -0
- package/dist/adapters/postgres/logger.js +37 -0
- package/dist/adapters/postgres/manifest.d.ts +52 -0
- package/dist/adapters/postgres/manifest.js +53 -0
- package/dist/adapters/postgres/migrate.d.ts +20 -0
- package/dist/adapters/postgres/migrate.js +96 -0
- package/dist/adapters/postgres/queue.d.ts +64 -0
- package/dist/adapters/postgres/queue.js +333 -0
- package/dist/adapters/postgres/retention.d.ts +18 -0
- package/dist/adapters/postgres/retention.js +104 -0
- package/dist/adapters/postgres/session-storage.d.ts +20 -0
- package/dist/adapters/postgres/session-storage.js +71 -0
- package/dist/adapters/postgres/toolkit.d.ts +25 -0
- package/dist/adapters/postgres/toolkit.js +58 -0
- package/dist/adapters/postgres/with-client.d.ts +11 -0
- package/dist/adapters/postgres/with-client.js +29 -0
- package/dist/adapters/reference-executor.d.ts +171 -0
- package/dist/adapters/reference-executor.js +569 -0
- package/dist/adapters/retention.d.ts +18 -0
- package/dist/adapters/retention.js +13 -0
- package/dist/adapters/s3/blob-store.d.ts +35 -0
- package/dist/adapters/s3/blob-store.js +92 -0
- package/dist/adapters/s3/faults.d.ts +8 -0
- package/dist/adapters/s3/faults.js +34 -0
- package/dist/adapters/s3/index.d.ts +2 -0
- package/dist/adapters/s3/index.js +2 -0
- package/dist/adapters/session-envelope.d.ts +21 -0
- package/dist/adapters/session-envelope.js +122 -0
- package/dist/adapters/system-clock.d.ts +8 -0
- package/dist/adapters/system-clock.js +8 -0
- package/dist/contracts/blob-store.d.ts +11 -0
- package/dist/contracts/blob-store.js +1 -0
- package/dist/contracts/cache.d.ts +27 -0
- package/dist/contracts/cache.js +1 -0
- package/dist/contracts/duration.d.ts +23 -0
- package/dist/contracts/duration.js +27 -0
- package/dist/contracts/faults.d.ts +28 -0
- package/dist/contracts/faults.js +29 -0
- package/dist/contracts/identity.d.ts +12 -0
- package/dist/contracts/identity.js +1 -0
- package/dist/contracts/index.d.ts +14 -0
- package/dist/contracts/index.js +15 -0
- package/dist/contracts/instant.d.ts +17 -0
- package/dist/contracts/instant.js +12 -0
- package/dist/contracts/journal.d.ts +196 -0
- package/dist/contracts/journal.js +10 -0
- package/dist/contracts/ledger.d.ts +34 -0
- package/dist/contracts/ledger.js +1 -0
- package/dist/contracts/logger.d.ts +11 -0
- package/dist/contracts/logger.js +1 -0
- package/dist/contracts/manifest.d.ts +37 -0
- package/dist/contracts/manifest.js +30 -0
- package/dist/contracts/pipelines.d.ts +348 -0
- package/dist/contracts/pipelines.js +1 -0
- package/dist/contracts/queue.d.ts +55 -0
- package/dist/contracts/queue.js +1 -0
- package/dist/contracts/session-storage.d.ts +18 -0
- package/dist/contracts/session-storage.js +1 -0
- package/dist/contracts/toolkit.d.ts +21 -0
- package/dist/contracts/toolkit.js +1 -0
- package/dist/pipelines/index.d.ts +1 -0
- package/dist/pipelines/index.js +2 -0
- package/dist/pipelines/pipeline.d.ts +142 -0
- package/dist/pipelines/pipeline.js +140 -0
- package/dist/pipelines/use-case-step.d.ts +24 -0
- package/dist/pipelines/use-case-step.js +34 -0
- package/dist/schedule/schedule.d.ts +40 -0
- package/dist/schedule/schedule.js +135 -0
- package/dist/use-cases/index.d.ts +3 -0
- package/dist/use-cases/index.js +3 -0
- package/dist/use-cases/run-use-case.d.ts +33 -0
- package/dist/use-cases/run-use-case.js +117 -0
- package/dist/use-cases/use-case-consumer.d.ts +44 -0
- package/dist/use-cases/use-case-consumer.js +98 -0
- package/dist/use-cases/use-case.d.ts +116 -0
- package/dist/use-cases/use-case.js +75 -0
- package/dist/webhooks/create-webhook-handler.d.ts +63 -0
- package/dist/webhooks/create-webhook-handler.js +253 -0
- package/dist/webhooks/dead-letter-consumer.d.ts +14 -0
- package/dist/webhooks/dead-letter-consumer.js +42 -0
- package/dist/webhooks/define-registry.d.ts +42 -0
- package/dist/webhooks/define-registry.js +56 -0
- package/dist/webhooks/once.d.ts +15 -0
- package/dist/webhooks/once.js +29 -0
- package/dist/webhooks/redact-customer-bodies.d.ts +29 -0
- package/dist/webhooks/redact-customer-bodies.js +45 -0
- package/dist/webhooks/replay-webhooks.d.ts +39 -0
- package/dist/webhooks/replay-webhooks.js +82 -0
- package/dist/webhooks/sign-shopify-webhook.d.ts +14 -0
- package/dist/webhooks/sign-shopify-webhook.js +31 -0
- package/dist/webhooks/sweep-stuck-tasks.d.ts +32 -0
- package/dist/webhooks/sweep-stuck-tasks.js +73 -0
- package/dist/webhooks/webhook-consumer.d.ts +52 -0
- package/dist/webhooks/webhook-consumer.js +132 -0
- package/migrations/0001_create_ledger_claims.sql +23 -0
- package/migrations/0002_create_journal.sql +76 -0
- package/migrations/0003_create_shopify_sessions.sql +30 -0
- package/migrations/0004_create_journal_steps.sql +34 -0
- package/migrations/0007_create_job_tables.sql +71 -0
- package/migrations/0008_add_ledger_completed_at.sql +7 -0
- package/migrations/0009_create_webhook_receipts.sql +34 -0
- package/migrations/0010_index_webhook_deliveries_received_at.sql +2 -0
- package/migrations/0011_add_webhook_task_reason_code.sql +4 -0
- package/migrations/0012_rename_webhook_task_action_to_use_case.sql +11 -0
- package/migrations/0013_rename_job_tables_to_pipeline.sql +24 -0
- package/migrations/0016_add_webhook_task_requeues.sql +3 -0
- package/migrations/postgres/0001_create_ledger_claims.sql +13 -0
- package/migrations/postgres/0002_create_journal.sql +48 -0
- package/migrations/postgres/0003_create_shopify_sessions.sql +12 -0
- package/migrations/postgres/0004_create_journal_steps.sql +19 -0
- package/migrations/postgres/0005_create_cache_entries.sql +14 -0
- package/migrations/postgres/0006_create_queue.sql +42 -0
- package/migrations/postgres/0007_create_job_tables.sql +40 -0
- package/migrations/postgres/0008_add_ledger_completed_at.sql +3 -0
- package/migrations/postgres/0009_create_webhook_receipts.sql +23 -0
- package/migrations/postgres/0010_index_webhook_deliveries_received_at.sql +2 -0
- package/migrations/postgres/0011_add_webhook_task_reason_code.sql +3 -0
- package/migrations/postgres/0012_rename_webhook_task_action_to_use_case.sql +5 -0
- package/migrations/postgres/0013_rename_job_tables_to_pipeline.sql +22 -0
- package/migrations/postgres/0016_add_webhook_task_requeues.sql +3 -0
- package/package.json +144 -4
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { DeploymentIdentity } from './identity.js';
|
|
2
|
+
import type { Instant } from './instant.js';
|
|
3
|
+
/**
|
|
4
|
+
* The RUN JOURNAL. Distinct from the Ledger: this one is queryable, it is not on the
|
|
5
|
+
* correctness path, and it may be lossy under pressure without breaking anything.
|
|
6
|
+
* The one exception is webhook receipts, which are required writes: see below.
|
|
7
|
+
*
|
|
8
|
+
* Four grains. The UNIT is the grain an operator thinks in — they have an identifier
|
|
9
|
+
* and one question about it. A surface that makes them start from a run has failed.
|
|
10
|
+
*/
|
|
11
|
+
export type RunId = string;
|
|
12
|
+
export type UnitKey = string;
|
|
13
|
+
export type UnitOutcome = 'written' | 'skipped' | 'failed' | 'unchanged' | 'would-write';
|
|
14
|
+
export type RunRow = {
|
|
15
|
+
readonly runId: RunId;
|
|
16
|
+
readonly job: string;
|
|
17
|
+
readonly trigger: 'schedule' | 'http' | 'queue' | 'admin' | 'replay' | 'pipeline';
|
|
18
|
+
readonly mode: 'live' | 'dry-run';
|
|
19
|
+
readonly startedAt: Instant;
|
|
20
|
+
readonly identity: DeploymentIdentity;
|
|
21
|
+
};
|
|
22
|
+
export type UnitRow = {
|
|
23
|
+
readonly runId: RunId;
|
|
24
|
+
readonly unitKey: UnitKey;
|
|
25
|
+
readonly unitType: string;
|
|
26
|
+
/** When this unit reached its outcome. Every time-windowed query needs it. */
|
|
27
|
+
readonly recordedAt: Instant;
|
|
28
|
+
readonly outcome: UnitOutcome;
|
|
29
|
+
/** From the domain's closed list. Required on anything that is not a plain success. */
|
|
30
|
+
readonly reasonCode?: string;
|
|
31
|
+
/** Hash of the composed plan. Two runs, same hash, no work to do. */
|
|
32
|
+
readonly planHash?: string;
|
|
33
|
+
readonly planRef?: string;
|
|
34
|
+
readonly durationMs: number;
|
|
35
|
+
readonly externalIds?: Readonly<Record<string, string>>;
|
|
36
|
+
};
|
|
37
|
+
export type StepOutcome = 'ok' | 'retry' | 'failed' | 'superseded';
|
|
38
|
+
/**
|
|
39
|
+
* One attempt of one Pipeline step on one unit. The Step grain of plan §9.2.
|
|
40
|
+
*
|
|
41
|
+
* **A record, not state.** Nothing reads a step row to decide what runs next:
|
|
42
|
+
* the reference executor keeps its own step state, and Workflows keeps its
|
|
43
|
+
* own. This row may be lossy, like every journal row, and a missing one costs
|
|
44
|
+
* visibility, never correctness. `docs/decisions/0006`.
|
|
45
|
+
*
|
|
46
|
+
* It holds an outcome, never a step result. There is no field for one, so there
|
|
47
|
+
* is nothing to redact on the way in beyond what the caller puts in `step` and
|
|
48
|
+
* `reasonCode`, which come from code, not from a customer.
|
|
49
|
+
*/
|
|
50
|
+
export type StepRow = {
|
|
51
|
+
readonly runId: RunId;
|
|
52
|
+
readonly unitKey: UnitKey;
|
|
53
|
+
/** The step's name in its Pipeline definition. */
|
|
54
|
+
readonly step: string;
|
|
55
|
+
/** 1 for the first attempt. A retry writes a new row with the next number. */
|
|
56
|
+
readonly attempt: number;
|
|
57
|
+
/**
|
|
58
|
+
* `superseded`: another consumer committed this step first, so this
|
|
59
|
+
* attempt's result was discarded. Not a failure.
|
|
60
|
+
*/
|
|
61
|
+
readonly outcome: StepOutcome;
|
|
62
|
+
/** From the domain's closed list. Required on anything that is not `ok`. */
|
|
63
|
+
readonly reasonCode?: string;
|
|
64
|
+
readonly durationMs: number;
|
|
65
|
+
/** When this attempt ended. `unit` orders steps by it, then by write order. */
|
|
66
|
+
readonly recordedAt: Instant;
|
|
67
|
+
};
|
|
68
|
+
export type CallRow = {
|
|
69
|
+
readonly runId: RunId;
|
|
70
|
+
readonly unitKey: UnitKey;
|
|
71
|
+
readonly system: string;
|
|
72
|
+
/** Our name for the operation, never a URL. */
|
|
73
|
+
readonly operation: string;
|
|
74
|
+
readonly status: 'intent' | 'ok' | 'failed' | 'ambiguous';
|
|
75
|
+
readonly httpStatus?: number;
|
|
76
|
+
readonly idempotencyKey?: string;
|
|
77
|
+
readonly durationMs?: number;
|
|
78
|
+
};
|
|
79
|
+
export type ReasonCount = {
|
|
80
|
+
readonly reasonCode: string;
|
|
81
|
+
readonly count: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A webhook task: one use case's work on one delivery. `failed` means a retry is
|
|
85
|
+
* scheduled; `dead` means the retries ran out. A use case's non-retryable
|
|
86
|
+
* failure is `done`, and its unit row says why.
|
|
87
|
+
*/
|
|
88
|
+
export type TaskState = 'received' | 'processing' | 'done' | 'failed' | 'dead' | 'replayed';
|
|
89
|
+
/** The state a task moves to, and the states it may move from. `received` is only ever the first. */
|
|
90
|
+
export declare const TASK_TRANSITIONS: Readonly<Record<Exclude<TaskState, 'received'>, readonly TaskState[]>>;
|
|
91
|
+
/** One webhook delivery, as the edge accepted it. */
|
|
92
|
+
export type DeliveryRow = {
|
|
93
|
+
/** The edge's dedup key, `source:shop:topic:webhookId`. */
|
|
94
|
+
readonly deliveryId: string;
|
|
95
|
+
readonly source: string;
|
|
96
|
+
readonly topic: string;
|
|
97
|
+
readonly shop: string;
|
|
98
|
+
readonly webhookId: string;
|
|
99
|
+
/** The raw body's key in the blob store. */
|
|
100
|
+
readonly bodyKey: string;
|
|
101
|
+
readonly receivedAt: Instant;
|
|
102
|
+
};
|
|
103
|
+
export type TaskRow = {
|
|
104
|
+
readonly deliveryId: string;
|
|
105
|
+
/** The use case's name. */
|
|
106
|
+
readonly useCase: string;
|
|
107
|
+
readonly state: TaskState;
|
|
108
|
+
/** When the task last moved. */
|
|
109
|
+
readonly updatedAt: Instant;
|
|
110
|
+
/** Why it is `dead`: the use case's last retryable reason, `fault`, `dead-lettered` or `stuck`. Set by the move that set the state. */
|
|
111
|
+
readonly reasonCode?: string;
|
|
112
|
+
/** How many times the stuck-task sweeper re-sent it. A move to `replayed` resets it. */
|
|
113
|
+
readonly requeues: number;
|
|
114
|
+
};
|
|
115
|
+
/** Where `deadTasks` resumes: the last row of the previous page. */
|
|
116
|
+
export type TaskCursor = Pick<TaskRow, 'updatedAt' | 'deliveryId' | 'useCase'>;
|
|
117
|
+
/**
|
|
118
|
+
* Named queries only. No method takes SQL.
|
|
119
|
+
*
|
|
120
|
+
* One method per question the operator surface asks. A new screen means a new named
|
|
121
|
+
* query, which is a moment of review rather than an ad-hoc SELECT in a route.
|
|
122
|
+
*/
|
|
123
|
+
export interface Journal {
|
|
124
|
+
startRun(row: RunRow): Promise<void>;
|
|
125
|
+
finishRun(runId: RunId, endedAt: Instant): Promise<void>;
|
|
126
|
+
/** Batched per unit: one write, not one per step. */
|
|
127
|
+
recordUnit(unit: UnitRow, calls: readonly CallRow[]): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* One step row, written after each attempt. Deliberately not batched per
|
|
130
|
+
* unit: the step has already done its work, and a row held back for a batch
|
|
131
|
+
* is lost with the process that held it.
|
|
132
|
+
*
|
|
133
|
+
* **Never rejects.** A failed write is logged through `Logger` and the call
|
|
134
|
+
* resolves, because failing a step that already did its work would repeat the
|
|
135
|
+
* work to record it. This is the one journal write that does not fail the
|
|
136
|
+
* unit (plan §9.3, `docs/decisions/0006`).
|
|
137
|
+
*
|
|
138
|
+
* Append-only. A step row is never a correction, so writing the same row
|
|
139
|
+
* twice records it twice rather than merging it.
|
|
140
|
+
*
|
|
141
|
+
* There is no query that reads step rows back by Pipeline instance, and there must
|
|
142
|
+
* not be one: that would make the journal the executor's state store, which
|
|
143
|
+
* decision 0006 rejected. Step rows are read only through `unit`.
|
|
144
|
+
*/
|
|
145
|
+
recordStep(step: StepRow): Promise<void>;
|
|
146
|
+
unitsForRun(runId: RunId, limit?: number): Promise<readonly UnitRow[]>;
|
|
147
|
+
/**
|
|
148
|
+
* The unit with its steps, oldest attempt first, and its calls.
|
|
149
|
+
*
|
|
150
|
+
* Undefined until the unit row is recorded, even when step rows exist: the
|
|
151
|
+
* unit row is what says a unit exists. Re-recording a unit replaces its calls
|
|
152
|
+
* and leaves its steps alone, because they were written by other attempts.
|
|
153
|
+
*/
|
|
154
|
+
unit(runId: RunId, unitKey: UnitKey): Promise<{
|
|
155
|
+
unit: UnitRow;
|
|
156
|
+
steps: readonly StepRow[];
|
|
157
|
+
calls: readonly CallRow[];
|
|
158
|
+
} | undefined>;
|
|
159
|
+
latestForUnit(unitKey: UnitKey): Promise<UnitRow | undefined>;
|
|
160
|
+
failuresByReason(since: Instant): Promise<readonly ReasonCount[]>;
|
|
161
|
+
recentRuns(limit?: number): Promise<readonly RunRow[]>;
|
|
162
|
+
/**
|
|
163
|
+
* The delivery and one `received` task per use case, in one atomic write.
|
|
164
|
+
* Recording it again, as a retried delivery does, changes no row already
|
|
165
|
+
* there: it adds only the tasks it lacks.
|
|
166
|
+
*/
|
|
167
|
+
recordDelivery(delivery: DeliveryRow, useCases: readonly string[]): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Moves a task to `to` only from a state `TASK_TRANSITIONS` allows, in one
|
|
170
|
+
* conditional update. False when the task is in another state or missing.
|
|
171
|
+
* Writes `reasonCode`, or clears it when absent: a reason describes the
|
|
172
|
+
* state it came with.
|
|
173
|
+
*/
|
|
174
|
+
moveTask(deliveryId: string, useCase: string, to: Exclude<TaskState, 'received'>, at: Instant, reasonCode?: string): Promise<boolean>;
|
|
175
|
+
/** The delivery with its tasks, by use case name. */
|
|
176
|
+
delivery(deliveryId: string): Promise<{
|
|
177
|
+
delivery: DeliveryRow;
|
|
178
|
+
tasks: readonly TaskRow[];
|
|
179
|
+
} | undefined>;
|
|
180
|
+
/** Dead tasks, oldest first, keyset-paged by `after`. */
|
|
181
|
+
deadTasks(options?: {
|
|
182
|
+
readonly useCase?: string;
|
|
183
|
+
readonly after?: TaskCursor;
|
|
184
|
+
readonly limit?: number;
|
|
185
|
+
}): Promise<readonly TaskRow[]>;
|
|
186
|
+
/** Tasks still `received`, `processing` or `replayed` that last moved before `before`, oldest first. */
|
|
187
|
+
stuckTasks(before: Instant, limit?: number): Promise<readonly TaskRow[]>;
|
|
188
|
+
/**
|
|
189
|
+
* Claims a task `stuckTasks` returned, in one conditional write: only while
|
|
190
|
+
* it is still stuck and last moved at `task.updatedAt`, so of two sweepers
|
|
191
|
+
* that read it, one wins. `requeued` keeps its state, sets `updatedAt` to
|
|
192
|
+
* `at` and counts one more requeue; `dead` makes it `dead` with reason
|
|
193
|
+
* `stuck`. False when the task moved since it was read.
|
|
194
|
+
*/
|
|
195
|
+
reclaimStuckTask(task: Pick<TaskRow, 'deliveryId' | 'useCase' | 'updatedAt'>, at: Instant, to: 'requeued' | 'dead'): Promise<boolean>;
|
|
196
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The state a task moves to, and the states it may move from. `received` is only ever the first. */
|
|
2
|
+
export const TASK_TRANSITIONS = {
|
|
3
|
+
// From `processing` too: a queue redelivers after a consumer crashed mid-run.
|
|
4
|
+
// From `replayed`: a replay sends the message again, and it runs as any other.
|
|
5
|
+
processing: ['received', 'failed', 'processing', 'replayed'],
|
|
6
|
+
done: ['processing'],
|
|
7
|
+
failed: ['processing'],
|
|
8
|
+
dead: ['processing'],
|
|
9
|
+
replayed: ['dead'],
|
|
10
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type ClaimResult = {
|
|
2
|
+
readonly status: 'claimed';
|
|
3
|
+
}
|
|
4
|
+
/** Another holder's lease is live and it has not completed. */
|
|
5
|
+
| {
|
|
6
|
+
readonly status: 'in-progress';
|
|
7
|
+
readonly claimedAt: string;
|
|
8
|
+
} | {
|
|
9
|
+
readonly status: 'completed';
|
|
10
|
+
readonly completedAt: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Idempotency. Key plus conditional write, and NOTHING else.
|
|
14
|
+
*
|
|
15
|
+
* There is no get(), no list(), no query. Adding one turns this into the run journal,
|
|
16
|
+
* which is a different store with a different access pattern and a different
|
|
17
|
+
* portability story. Use Journal for that.
|
|
18
|
+
*
|
|
19
|
+
* Claim, act, complete. A claim is a short lease; a holder that dies before
|
|
20
|
+
* `complete` lets the key be claimed again once the lease ends, instead of
|
|
21
|
+
* holding it for the long TTL with the work never done.
|
|
22
|
+
*/
|
|
23
|
+
export interface Ledger {
|
|
24
|
+
claim(key: string, leaseSeconds: number): Promise<ClaimResult>;
|
|
25
|
+
/** Marks the work done. The key stays claimed for `ttlSeconds` from now. */
|
|
26
|
+
complete(key: string, ttlSeconds: number): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Frees the key now, instead of when the lease ends. Throws on a fault like
|
|
29
|
+
* every other method. A failed release needs no recovery: the key frees
|
|
30
|
+
* itself when the lease ends. A caller already handling an error should not
|
|
31
|
+
* let a release fault replace it.
|
|
32
|
+
*/
|
|
33
|
+
release(key: string): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DeploymentIdentity } from './identity.js';
|
|
2
|
+
export type LogFields = Readonly<Record<string, string | number | boolean | null>>;
|
|
3
|
+
/** Structured only. A correlation id and the deployment identity are required, by type. */
|
|
4
|
+
export interface Logger {
|
|
5
|
+
readonly identity: DeploymentIdentity;
|
|
6
|
+
readonly correlationId: string;
|
|
7
|
+
info(message: string, fields?: LogFields): void;
|
|
8
|
+
warn(message: string, fields?: LogFields): void;
|
|
9
|
+
error(message: string, fields?: LogFields): void;
|
|
10
|
+
child(correlationId: string): Logger;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Weakest to strongest. The array order IS the ranking. */
|
|
2
|
+
export declare const LOCK_GUARANTEES: readonly ["none", "advisory", "strict-partitioned", "strict"];
|
|
3
|
+
export type LockGuarantee = (typeof LOCK_GUARANTEES)[number];
|
|
4
|
+
/** What a target provides. Every adapter exports one. */
|
|
5
|
+
export type ToolManifest = {
|
|
6
|
+
readonly lock: LockGuarantee;
|
|
7
|
+
readonly lockFencing: boolean;
|
|
8
|
+
readonly queueDelayMaxSeconds: number;
|
|
9
|
+
readonly messageMaxBytes: number;
|
|
10
|
+
readonly blobMaxBytes: number;
|
|
11
|
+
readonly cacheMinTtlSeconds: number;
|
|
12
|
+
/**
|
|
13
|
+
* The largest step result a Pipelines executor stores, in bytes of the result's
|
|
14
|
+
* JSON encoding as UTF-8. The executor checks it when a step returns, before
|
|
15
|
+
* the result is stored or handed to the platform, and rejects a larger one
|
|
16
|
+
* with `LimitExceeded` (rule 7). The step then fails terminally, with no
|
|
17
|
+
* retry, because the same input produces the same result. A Pipeline's exhaustion
|
|
18
|
+
* handler sees the cause `result-too-large`.
|
|
19
|
+
*/
|
|
20
|
+
readonly stepResultMaxBytes: number;
|
|
21
|
+
readonly journalDialect: 'sqlite' | 'postgres';
|
|
22
|
+
readonly scheduleTimezone: 'native' | 'resolved-in-code';
|
|
23
|
+
/** The shortest interval `defineSchedule` accepts on this target, in seconds. */
|
|
24
|
+
readonly scheduleMinIntervalSeconds: number;
|
|
25
|
+
};
|
|
26
|
+
/** What a trigger, a topic or a job needs. Checked against the manifest before deploy. */
|
|
27
|
+
export type Requirements = Partial<{
|
|
28
|
+
readonly lock: LockGuarantee;
|
|
29
|
+
readonly lockFencing: true;
|
|
30
|
+
readonly queueDelayMaxSeconds: number;
|
|
31
|
+
}>;
|
|
32
|
+
export type Unmet = {
|
|
33
|
+
readonly requirement: keyof Requirements;
|
|
34
|
+
readonly required: string;
|
|
35
|
+
readonly provided: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function satisfies(m: ToolManifest, r: Requirements): readonly Unmet[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Weakest to strongest. The array order IS the ranking. */
|
|
2
|
+
export const LOCK_GUARANTEES = [
|
|
3
|
+
'none',
|
|
4
|
+
'advisory',
|
|
5
|
+
'strict-partitioned',
|
|
6
|
+
'strict',
|
|
7
|
+
];
|
|
8
|
+
const lockRank = (g) => LOCK_GUARANTEES.indexOf(g);
|
|
9
|
+
export function satisfies(m, r) {
|
|
10
|
+
const unmet = [];
|
|
11
|
+
if (r.lock !== undefined && lockRank(m.lock) < lockRank(r.lock)) {
|
|
12
|
+
unmet.push({ requirement: 'lock', required: r.lock, provided: m.lock });
|
|
13
|
+
}
|
|
14
|
+
if (r.lockFencing === true && !m.lockFencing) {
|
|
15
|
+
unmet.push({
|
|
16
|
+
requirement: 'lockFencing',
|
|
17
|
+
required: 'true',
|
|
18
|
+
provided: 'false',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (r.queueDelayMaxSeconds !== undefined &&
|
|
22
|
+
m.queueDelayMaxSeconds < r.queueDelayMaxSeconds) {
|
|
23
|
+
unmet.push({
|
|
24
|
+
requirement: 'queueDelayMaxSeconds',
|
|
25
|
+
required: String(r.queueDelayMaxSeconds),
|
|
26
|
+
provided: String(m.queueDelayMaxSeconds),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return unmet;
|
|
30
|
+
}
|