durability 5.0.0 → 5.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 +238 -7
- package/dist/{durability-alarms.d.ts → alarms/index.d.ts} +23 -6
- package/dist/{durability-alarms.js → alarms/index.js} +96 -52
- package/dist/alarms/migrations.d.ts +9 -0
- package/dist/alarms/migrations.js +133 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +24 -0
- package/dist/experimental.d.ts +11 -8
- package/dist/experimental.js +8 -5
- package/dist/{fanout.d.ts → fanout/index.d.ts} +13 -6
- package/dist/{fanout.js → fanout/index.js} +55 -49
- package/dist/fanout/migrations.d.ts +9 -0
- package/dist/fanout/migrations.js +181 -0
- package/dist/{stored-message.d.ts → fanout/stored-message.d.ts} +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +13 -8
- package/dist/{log.d.ts → log/index.d.ts} +15 -3
- package/dist/{log.js → log/index.js} +152 -124
- package/dist/log/migrations.d.ts +18 -0
- package/dist/log/migrations.js +297 -0
- package/dist/{memoize.d.ts → memoize/index.d.ts} +1 -1
- package/dist/{memoize.js → memoize/index.js} +14 -11
- package/dist/memoize/migrations.d.ts +10 -0
- package/dist/memoize/migrations.js +21 -0
- package/dist/migrations.d.ts +1 -103
- package/dist/migrations.js +1 -570
- package/dist/{durability.d.ts → operations/index.d.ts} +13 -5
- package/dist/{durability.js → operations/index.js} +63 -46
- package/dist/operations/migrations.d.ts +10 -0
- package/dist/operations/migrations.js +150 -0
- package/dist/{outbox.d.ts → outbox/index.d.ts} +4 -4
- package/dist/{outbox.js → outbox/index.js} +18 -63
- package/dist/outbox/migrations.d.ts +9 -0
- package/dist/outbox/migrations.js +43 -0
- package/dist/{routing-client.js → routing/client.js} +1 -1
- package/dist/{routing.d.ts → routing/index.d.ts} +3 -3
- package/dist/{routing.js → routing/index.js} +3 -3
- package/dist/{load.d.ts → routing/load.d.ts} +1 -1
- package/dist/schedule/index.d.ts +165 -0
- package/dist/schedule/index.js +667 -0
- package/dist/schedule/migrations.d.ts +9 -0
- package/dist/schedule/migrations.js +118 -0
- package/dist/{scheduler.d.ts → scheduler/index.d.ts} +122 -22
- package/dist/scheduler/index.js +925 -0
- package/dist/{semaphore-client.d.ts → semaphore/client.d.ts} +1 -1
- package/dist/{semaphore-client.js → semaphore/client.js} +2 -2
- package/dist/{semaphore.d.ts → semaphore/index.d.ts} +10 -10
- package/dist/{semaphore.js → semaphore/index.js} +7 -7
- package/dist/{semaphore-leases.d.ts → semaphore/leases.d.ts} +17 -6
- package/dist/{semaphore-leases.js → semaphore/leases.js} +28 -12
- package/dist/semaphore/migrations.d.ts +18 -0
- package/dist/semaphore/migrations.js +444 -0
- package/dist/{semaphore-protocol.d.ts → semaphore/protocol.d.ts} +16 -8
- package/dist/{semaphore-protocol.js → semaphore/protocol.js} +37 -14
- package/dist/{semaphore-queue-store.d.ts → semaphore/queue-store.d.ts} +12 -6
- package/dist/{semaphore-queue-store.js → semaphore/queue-store.js} +87 -75
- package/dist/{semaphore-queue.d.ts → semaphore/queue.d.ts} +15 -5
- package/dist/{semaphore-queue.js → semaphore/queue.js} +105 -46
- package/dist/{semaphore-server.d.ts → semaphore/server.d.ts} +12 -4
- package/dist/{semaphore-server.js → semaphore/server.js} +51 -24
- package/dist/{semaphore-store.d.ts → semaphore/store.d.ts} +8 -3
- package/dist/{semaphore-store.js → semaphore/store.js} +35 -33
- package/dist/{client.d.ts → socket/client.d.ts} +3 -3
- package/dist/{client.js → socket/client.js} +4 -4
- package/dist/{socket.d.ts → socket/index.d.ts} +15 -4
- package/dist/{socket.js → socket/index.js} +66 -20
- package/dist/socket/migrations.d.ts +9 -0
- package/dist/socket/migrations.js +57 -0
- package/dist/{socket-protocol.d.ts → socket/protocol.d.ts} +1 -1
- package/dist/storage.d.ts +9 -2
- package/dist/storage.js +24 -11
- package/dist/{topology-client.d.ts → topology/client.d.ts} +2 -2
- package/dist/{topology-client.js → topology/client.js} +3 -3
- package/dist/{topology.d.ts → topology/index.d.ts} +17 -7
- package/dist/{topology.js → topology/index.js} +92 -58
- package/dist/topology/migrations.d.ts +10 -0
- package/dist/topology/migrations.js +138 -0
- package/dist/{tracker.d.ts → tracker/index.d.ts} +3 -3
- package/dist/{tracker.js → tracker/index.js} +2 -2
- package/package.json +11 -11
- package/dist/scheduler.js +0 -577
- /package/dist/{stored-message.js → fanout/stored-message.js} +0 -0
- /package/dist/{routing-client.d.ts → routing/client.d.ts} +0 -0
- /package/dist/{load.js → routing/load.js} +0 -0
- /package/dist/{socket-protocol.js → socket/protocol.js} +0 -0
- /package/dist/{topology-snapshot.d.ts → topology/snapshot.d.ts} +0 -0
- /package/dist/{topology-snapshot.js → topology/snapshot.js} +0 -0
- /package/dist/{tracked-source.d.ts → tracker/source.d.ts} +0 -0
- /package/dist/{tracked-source.js → tracker/source.js} +0 -0
|
@@ -9,19 +9,22 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _DurabilityAlarmsCore_instances, _DurabilityAlarmsCore_engine, _DurabilityAlarmsCore_handlers, _DurabilityAlarmsCore_policy, _DurabilityAlarmsCore_lifecycle, _DurabilityAlarmsCore_emit, _DurabilityAlarmsCore_active, _DurabilityAlarmsCore_trackedSource, _DurabilityAlarmsCore_runDue, _DurabilityAlarmsCore_schedule, _DurabilityAlarmsCore_execute;
|
|
12
|
+
var _DurabilityAlarmsCore_instances, _DurabilityAlarmsCore_engine, _DurabilityAlarmsCore_channel, _DurabilityAlarmsCore_table, _DurabilityAlarmsCore_handlers, _DurabilityAlarmsCore_policy, _DurabilityAlarmsCore_lifecycle, _DurabilityAlarmsCore_emit, _DurabilityAlarmsCore_active, _DurabilityAlarmsCore_trackedSource, _DurabilityAlarmsCore_runDue, _DurabilityAlarmsCore_schedule, _DurabilityAlarmsCore_cancel, _DurabilityAlarmsCore_execute;
|
|
13
13
|
import { z } from 'zod';
|
|
14
|
-
import { traceFunction, traceMethods } from '
|
|
15
|
-
import { DurableAlarmTimeoutError, DurableAttemptsExhaustedError, isErrorInstance, NonRetryableError, } from '
|
|
16
|
-
import { createLifecycleHooks, } from '
|
|
17
|
-
import { durabilityNamedAlarmMigrations
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
14
|
+
import { traceFunction, traceMethods } from '../dev.js';
|
|
15
|
+
import { DurableAlarmTimeoutError, DurableAttemptsExhaustedError, isErrorInstance, NonRetryableError, } from '../errors.js';
|
|
16
|
+
import { createLifecycleHooks, } from '../lifecycle.js';
|
|
17
|
+
import { durabilityNamedAlarmMigrations } from './migrations.js';
|
|
18
|
+
import { durabilityMemoMigrations } from '../memoize/migrations.js';
|
|
19
|
+
import { migrateCapability, } from '../migrations.js';
|
|
20
|
+
import { alarmMethodOptionsSchema, createPolicyResolver, } from '../policy.js';
|
|
21
|
+
import { assertChannel, defaultChannel, engineFor, } from '../scheduler/index.js';
|
|
22
|
+
import { createMemoize, deleteMemos, deleteMemosOfDroppedTable, memoizedKeys, } from '../memoize/index.js';
|
|
23
|
+
import { deleteAttempt, listCreated } from '../storage.js';
|
|
24
|
+
import { registerTrackedSource, } from '../tracker/source.js';
|
|
23
25
|
const alarmRowSchema = z.object({
|
|
24
26
|
name: z.string(),
|
|
27
|
+
channel: z.string(),
|
|
25
28
|
generation_id: z.string(),
|
|
26
29
|
status: z.enum(['pending', 'failed']),
|
|
27
30
|
scheduled_at: z.number().int().nonnegative(),
|
|
@@ -33,10 +36,10 @@ const alarmRowSchema = z.object({
|
|
|
33
36
|
});
|
|
34
37
|
const alarmsTable = { name: 'durability_alarms', key: 'name' };
|
|
35
38
|
const alarmHandlerSchema = z.custom((value) => typeof value === 'function');
|
|
36
|
-
const readAlarm = (sql, name) => alarmRowSchema
|
|
39
|
+
const readAlarm = (sql, channel, name) => alarmRowSchema
|
|
37
40
|
.optional()
|
|
38
41
|
.parse(sql
|
|
39
|
-
.exec('SELECT * FROM durability_alarms WHERE name = ?', name)
|
|
42
|
+
.exec('SELECT * FROM durability_alarms WHERE channel = ? AND name = ?', channel, name)
|
|
40
43
|
.toArray()[0]);
|
|
41
44
|
const alarmRecord = (sql, row) => ({
|
|
42
45
|
id: row.name,
|
|
@@ -49,7 +52,7 @@ const alarmRecord = (sql, row) => ({
|
|
|
49
52
|
attempt: row.attempt,
|
|
50
53
|
nextAttemptAt: row.next_attempt_at,
|
|
51
54
|
lastError: row.last_error,
|
|
52
|
-
memoized: memoizedKeys(sql, alarmsTable, row.name, row.generation_id),
|
|
55
|
+
memoized: memoizedKeys(sql, { ...alarmsTable, channel: row.channel }, row.name, row.generation_id),
|
|
53
56
|
}
|
|
54
57
|
: {
|
|
55
58
|
status: 'failed',
|
|
@@ -70,11 +73,15 @@ class DurabilityAlarmsCore {
|
|
|
70
73
|
constructor(config) {
|
|
71
74
|
_DurabilityAlarmsCore_instances.add(this);
|
|
72
75
|
_DurabilityAlarmsCore_engine.set(this, void 0);
|
|
76
|
+
_DurabilityAlarmsCore_channel.set(this, void 0);
|
|
77
|
+
_DurabilityAlarmsCore_table.set(this, void 0);
|
|
73
78
|
_DurabilityAlarmsCore_handlers.set(this, void 0);
|
|
74
79
|
_DurabilityAlarmsCore_policy.set(this, void 0);
|
|
75
80
|
_DurabilityAlarmsCore_lifecycle.set(this, void 0);
|
|
76
81
|
_DurabilityAlarmsCore_emit.set(this, void 0);
|
|
77
82
|
_DurabilityAlarmsCore_active.set(this, new Map());
|
|
83
|
+
__classPrivateFieldSet(this, _DurabilityAlarmsCore_channel, assertChannel('DurabilityAlarms', config.channel ?? defaultChannel), "f");
|
|
84
|
+
__classPrivateFieldSet(this, _DurabilityAlarmsCore_table, { ...alarmsTable, channel: __classPrivateFieldGet(this, _DurabilityAlarmsCore_channel, "f") }, "f");
|
|
78
85
|
__classPrivateFieldSet(this, _DurabilityAlarmsCore_engine, engineFor(config), "f");
|
|
79
86
|
__classPrivateFieldSet(this, _DurabilityAlarmsCore_handlers, new Map(Object.entries(config.handlers).map(([name, handler]) => [name, alarmHandlerSchema.parse(handler)])), "f");
|
|
80
87
|
__classPrivateFieldSet(this, _DurabilityAlarmsCore_policy, createPolicyResolver(config, config.methods ?? {}, alarmMethodOptionsSchema), "f");
|
|
@@ -85,15 +92,20 @@ class DurabilityAlarmsCore {
|
|
|
85
92
|
if (reserved.has(name)) {
|
|
86
93
|
throw new Error(`"${name}" is reserved by DurabilityAlarms`);
|
|
87
94
|
}
|
|
95
|
+
const method = Object.assign(traceFunction(`DurabilityAlarms.${name}`, (scheduledTime) => __classPrivateFieldGet(this, _DurabilityAlarmsCore_instances, "m", _DurabilityAlarmsCore_schedule).call(this, name, scheduledTime)), {
|
|
96
|
+
cancel: traceFunction(`DurabilityAlarms.${name}.cancel`, () => __classPrivateFieldGet(this, _DurabilityAlarmsCore_instances, "m", _DurabilityAlarmsCore_cancel).call(this, name)),
|
|
97
|
+
});
|
|
88
98
|
Object.defineProperty(this, name, {
|
|
89
|
-
value:
|
|
99
|
+
value: method,
|
|
90
100
|
enumerable: true,
|
|
91
101
|
});
|
|
92
102
|
}
|
|
93
103
|
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").migrateSchema('namedAlarms', durabilityNamedAlarmMigrations);
|
|
94
104
|
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").migrateSchema('memos', durabilityMemoMigrations);
|
|
95
|
-
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").
|
|
96
|
-
table:
|
|
105
|
+
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").registerChannel({
|
|
106
|
+
table: __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"),
|
|
107
|
+
channel: __classPrivateFieldGet(this, _DurabilityAlarmsCore_channel, "f"),
|
|
108
|
+
helper: 'DurabilityAlarms',
|
|
97
109
|
runDue: (now, info) => __classPrivateFieldGet(this, _DurabilityAlarmsCore_instances, "m", _DurabilityAlarmsCore_runDue).call(this, now, info),
|
|
98
110
|
});
|
|
99
111
|
registerTrackedSource(this, __classPrivateFieldGet(this, _DurabilityAlarmsCore_instances, "m", _DurabilityAlarmsCore_trackedSource).call(this));
|
|
@@ -120,7 +132,7 @@ class DurabilityAlarmsCore {
|
|
|
120
132
|
* timestamp, regardless of status, and returns how many were removed.
|
|
121
133
|
*/
|
|
122
134
|
async purgeBefore(before) {
|
|
123
|
-
const count = await __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").purge(
|
|
135
|
+
const count = await __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").purge(__classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), before, __classPrivateFieldGet(this, _DurabilityAlarmsCore_active, "f"), 'Durable alarm was purged');
|
|
124
136
|
__classPrivateFieldGet(this, _DurabilityAlarmsCore_emit, "f").call(this, {
|
|
125
137
|
type: 'purged',
|
|
126
138
|
entityKind: 'named_alarm',
|
|
@@ -131,15 +143,15 @@ class DurabilityAlarmsCore {
|
|
|
131
143
|
return count;
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
|
-
_DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_handlers = new WeakMap(), _DurabilityAlarmsCore_policy = new WeakMap(), _DurabilityAlarmsCore_lifecycle = new WeakMap(), _DurabilityAlarmsCore_emit = new WeakMap(), _DurabilityAlarmsCore_active = new WeakMap(), _DurabilityAlarmsCore_instances = new WeakSet(), _DurabilityAlarmsCore_trackedSource = function _DurabilityAlarmsCore_trackedSource() {
|
|
146
|
+
_DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_channel = new WeakMap(), _DurabilityAlarmsCore_table = new WeakMap(), _DurabilityAlarmsCore_handlers = new WeakMap(), _DurabilityAlarmsCore_policy = new WeakMap(), _DurabilityAlarmsCore_lifecycle = new WeakMap(), _DurabilityAlarmsCore_emit = new WeakMap(), _DurabilityAlarmsCore_active = new WeakMap(), _DurabilityAlarmsCore_instances = new WeakSet(), _DurabilityAlarmsCore_trackedSource = function _DurabilityAlarmsCore_trackedSource() {
|
|
135
147
|
const sql = __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").sql;
|
|
136
148
|
return {
|
|
137
149
|
get: async (name) => {
|
|
138
|
-
const row = readAlarm(sql, name);
|
|
150
|
+
const row = readAlarm(sql, __classPrivateFieldGet(this, _DurabilityAlarmsCore_channel, "f"), name);
|
|
139
151
|
return row && alarmRecord(sql, row);
|
|
140
152
|
},
|
|
141
153
|
list: async ({ limit, cursor, status, name }) => {
|
|
142
|
-
const page = listCreated(sql,
|
|
154
|
+
const page = listCreated(sql, __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), 'name', {
|
|
143
155
|
limit,
|
|
144
156
|
after: cursor,
|
|
145
157
|
status,
|
|
@@ -153,29 +165,36 @@ _DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_handlers = n
|
|
|
153
165
|
? { records }
|
|
154
166
|
: { records, cursor: page.next };
|
|
155
167
|
},
|
|
156
|
-
watch: (name, listener) =>
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
watch: (name, listener) => {
|
|
169
|
+
return __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").watch(__classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), name, (completed) => {
|
|
170
|
+
if (!completed) {
|
|
171
|
+
listener();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
listener({
|
|
175
|
+
id: name,
|
|
176
|
+
name,
|
|
177
|
+
generation: completed.generation_id,
|
|
178
|
+
createdAt: completed.created_at,
|
|
179
|
+
state: { status: 'completed', result: undefined },
|
|
180
|
+
});
|
|
167
181
|
});
|
|
168
|
-
}
|
|
182
|
+
},
|
|
169
183
|
};
|
|
170
184
|
}, _DurabilityAlarmsCore_runDue = async function _DurabilityAlarmsCore_runDue(now, info) {
|
|
171
185
|
const due = alarmRowSchema.array().parse(__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").sql
|
|
172
186
|
.exec(`SELECT * FROM durability_alarms
|
|
173
|
-
WHERE status = 'pending' AND next_attempt_at <= ?
|
|
187
|
+
WHERE channel = ? AND status = 'pending' AND next_attempt_at <= ?
|
|
174
188
|
ORDER BY next_attempt_at ASC
|
|
175
|
-
LIMIT 100`, now)
|
|
189
|
+
LIMIT 100`, __classPrivateFieldGet(this, _DurabilityAlarmsCore_channel, "f"), now)
|
|
176
190
|
.toArray());
|
|
191
|
+
// With liveTimers a running occurrence re-arms itself when it settles, so
|
|
192
|
+
// skipping it keeps a long handler from blocking a concurrent alarm pass.
|
|
193
|
+
const pending = __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").liveTimers
|
|
194
|
+
? due.filter((row) => !__classPrivateFieldGet(this, _DurabilityAlarmsCore_active, "f").has(row.name))
|
|
195
|
+
: due;
|
|
177
196
|
const failures = [];
|
|
178
|
-
await __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").runConcurrent(
|
|
197
|
+
await __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").runConcurrent(pending, async (row) => {
|
|
179
198
|
try {
|
|
180
199
|
await __classPrivateFieldGet(this, _DurabilityAlarmsCore_instances, "m", _DurabilityAlarmsCore_execute).call(this, row, info);
|
|
181
200
|
}
|
|
@@ -190,14 +209,15 @@ _DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_handlers = n
|
|
|
190
209
|
if (!Number.isSafeInteger(scheduledTime) || scheduledTime < 0) {
|
|
191
210
|
throw new RangeError('scheduledTime must be a non-negative safe integer');
|
|
192
211
|
}
|
|
212
|
+
const key = name;
|
|
193
213
|
const generation = crypto.randomUUID();
|
|
194
214
|
const createdAt = Date.now();
|
|
195
215
|
await __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").transaction((sql) => {
|
|
196
216
|
sql.exec(`INSERT INTO durability_alarms
|
|
197
|
-
(name, generation_id, status, scheduled_at,
|
|
198
|
-
attempt, last_error, last_error_name, created_at)
|
|
199
|
-
VALUES (?, ?, 'pending', ?, ?, 0, NULL, NULL, ?)
|
|
200
|
-
ON CONFLICT(name) DO UPDATE SET
|
|
217
|
+
(name, channel, generation_id, status, scheduled_at,
|
|
218
|
+
next_attempt_at, attempt, last_error, last_error_name, created_at)
|
|
219
|
+
VALUES (?, ?, ?, 'pending', ?, ?, 0, NULL, NULL, ?)
|
|
220
|
+
ON CONFLICT(channel, name) DO UPDATE SET
|
|
201
221
|
generation_id = excluded.generation_id,
|
|
202
222
|
status = excluded.status,
|
|
203
223
|
scheduled_at = excluded.scheduled_at,
|
|
@@ -205,12 +225,12 @@ _DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_handlers = n
|
|
|
205
225
|
attempt = excluded.attempt,
|
|
206
226
|
last_error = excluded.last_error,
|
|
207
227
|
last_error_name = excluded.last_error_name,
|
|
208
|
-
created_at = excluded.created_at`,
|
|
228
|
+
created_at = excluded.created_at`, key, __classPrivateFieldGet(this, _DurabilityAlarmsCore_channel, "f"), generation, scheduledTime, scheduledTime, createdAt);
|
|
209
229
|
// Memoized results belong to the replaced occurrence, never to the new one.
|
|
210
|
-
deleteMemos(sql,
|
|
230
|
+
deleteMemos(sql, __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), key);
|
|
211
231
|
});
|
|
212
232
|
// A waiter on the replaced occurrence resolves now instead of at its timeout.
|
|
213
|
-
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").notify(
|
|
233
|
+
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").notify(__classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), key);
|
|
214
234
|
__classPrivateFieldGet(this, _DurabilityAlarmsCore_emit, "f").call(this, {
|
|
215
235
|
type: 'scheduled',
|
|
216
236
|
entityKind: 'named_alarm',
|
|
@@ -221,38 +241,62 @@ _DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_handlers = n
|
|
|
221
241
|
attempt: 0,
|
|
222
242
|
scheduledTime,
|
|
223
243
|
});
|
|
244
|
+
}, _DurabilityAlarmsCore_cancel = async function _DurabilityAlarmsCore_cancel(name) {
|
|
245
|
+
const key = name;
|
|
246
|
+
const cancelled = await __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").transaction((sql) => {
|
|
247
|
+
const removed = sql
|
|
248
|
+
.exec(`DELETE FROM durability_alarms
|
|
249
|
+
WHERE channel = ? AND name = ? AND status = 'pending'
|
|
250
|
+
RETURNING name`, __classPrivateFieldGet(this, _DurabilityAlarmsCore_channel, "f"), key)
|
|
251
|
+
.toArray().length > 0;
|
|
252
|
+
if (removed) {
|
|
253
|
+
deleteMemos(sql, __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), key);
|
|
254
|
+
}
|
|
255
|
+
return removed;
|
|
256
|
+
});
|
|
257
|
+
if (!cancelled) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
// Every settlement write is conditional on the deleted row, so a running
|
|
261
|
+
// attempt can no longer retry; abort it as purging does.
|
|
262
|
+
__classPrivateFieldGet(this, _DurabilityAlarmsCore_active, "f")
|
|
263
|
+
.get(key)
|
|
264
|
+
?.controller?.abort(new Error(`Durable alarm "${name}" was cancelled`));
|
|
265
|
+
__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").notify(__classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), key);
|
|
266
|
+
return true;
|
|
224
267
|
}, _DurabilityAlarmsCore_execute = function _DurabilityAlarmsCore_execute(row, platform) {
|
|
225
268
|
const running = __classPrivateFieldGet(this, _DurabilityAlarmsCore_active, "f").get(row.name);
|
|
226
269
|
if (running) {
|
|
227
270
|
return running.settled;
|
|
228
271
|
}
|
|
229
|
-
const
|
|
272
|
+
const name = row.name;
|
|
273
|
+
const policy = __classPrivateFieldGet(this, _DurabilityAlarmsCore_policy, "f").call(this, name);
|
|
230
274
|
const retryTimeouts = policy.method?.retryTimeouts ?? false;
|
|
231
275
|
return __classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").startExecution({
|
|
232
|
-
table:
|
|
276
|
+
table: __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"),
|
|
233
277
|
key: row.name,
|
|
234
278
|
row,
|
|
235
|
-
label: `named alarm "${
|
|
279
|
+
label: `named alarm "${name}"`,
|
|
236
280
|
entity: alarmEntity(row),
|
|
237
281
|
active: __classPrivateFieldGet(this, _DurabilityAlarmsCore_active, "f"),
|
|
238
282
|
policy,
|
|
239
283
|
emit: __classPrivateFieldGet(this, _DurabilityAlarmsCore_emit, "f"),
|
|
240
|
-
exhaustedError: () => new DurableAttemptsExhaustedError('named alarm',
|
|
241
|
-
timeoutError: () => new DurableAlarmTimeoutError(
|
|
284
|
+
exhaustedError: () => new DurableAttemptsExhaustedError('named alarm', name, policy.maxAttempts),
|
|
285
|
+
timeoutError: () => new DurableAlarmTimeoutError(name, policy.attemptTimeoutMs),
|
|
242
286
|
invoke: (attempt, signal) => {
|
|
243
|
-
const handler = __classPrivateFieldGet(this, _DurabilityAlarmsCore_handlers, "f").get(
|
|
287
|
+
const handler = __classPrivateFieldGet(this, _DurabilityAlarmsCore_handlers, "f").get(name);
|
|
244
288
|
if (!handler) {
|
|
245
|
-
throw new NonRetryableError(`No named alarm handler registered for "${
|
|
289
|
+
throw new NonRetryableError(`No named alarm handler registered for "${name}"`);
|
|
246
290
|
}
|
|
247
291
|
return handler({
|
|
248
|
-
name
|
|
292
|
+
name,
|
|
249
293
|
scheduledTime: row.scheduled_at,
|
|
250
294
|
attempt,
|
|
251
295
|
isRetry: attempt > 1,
|
|
252
296
|
retryCount: attempt - 1,
|
|
253
297
|
idempotencyKey: `durability-alarm:v1:${row.generation_id}`,
|
|
254
298
|
signal,
|
|
255
|
-
memoize: createMemoize(__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").sql,
|
|
299
|
+
memoize: createMemoize(__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").sql, __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), {
|
|
256
300
|
key: row.name,
|
|
257
301
|
generation: row.generation_id,
|
|
258
302
|
attempt,
|
|
@@ -262,7 +306,7 @@ _DurabilityAlarmsCore_engine = new WeakMap(), _DurabilityAlarmsCore_handlers = n
|
|
|
262
306
|
},
|
|
263
307
|
complete: (_result, attempt) => {
|
|
264
308
|
const timestamp = Date.now();
|
|
265
|
-
const removed = deleteAttempt(__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").sql,
|
|
309
|
+
const removed = deleteAttempt(__classPrivateFieldGet(this, _DurabilityAlarmsCore_engine, "f").sql, __classPrivateFieldGet(this, _DurabilityAlarmsCore_table, "f"), {
|
|
266
310
|
key: row.name,
|
|
267
311
|
generation: row.generation_id,
|
|
268
312
|
attempt,
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ordered SQLite migrations for the `durability_alarms` table owned by
|
|
3
|
+
* {@link DurabilityAlarms}. Applied automatically on construction.
|
|
4
|
+
*/
|
|
5
|
+
export const durabilityNamedAlarmMigrations = [
|
|
6
|
+
{
|
|
7
|
+
name: 'durability_0003_create_alarms',
|
|
8
|
+
up: `
|
|
9
|
+
CREATE TABLE IF NOT EXISTS durability_alarms (
|
|
10
|
+
name TEXT PRIMARY KEY,
|
|
11
|
+
generation_id TEXT NOT NULL,
|
|
12
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
13
|
+
scheduled_at INTEGER NOT NULL,
|
|
14
|
+
next_attempt_at INTEGER NOT NULL,
|
|
15
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
16
|
+
last_error TEXT,
|
|
17
|
+
last_error_name TEXT
|
|
18
|
+
);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS durability_alarms_pending_idx
|
|
20
|
+
ON durability_alarms (status, next_attempt_at);
|
|
21
|
+
`,
|
|
22
|
+
down: `
|
|
23
|
+
DROP INDEX IF EXISTS durability_alarms_pending_idx;
|
|
24
|
+
DROP TABLE IF EXISTS durability_alarms;
|
|
25
|
+
`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'durability_0004_alarms_generation_and_created_at',
|
|
29
|
+
up: `
|
|
30
|
+
DROP INDEX IF EXISTS durability_alarms_pending_idx;
|
|
31
|
+
ALTER TABLE durability_alarms RENAME TO durability_alarms_v3;
|
|
32
|
+
CREATE TABLE durability_alarms (
|
|
33
|
+
name TEXT PRIMARY KEY,
|
|
34
|
+
generation_id TEXT NOT NULL,
|
|
35
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
36
|
+
scheduled_at INTEGER NOT NULL,
|
|
37
|
+
next_attempt_at INTEGER NOT NULL,
|
|
38
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
39
|
+
last_error TEXT,
|
|
40
|
+
last_error_name TEXT,
|
|
41
|
+
created_at INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER))
|
|
42
|
+
);
|
|
43
|
+
INSERT INTO durability_alarms
|
|
44
|
+
SELECT name, generation_id, status, scheduled_at, next_attempt_at,
|
|
45
|
+
attempt, last_error, last_error_name,
|
|
46
|
+
CAST(unixepoch('subsec') * 1000 AS INTEGER)
|
|
47
|
+
FROM durability_alarms_v3;
|
|
48
|
+
DROP TABLE durability_alarms_v3;
|
|
49
|
+
CREATE INDEX durability_alarms_pending_idx
|
|
50
|
+
ON durability_alarms (status, next_attempt_at);
|
|
51
|
+
CREATE INDEX durability_alarms_created_idx
|
|
52
|
+
ON durability_alarms (created_at);
|
|
53
|
+
`,
|
|
54
|
+
down: `
|
|
55
|
+
DROP INDEX IF EXISTS durability_alarms_pending_idx;
|
|
56
|
+
DROP INDEX IF EXISTS durability_alarms_created_idx;
|
|
57
|
+
ALTER TABLE durability_alarms RENAME TO durability_alarms_v4;
|
|
58
|
+
CREATE TABLE durability_alarms (
|
|
59
|
+
name TEXT PRIMARY KEY,
|
|
60
|
+
generation_id TEXT NOT NULL,
|
|
61
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
62
|
+
scheduled_at INTEGER NOT NULL,
|
|
63
|
+
next_attempt_at INTEGER NOT NULL,
|
|
64
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
65
|
+
last_error TEXT,
|
|
66
|
+
last_error_name TEXT
|
|
67
|
+
);
|
|
68
|
+
INSERT INTO durability_alarms
|
|
69
|
+
SELECT name, generation_id, status, scheduled_at, next_attempt_at,
|
|
70
|
+
attempt, last_error, last_error_name
|
|
71
|
+
FROM durability_alarms_v4;
|
|
72
|
+
DROP TABLE durability_alarms_v4;
|
|
73
|
+
CREATE INDEX durability_alarms_pending_idx
|
|
74
|
+
ON durability_alarms (status, next_attempt_at);
|
|
75
|
+
`,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'durability_0016_alarms_channel',
|
|
79
|
+
up: `
|
|
80
|
+
ALTER TABLE durability_alarms RENAME TO durability_alarms_before_channels;
|
|
81
|
+
CREATE TABLE durability_alarms (
|
|
82
|
+
name TEXT NOT NULL,
|
|
83
|
+
generation_id TEXT NOT NULL,
|
|
84
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
85
|
+
scheduled_at INTEGER NOT NULL,
|
|
86
|
+
next_attempt_at INTEGER NOT NULL,
|
|
87
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
88
|
+
last_error TEXT,
|
|
89
|
+
last_error_name TEXT,
|
|
90
|
+
created_at INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER)),
|
|
91
|
+
channel TEXT NOT NULL DEFAULT 'default',
|
|
92
|
+
PRIMARY KEY (channel, name)
|
|
93
|
+
);
|
|
94
|
+
INSERT INTO durability_alarms
|
|
95
|
+
SELECT *, 'default' FROM durability_alarms_before_channels;
|
|
96
|
+
DROP TABLE durability_alarms_before_channels;
|
|
97
|
+
CREATE INDEX durability_alarms_pending_idx
|
|
98
|
+
ON durability_alarms (status, next_attempt_at);
|
|
99
|
+
CREATE INDEX durability_alarms_created_idx
|
|
100
|
+
ON durability_alarms (created_at);
|
|
101
|
+
CREATE INDEX durability_alarms_channel_pending_idx
|
|
102
|
+
ON durability_alarms (channel, status, next_attempt_at);
|
|
103
|
+
`,
|
|
104
|
+
down: `
|
|
105
|
+
CREATE TABLE durability_alarms_channel_guard (
|
|
106
|
+
channel TEXT CONSTRAINT cannot_downgrade_nondefault_channels CHECK (channel = 'default')
|
|
107
|
+
);
|
|
108
|
+
INSERT INTO durability_alarms_channel_guard SELECT DISTINCT channel FROM durability_alarms;
|
|
109
|
+
DROP TABLE durability_alarms_channel_guard;
|
|
110
|
+
ALTER TABLE durability_alarms RENAME TO durability_alarms_with_channels;
|
|
111
|
+
CREATE TABLE durability_alarms (
|
|
112
|
+
name TEXT PRIMARY KEY,
|
|
113
|
+
generation_id TEXT NOT NULL,
|
|
114
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'failed')),
|
|
115
|
+
scheduled_at INTEGER NOT NULL,
|
|
116
|
+
next_attempt_at INTEGER NOT NULL,
|
|
117
|
+
attempt INTEGER NOT NULL DEFAULT 0,
|
|
118
|
+
last_error TEXT,
|
|
119
|
+
last_error_name TEXT,
|
|
120
|
+
created_at INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsec') * 1000 AS INTEGER))
|
|
121
|
+
);
|
|
122
|
+
INSERT INTO durability_alarms
|
|
123
|
+
SELECT name, generation_id, status, scheduled_at, next_attempt_at,
|
|
124
|
+
attempt, last_error, last_error_name, created_at
|
|
125
|
+
FROM durability_alarms_with_channels;
|
|
126
|
+
DROP TABLE durability_alarms_with_channels;
|
|
127
|
+
CREATE INDEX durability_alarms_pending_idx
|
|
128
|
+
ON durability_alarms (status, next_attempt_at);
|
|
129
|
+
CREATE INDEX durability_alarms_created_idx
|
|
130
|
+
ON durability_alarms (created_at);
|
|
131
|
+
`,
|
|
132
|
+
},
|
|
133
|
+
];
|
package/dist/errors.d.ts
CHANGED
|
@@ -85,6 +85,21 @@ export declare class FanoutTimeoutError extends Error {
|
|
|
85
85
|
export declare class OutboxTimeoutError extends Error {
|
|
86
86
|
constructor(timeoutMs: number);
|
|
87
87
|
}
|
|
88
|
+
/** Outcome error of a scheduled run that exceeded `runTimeoutMs`. */
|
|
89
|
+
export declare class ScheduledRunTimeoutError extends Error {
|
|
90
|
+
constructor(timeoutMs: number);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Outcome error of a scheduled run that was still marked running when no live
|
|
94
|
+
* instance was executing it, for example after its object was evicted or reset.
|
|
95
|
+
*/
|
|
96
|
+
export declare class ScheduledRunInterruptedError extends Error {
|
|
97
|
+
constructor();
|
|
98
|
+
}
|
|
99
|
+
/** Error recorded when one `onOutcome` delivery exceeds `outcomeTimeoutMs`. */
|
|
100
|
+
export declare class ScheduledOutcomeTimeoutError extends Error {
|
|
101
|
+
constructor(timeoutMs: number);
|
|
102
|
+
}
|
|
88
103
|
/** A definite rejection before the batch was durably accepted. */
|
|
89
104
|
export declare class FanoutEnqueueError extends Error {
|
|
90
105
|
constructor(message: string);
|
package/dist/errors.js
CHANGED
|
@@ -135,6 +135,30 @@ export class OutboxTimeoutError extends Error {
|
|
|
135
135
|
this.name = 'OutboxTimeoutError';
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
+
/** Outcome error of a scheduled run that exceeded `runTimeoutMs`. */
|
|
139
|
+
export class ScheduledRunTimeoutError extends Error {
|
|
140
|
+
constructor(timeoutMs) {
|
|
141
|
+
super(`Scheduled run timed out after ${timeoutMs}ms`);
|
|
142
|
+
this.name = 'ScheduledRunTimeoutError';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Outcome error of a scheduled run that was still marked running when no live
|
|
147
|
+
* instance was executing it, for example after its object was evicted or reset.
|
|
148
|
+
*/
|
|
149
|
+
export class ScheduledRunInterruptedError extends Error {
|
|
150
|
+
constructor() {
|
|
151
|
+
super('Scheduled run was interrupted before it reported an outcome');
|
|
152
|
+
this.name = 'ScheduledRunInterruptedError';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Error recorded when one `onOutcome` delivery exceeds `outcomeTimeoutMs`. */
|
|
156
|
+
export class ScheduledOutcomeTimeoutError extends Error {
|
|
157
|
+
constructor(timeoutMs) {
|
|
158
|
+
super(`Scheduled run outcome delivery timed out after ${timeoutMs}ms`);
|
|
159
|
+
this.name = 'ScheduledOutcomeTimeoutError';
|
|
160
|
+
}
|
|
161
|
+
}
|
|
138
162
|
/** A definite rejection before the batch was durably accepted. */
|
|
139
163
|
export class FanoutEnqueueError extends Error {
|
|
140
164
|
constructor(message) {
|
package/dist/experimental.d.ts
CHANGED
|
@@ -4,13 +4,16 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
export { DurabilityTracker, type DurabilityTrackerConfig, type TrackedHandle, type TrackedItem, type TrackedResult, type TrackedWaitOptions, type TrackerHandle, type TrackerPage, type TrackerQuery, type TrackerRecord, type TrackerRecordPage, } from './tracker.js';
|
|
8
|
-
export type { TrackedEntry, TrackedPage, TrackedQuery, TrackedRecord, TrackedResults, TrackedSource, TrackedState, TrackedStatus, } from './
|
|
9
|
-
export { DurabilityOutbox, type DurabilityOutboxConfig, type DurabilityOutboxEvent, type OutboxEntry, } from './outbox.js';
|
|
7
|
+
export { DurabilityTracker, type DurabilityTrackerConfig, type TrackedHandle, type TrackedItem, type TrackedResult, type TrackedWaitOptions, type TrackerHandle, type TrackerPage, type TrackerQuery, type TrackerRecord, type TrackerRecordPage, } from './tracker/index.js';
|
|
8
|
+
export type { TrackedEntry, TrackedPage, TrackedQuery, TrackedRecord, TrackedResults, TrackedSource, TrackedState, TrackedStatus, } from './tracker/source.js';
|
|
9
|
+
export { DurabilityOutbox, type DurabilityOutboxConfig, type DurabilityOutboxEvent, type OutboxEntry, } from './outbox/index.js';
|
|
10
10
|
export { OutboxTimeoutError } from './errors.js';
|
|
11
|
-
export { durabilityOutboxMigrations } from './migrations.js';
|
|
12
|
-
export { DurabilityTopology, type DurabilityTopologyConfig, type DurabilityTopologyEvent, type TopologyChannel, type TopologyCurrent, type TopologyDraft, type TopologyPublisher, type TopologyRetryOptions, type TopologyRole, type TopologyStateUpdate, } from './topology.js';
|
|
13
|
-
export type { TopologyClient, TopologyClientConfig, TopologySource, TopologyView, } from './topology
|
|
14
|
-
export type { TopologyMember, TopologyMemberInput, TopologyMemberState, TopologySnapshot, } from './topology
|
|
11
|
+
export { durabilityOutboxMigrations } from './outbox/migrations.js';
|
|
12
|
+
export { DurabilityTopology, type DurabilityTopologyConfig, type DurabilityTopologyEvent, type TopologyChannel, type TopologyCurrent, type TopologyDraft, type TopologyPublisher, type TopologyRetryOptions, type TopologyRole, type TopologyStateUpdate, } from './topology/index.js';
|
|
13
|
+
export type { TopologyClient, TopologyClientConfig, TopologySource, TopologyView, } from './topology/client.js';
|
|
14
|
+
export type { TopologyMember, TopologyMemberInput, TopologyMemberState, TopologySnapshot, } from './topology/snapshot.js';
|
|
15
15
|
export { TopologyError, TopologyUnavailableError, type TopologyFallbackReason, } from './errors.js';
|
|
16
|
-
export { durabilityTopologyMigrations } from './migrations.js';
|
|
16
|
+
export { durabilityTopologyMigrations } from './topology/migrations.js';
|
|
17
|
+
export { DurabilitySchedule, type DurabilityScheduleConfig, type DurabilityScheduleEvent, type ScheduleDefinition, type ScheduledOutcomeDelivery, type ScheduledRun, type ScheduledRunContext, type ScheduledRunOutcome, type ScheduleState, } from './schedule/index.js';
|
|
18
|
+
export { ScheduledOutcomeTimeoutError, ScheduledRunInterruptedError, ScheduledRunTimeoutError, } from './errors.js';
|
|
19
|
+
export { durabilityScheduleMigrations } from './schedule/migrations.js';
|
package/dist/experimental.js
CHANGED
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
*/
|
|
7
|
-
export { DurabilityTracker, } from './tracker.js';
|
|
8
|
-
export { DurabilityOutbox, } from './outbox.js';
|
|
7
|
+
export { DurabilityTracker, } from './tracker/index.js';
|
|
8
|
+
export { DurabilityOutbox, } from './outbox/index.js';
|
|
9
9
|
export { OutboxTimeoutError } from './errors.js';
|
|
10
|
-
export { durabilityOutboxMigrations } from './migrations.js';
|
|
11
|
-
export { DurabilityTopology, } from './topology.js';
|
|
10
|
+
export { durabilityOutboxMigrations } from './outbox/migrations.js';
|
|
11
|
+
export { DurabilityTopology, } from './topology/index.js';
|
|
12
12
|
export { TopologyError, TopologyUnavailableError, } from './errors.js';
|
|
13
|
-
export { durabilityTopologyMigrations } from './migrations.js';
|
|
13
|
+
export { durabilityTopologyMigrations } from './topology/migrations.js';
|
|
14
|
+
export { DurabilitySchedule, } from './schedule/index.js';
|
|
15
|
+
export { ScheduledOutcomeTimeoutError, ScheduledRunInterruptedError, ScheduledRunTimeoutError, } from './errors.js';
|
|
16
|
+
export { durabilityScheduleMigrations } from './schedule/migrations.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type DurabilityLifecycleEvent, type LifecycleHook } from '
|
|
2
|
-
import { RoutingLoad, type EnqueueResult, type LoadSnapshot } from '
|
|
1
|
+
import { type DurabilityLifecycleEvent, type LifecycleHook } from '../lifecycle.js';
|
|
2
|
+
import { RoutingLoad, type EnqueueResult, type LoadSnapshot } from '../routing/load.js';
|
|
3
3
|
import type { MessageWrite } from './stored-message.js';
|
|
4
|
-
import { type DurableMemoize } from '
|
|
5
|
-
import { type ExecutionPolicyOptions } from '
|
|
6
|
-
import { type SchedulerAttachment } from '
|
|
4
|
+
import { type DurableMemoize } from '../memoize/index.js';
|
|
5
|
+
import { type ExecutionPolicyOptions } from '../policy.js';
|
|
6
|
+
import { type SchedulerAttachment } from '../scheduler/index.js';
|
|
7
7
|
export type FanoutInput<Body = unknown> = {
|
|
8
8
|
id?: string;
|
|
9
9
|
body: Body;
|
|
@@ -46,6 +46,13 @@ export type FanoutEnqueueOptions = {
|
|
|
46
46
|
targets?: readonly string[];
|
|
47
47
|
};
|
|
48
48
|
export type DurabilityFanoutConfig<Body> = SchedulerAttachment & ExecutionPolicyOptions & {
|
|
49
|
+
/**
|
|
50
|
+
* Stable channel ID. Instances on one scheduler share storage, partitioned
|
|
51
|
+
* by channel; target IDs and deduplication keys are independent in each
|
|
52
|
+
* channel, so a library can attach its own fanout beside the application's.
|
|
53
|
+
* Defaults to `default`.
|
|
54
|
+
*/
|
|
55
|
+
channel?: string;
|
|
49
56
|
targets: Record<string, FanoutTarget<Body>>;
|
|
50
57
|
routing?: RoutingLoad;
|
|
51
58
|
/** Receives terminal failures. Without it, terminal deliveries are dropped. */
|
|
@@ -72,7 +79,7 @@ export type DurabilityFanoutEvent = Extract<DurabilityLifecycleEvent, {
|
|
|
72
79
|
export declare class DurabilityFanout<Body = unknown> {
|
|
73
80
|
#private;
|
|
74
81
|
constructor(config: DurabilityFanoutConfig<Body>);
|
|
75
|
-
static migrate(context: Pick<DurableObjectState, 'storage'>, target?: string | null): import("
|
|
82
|
+
static migrate(context: Pick<DurableObjectState, 'storage'>, target?: string | null): import("../migrations.js").DurabilityMigrationResult;
|
|
76
83
|
alarm(info?: AlarmInvocationInfo): Promise<void>;
|
|
77
84
|
/**
|
|
78
85
|
* Attaches a best-effort lifecycle hook alongside `onLifecycleEvent` and
|