logic-sdk 0.7.0 → 0.7.2
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 +9 -9
- package/dist/adapters/cloudflare-queue.d.ts +14 -0
- package/dist/adapters/cloudflare-queue.js +48 -0
- package/dist/adapters/drizzle-pg.d.ts +250 -0
- package/dist/adapters/drizzle-pg.js +69 -0
- package/dist/adapters/drizzle-sqlite.d.ts +257 -0
- package/dist/adapters/drizzle-sqlite.js +196 -0
- package/dist/adapters/pg-boss.d.ts +45 -0
- package/dist/adapters/pg-boss.js +180 -0
- package/dist/adapters/postgres.d.ts +32 -0
- package/dist/adapters/postgres.js +105 -0
- package/dist/adapters/sqlite.d.ts +13 -0
- package/dist/adapters/sqlite.js +88 -0
- package/dist/{stored-jobs.d.ts → adapters/stored-jobs.d.ts} +27 -10
- package/dist/{stored-jobs.js → adapters/stored-jobs.js} +106 -20
- package/dist/ai.d.ts +1 -32
- package/dist/ai.js +1 -40
- package/dist/cloudflare.d.ts +2 -55
- package/dist/cloudflare.js +2 -85
- package/dist/core/in-process.d.ts +9 -0
- package/dist/core/in-process.js +17 -0
- package/dist/core/jobs.d.ts +57 -0
- package/dist/{jobs.js → core/jobs.js} +161 -42
- package/dist/core/registry.d.ts +120 -0
- package/dist/core/registry.js +503 -0
- package/dist/core/testing.d.ts +75 -0
- package/dist/core/testing.js +230 -0
- package/dist/{types.d.ts → core/types.d.ts} +224 -49
- package/dist/drizzle/pg.d.ts +3 -236
- package/dist/drizzle/pg.js +2 -67
- package/dist/drizzle/sqlite.d.ts +3 -242
- package/dist/drizzle/sqlite.js +2 -194
- package/dist/fetch.d.ts +1 -19
- package/dist/fetch.js +1 -30
- package/dist/hosts/cloudflare.d.ts +42 -0
- package/dist/hosts/cloudflare.js +39 -0
- package/dist/hosts/node.d.ts +26 -0
- package/dist/hosts/node.js +76 -0
- package/dist/hosts/pg-boss.d.ts +22 -0
- package/dist/hosts/pg-boss.js +55 -0
- package/dist/index.d.ts +5 -124
- package/dist/index.js +4 -495
- package/dist/integrations/ai.d.ts +32 -0
- package/dist/integrations/ai.js +40 -0
- package/dist/integrations/fetch.d.ts +19 -0
- package/dist/integrations/fetch.js +30 -0
- package/dist/integrations/orpc.d.ts +22 -0
- package/dist/integrations/orpc.js +37 -0
- package/dist/node.d.ts +1 -26
- package/dist/node.js +1 -76
- package/dist/orpc.d.ts +1 -21
- package/dist/orpc.js +1 -37
- package/dist/pg-boss.d.ts +2 -55
- package/dist/pg-boss.js +2 -211
- package/dist/postgres.d.ts +2 -28
- package/dist/postgres.js +1 -82
- package/dist/sqlite.d.ts +2 -9
- package/dist/sqlite.js +1 -65
- package/dist/testing.d.ts +1 -67
- package/dist/testing.js +1 -214
- package/package.json +2 -2
- package/skills/logic-sdk/SKILL.md +7 -6
- package/src/adapters/cloudflare-queue.ts +56 -0
- package/src/adapters/drizzle-pg.ts +108 -0
- package/src/adapters/drizzle-sqlite.ts +234 -0
- package/src/adapters/pg-boss.ts +195 -0
- package/src/adapters/postgres.ts +112 -0
- package/src/adapters/sqlite.ts +96 -0
- package/src/{stored-jobs.ts → adapters/stored-jobs.ts} +133 -30
- package/src/ai.ts +1 -62
- package/src/cloudflare.ts +2 -107
- package/src/core/in-process.ts +18 -0
- package/src/{jobs.ts → core/jobs.ts} +166 -43
- package/src/core/registry.ts +671 -0
- package/src/core/testing.ts +307 -0
- package/src/{types.ts → core/types.ts} +219 -46
- package/src/drizzle/pg.ts +3 -110
- package/src/drizzle/sqlite.ts +3 -236
- package/src/fetch.ts +1 -31
- package/src/hosts/cloudflare.ts +54 -0
- package/src/hosts/node.ts +99 -0
- package/src/hosts/pg-boss.ts +71 -0
- package/src/index.ts +17 -655
- package/src/integrations/ai.ts +63 -0
- package/src/integrations/fetch.ts +31 -0
- package/src/integrations/orpc.ts +47 -0
- package/src/node.ts +1 -99
- package/src/orpc.ts +1 -46
- package/src/pg-boss.ts +2 -242
- package/src/postgres.ts +2 -90
- package/src/sqlite.ts +2 -74
- package/src/testing.ts +1 -288
- package/dist/jobs.d.ts +0 -44
- /package/dist/{errors.d.ts → core/errors.d.ts} +0 -0
- /package/dist/{errors.js → core/errors.js} +0 -0
- /package/dist/{schedule.d.ts → core/schedule.d.ts} +0 -0
- /package/dist/{schedule.js → core/schedule.js} +0 -0
- /package/dist/{types.js → core/types.js} +0 -0
- /package/src/{errors.ts → core/errors.ts} +0 -0
- /package/src/{schedule.ts → core/schedule.ts} +0 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Caller,
|
|
3
|
+
type DatabaseAdapter,
|
|
4
|
+
type DeepPartial,
|
|
5
|
+
type CallJob,
|
|
6
|
+
type Cron,
|
|
7
|
+
type Delivery,
|
|
8
|
+
type Envelope,
|
|
9
|
+
type Fn,
|
|
10
|
+
type FnIn,
|
|
11
|
+
type FnOut,
|
|
12
|
+
type Job,
|
|
13
|
+
type JobOutcome,
|
|
14
|
+
type JobsAdapter,
|
|
15
|
+
type Listener,
|
|
16
|
+
type Registry,
|
|
17
|
+
} from "./types.ts";
|
|
18
|
+
import { deliveryOf, replaceKeyOf } from "./jobs.ts";
|
|
19
|
+
import { INTERNAL } from "./types.ts";
|
|
20
|
+
|
|
21
|
+
export interface TestOptions<Cf = unknown> {
|
|
22
|
+
/** Replace services (e.g. `{ mailer: memoryMailer() }`). */
|
|
23
|
+
services?: object;
|
|
24
|
+
/** Override parts of `config` (e.g. `{ orders: { maxItems: 1 } }`). Merged over the registry's, section by section. */
|
|
25
|
+
config?: DeepPartial<Cf>;
|
|
26
|
+
/** Freeze time. */
|
|
27
|
+
now?: Date | string | (() => Date);
|
|
28
|
+
/**
|
|
29
|
+
* `"inline"` (default): listeners run right after each mutation, inside the test. `"manual"`: jobs wait in
|
|
30
|
+
* `t.jobs.queued` until you `drain()` them, to test one module without the others reacting. Like Oban's
|
|
31
|
+
* `testing: :inline | :manual`. Either way, what waits (a listener's `delay`, `ctx.schedule`) waits for `drain()`, and
|
|
32
|
+
* your app's adapter (a database queue, an outbox, Cloudflare) is never used.
|
|
33
|
+
*/
|
|
34
|
+
jobs?: "inline" | "manual";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The jobs of the current test, like `registry.jobs` in production. */
|
|
38
|
+
export interface TestJobs<S> {
|
|
39
|
+
/** Listener jobs waiting: every one in `jobs: "manual"`, and the delayed ones in either mode. */
|
|
40
|
+
readonly queued: readonly Delivery[];
|
|
41
|
+
/** What `ctx.schedule` asked for, waiting for `drain()`. */
|
|
42
|
+
readonly scheduled: readonly CallJob[];
|
|
43
|
+
/**
|
|
44
|
+
* Run what's due at the test's now (or `until`), and what that queues, until nothing due is left. Throws a failure.
|
|
45
|
+
* Like Rails' `perform_enqueued_jobs(at:)` and Oban's `drain_queue(with_scheduled:)`.
|
|
46
|
+
*/
|
|
47
|
+
drain(options?: { until?: Date | string }): Promise<void>;
|
|
48
|
+
/** Run one listener by hand, as if its event had been emitted as `scope`. Throws its failure, like `drain()`. */
|
|
49
|
+
perform<O>(listener: Listener<O>, payload: O, options: { scope: S; attempt?: number }): Promise<JobOutcome>;
|
|
50
|
+
/**
|
|
51
|
+
* Run one cron by hand, as its own scope, for the minute `at` (default: the test's now), whatever its schedule. Throws
|
|
52
|
+
* its failure. `t.jobs.tick(at)` runs every cron due that minute instead.
|
|
53
|
+
*/
|
|
54
|
+
perform(cron: Cron, options?: { at?: Date | string; attempt?: number }): Promise<JobOutcome>;
|
|
55
|
+
/** Run the crons due in `at`'s minute (default: the test's now), here and now. Resolves their ids; throws a failure. */
|
|
56
|
+
tick(at?: Date | string): Promise<string[]>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface TestRegistry<S extends object, Mods extends Record<string, object>, Cf> {
|
|
60
|
+
/** Open the test's transaction: `beforeEach(() => t.begin())`. */
|
|
61
|
+
begin(): Promise<void>;
|
|
62
|
+
/** Roll it back: `afterEach(() => t.rollback())`. */
|
|
63
|
+
rollback(): Promise<void>;
|
|
64
|
+
/** Bind who is calling, like `registry.as(...)`. A listener that fails makes `run` throw, so a test can't pass over it. */
|
|
65
|
+
as(scope: S): Caller<S>;
|
|
66
|
+
/** Replace a function's implementation for this test. Matched by identity, so `run(availability.hold, …)` hits the stub. */
|
|
67
|
+
stub<F extends Fn>(fn: F, impl: (ctx: unknown, input: FnIn<F>) => Promise<FnOut<F>>): void;
|
|
68
|
+
/** Every event emitted (and committed) in this test, in order. */
|
|
69
|
+
readonly events: readonly Envelope[];
|
|
70
|
+
/** The test transaction itself: read rows to assert on them. */
|
|
71
|
+
readonly db: any;
|
|
72
|
+
/** The registry bound to this test's transaction, for adapters: an oRPC context's `caller: t.registry.as(scope)`. */
|
|
73
|
+
readonly registry: Registry<S, Mods, Cf>;
|
|
74
|
+
readonly jobs: TestJobs<S>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** One test, between `begin` and `rollback`. */
|
|
78
|
+
interface Open<S extends object, Mods extends Record<string, object>, Cf> {
|
|
79
|
+
registry: Registry<S, Mods, Cf>;
|
|
80
|
+
db: unknown;
|
|
81
|
+
events: Envelope[];
|
|
82
|
+
stubs: Map<Fn, (ctx: never, input: never) => Promise<unknown>>;
|
|
83
|
+
queued: Delivery[];
|
|
84
|
+
scheduled: CallJob[];
|
|
85
|
+
/** Job failures (listeners, crons, scheduled calls) during the current call. */
|
|
86
|
+
failures: unknown[];
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class Rollback extends Error {}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The test's jobs adapter. What waits (a delayed listener, `ctx.schedule`) is held for `drain()`, and in `"manual"` so
|
|
94
|
+
* is everything else; the rest runs now. It holds and replaces what your app's adapter does, so a test fails where
|
|
95
|
+
* production would.
|
|
96
|
+
*/
|
|
97
|
+
const testJobs = (mode: TestOptions["jobs"], app: JobsAdapter | undefined, queued: Delivery[], scheduled: CallJob[]): JobsAdapter => ({
|
|
98
|
+
name: app?.name,
|
|
99
|
+
holds: app?.holds,
|
|
100
|
+
replaces: app?.replaces,
|
|
101
|
+
retries: app?.retries,
|
|
102
|
+
async deliver(jobs, runner) {
|
|
103
|
+
for (const job of jobs) {
|
|
104
|
+
const key = replaceKeyOf(job);
|
|
105
|
+
if (key) {
|
|
106
|
+
const waiting = scheduled.findIndex((c) => replaceKeyOf(c) === key);
|
|
107
|
+
if (waiting >= 0) scheduled.splice(waiting, 1);
|
|
108
|
+
}
|
|
109
|
+
const waits = job.runAt !== undefined || (mode === "manual" && job.kind !== "cron");
|
|
110
|
+
if (!waits) await runner.run({ ...job, attempts: 1 }); // one try, like inProcess(): reported, so the test sees it
|
|
111
|
+
else if (job.kind === "call") scheduled.push(job);
|
|
112
|
+
else if (job.kind === "delivery") queued.push(job);
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
/** Removes the jobs that are due from `list` and returns them. */
|
|
118
|
+
function takeDue<T extends Job>(list: T[], cutoff: number): T[] {
|
|
119
|
+
const due = (job: T) => !job.runAt || Date.parse(job.runAt) <= cutoff;
|
|
120
|
+
const ready = list.filter(due);
|
|
121
|
+
list.splice(0, list.length, ...list.filter((job) => !due(job)));
|
|
122
|
+
return ready;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Run each test inside a transaction that's rolled back, set up once with hooks:
|
|
127
|
+
*
|
|
128
|
+
* ```ts
|
|
129
|
+
* const t = createTestRegistry(registry);
|
|
130
|
+
* beforeEach(() => t.begin());
|
|
131
|
+
* afterEach(() => t.rollback());
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* Every top-level mutation inside becomes a savepoint, so a failing mutation rolls back just its own writes, like it
|
|
135
|
+
* would in production. Tests that share `t` run one at a time (one connection, nested savepoints).
|
|
136
|
+
*/
|
|
137
|
+
export function createTestRegistry<S extends object, Mods extends Record<string, object>, Cf>(
|
|
138
|
+
registry: Registry<S, Mods, Cf>,
|
|
139
|
+
options: TestOptions<Cf> = {},
|
|
140
|
+
): TestRegistry<S, Mods, Cf> {
|
|
141
|
+
const { options: registryOptions } = registry[INTERNAL];
|
|
142
|
+
const fixed = options.now;
|
|
143
|
+
const now = typeof fixed === "function" ? fixed : fixed === undefined ? undefined : () => new Date(fixed);
|
|
144
|
+
/** While `drain()` runs a job that waited, the time it was due: what `ctx.now()` reads then. */
|
|
145
|
+
let travelled: number | undefined;
|
|
146
|
+
const clock = () => {
|
|
147
|
+
const base = (now ?? registryOptions.now ?? (() => new Date()))();
|
|
148
|
+
return travelled !== undefined && travelled > base.getTime() ? new Date(travelled) : base;
|
|
149
|
+
};
|
|
150
|
+
let open: Open<S, Mods, Cf> | undefined;
|
|
151
|
+
|
|
152
|
+
const current = () => {
|
|
153
|
+
if (!open) throw new Error("[logic-sdk] No test transaction. Add beforeEach(() => t.begin()) and afterEach(() => t.rollback()).");
|
|
154
|
+
return open;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/** `db` is the test's transaction, and `database` the adapter nested in it (none without a database). */
|
|
158
|
+
function start(db: unknown, database: DatabaseAdapter<unknown, unknown> | undefined, close: () => Promise<void>): Open<S, Mods, Cf> {
|
|
159
|
+
const events: Envelope[] = [];
|
|
160
|
+
const stubs: Open<S, Mods, Cf>["stubs"] = new Map();
|
|
161
|
+
const queued: Delivery[] = [];
|
|
162
|
+
const scheduled: CallJob[] = [];
|
|
163
|
+
const failures: unknown[] = [];
|
|
164
|
+
const derived = registry[INTERNAL].derive({
|
|
165
|
+
database,
|
|
166
|
+
services: options.services,
|
|
167
|
+
config: options.config,
|
|
168
|
+
now: clock,
|
|
169
|
+
stubs,
|
|
170
|
+
record: (e) => events.push(e),
|
|
171
|
+
adapter: testJobs(options.jobs, registryOptions.jobs?.adapter, queued, scheduled),
|
|
172
|
+
failed: null, // failures throw in the test instead
|
|
173
|
+
waitUntil: undefined, // listeners finish before a call returns, inside the test
|
|
174
|
+
onError(error, info) {
|
|
175
|
+
if (info.outcome !== "discarded") failures.push(error);
|
|
176
|
+
registryOptions.onError?.(error, info);
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
return { registry: derived, db, events, stubs, queued, scheduled, failures, close };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Run `work`, then throw the first listener failure since the last one thrown (calls through `t.registry` included). */
|
|
183
|
+
async function settle<T>(state: Open<S, Mods, Cf>, work: () => Promise<T>): Promise<T> {
|
|
184
|
+
let out: T;
|
|
185
|
+
try {
|
|
186
|
+
out = await work();
|
|
187
|
+
} catch (e) {
|
|
188
|
+
state.failures.length = 0; // what it threw is the failure: don't report it again on the next call
|
|
189
|
+
throw e;
|
|
190
|
+
}
|
|
191
|
+
throwFailures(state);
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
function throwFailures(state: Open<S, Mods, Cf>) {
|
|
195
|
+
if (!state.failures.length) return;
|
|
196
|
+
const [first] = state.failures.splice(0);
|
|
197
|
+
throw first;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
async begin() {
|
|
202
|
+
if (open)
|
|
203
|
+
throw new Error(
|
|
204
|
+
"[logic-sdk] t.begin() ran again before t.rollback(). Roll back in afterEach, and don't run tests that share `t` at the same time (test.concurrent).",
|
|
205
|
+
);
|
|
206
|
+
const database = registryOptions.database?.adapter;
|
|
207
|
+
if (!database) {
|
|
208
|
+
open = start(undefined, undefined, async () => {});
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!database.nest) throw new Error("[logic-sdk] This database adapter can't nest transactions, so tests can't roll back.");
|
|
212
|
+
// Drizzle transactions live inside a callback: park it there until rollback.
|
|
213
|
+
const opened = Promise.withResolvers<unknown>();
|
|
214
|
+
const released = Promise.withResolvers<void>();
|
|
215
|
+
const done = database
|
|
216
|
+
.transaction(async (tx) => {
|
|
217
|
+
opened.resolve(tx);
|
|
218
|
+
await released.promise;
|
|
219
|
+
throw new Rollback();
|
|
220
|
+
})
|
|
221
|
+
.catch((e) => {
|
|
222
|
+
if (!(e instanceof Rollback)) throw e;
|
|
223
|
+
});
|
|
224
|
+
const tx = await Promise.race([opened.promise, done]); // `done` settles first only if the transaction failed to open
|
|
225
|
+
open = start(tx, database.nest(tx), async () => {
|
|
226
|
+
released.resolve();
|
|
227
|
+
await done;
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
/** Also throws a listener failure nothing surfaced yet (a call through `t.registry`), so the test fails. */
|
|
231
|
+
async rollback() {
|
|
232
|
+
const state = open;
|
|
233
|
+
open = undefined;
|
|
234
|
+
await state?.close();
|
|
235
|
+
if (state) throwFailures(state);
|
|
236
|
+
},
|
|
237
|
+
as: (scope) => ({
|
|
238
|
+
scope,
|
|
239
|
+
run: (fn, ...args) => {
|
|
240
|
+
const state = current();
|
|
241
|
+
return settle(state, () => state.registry.as(scope).run(fn, ...args));
|
|
242
|
+
},
|
|
243
|
+
}),
|
|
244
|
+
stub: (fn, impl) => void current().stubs.set(fn, impl),
|
|
245
|
+
get events() {
|
|
246
|
+
return current().events;
|
|
247
|
+
},
|
|
248
|
+
get db() {
|
|
249
|
+
return current().db;
|
|
250
|
+
},
|
|
251
|
+
get registry() {
|
|
252
|
+
return current().registry;
|
|
253
|
+
},
|
|
254
|
+
jobs: {
|
|
255
|
+
get queued() {
|
|
256
|
+
return current().queued;
|
|
257
|
+
},
|
|
258
|
+
get scheduled() {
|
|
259
|
+
return current().scheduled;
|
|
260
|
+
},
|
|
261
|
+
async drain({ until } = {}) {
|
|
262
|
+
const state = current();
|
|
263
|
+
const end = until === undefined ? clock() : new Date(until);
|
|
264
|
+
if (Number.isNaN(end.getTime())) throw new Error(`[logic-sdk] drain({ until }) needs a valid date (got ${String(until)}).`);
|
|
265
|
+
try {
|
|
266
|
+
for (let round = 1; ; round++) {
|
|
267
|
+
const ready = [...takeDue(state.queued, end.getTime()), ...takeDue(state.scheduled, end.getTime())];
|
|
268
|
+
if (!ready.length) return;
|
|
269
|
+
if (round > 100) throw new Error("[logic-sdk] drain() ran 100 rounds and jobs are still due: does one reschedule itself, inside `until`, more often than you meant?");
|
|
270
|
+
ready.sort((a, b) => (a.runAt ?? "").localeCompare(b.runAt ?? ""));
|
|
271
|
+
for (const job of ready) {
|
|
272
|
+
// the job runs at the time it was due, so a self-rescheduling one moves forward and its checks see that time
|
|
273
|
+
if (job.runAt) travelled = Math.max(travelled ?? 0, Date.parse(job.runAt));
|
|
274
|
+
await settle(state, () => state.registry.jobs.run(job));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
} finally {
|
|
278
|
+
travelled = undefined;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
perform(target: Listener<any> | Cron, ...rest: any[]) {
|
|
282
|
+
const state = current();
|
|
283
|
+
if (target.kind === "cron") {
|
|
284
|
+
const { at, attempt } = (rest[0] ?? {}) as { at?: Date | string; attempt?: number };
|
|
285
|
+
const cron = state.registry.definitions.crons.find((c) => c.cron === target);
|
|
286
|
+
if (!cron) throw new Error("[logic-sdk] t.jobs.perform got a cron that isn't registered: export it from its module.");
|
|
287
|
+
const when = at === undefined ? clock() : new Date(at);
|
|
288
|
+
if (Number.isNaN(when.getTime())) throw new Error(`[logic-sdk] t.jobs.perform({ at }) needs a valid date (got ${String(at)}).`);
|
|
289
|
+
const [job] = state.registry[INTERNAL].due(when, cron.id);
|
|
290
|
+
return settle(state, () => state.registry.jobs.run(job!, { attempt }));
|
|
291
|
+
}
|
|
292
|
+
const listener = target;
|
|
293
|
+
const [payload, { scope, attempt }] = rest as [unknown, { scope: S; attempt?: number }];
|
|
294
|
+
const registered = state.registry.definitions.listeners.find((l) => l.listener === listener);
|
|
295
|
+
if (!registered) throw new Error("[logic-sdk] t.jobs.perform got a listener that isn't registered: export it from its module.");
|
|
296
|
+
const envelope = state.registry[INTERNAL].envelope(registered.event, payload, scope);
|
|
297
|
+
return settle(state, () => state.registry.jobs.run(deliveryOf(registered, envelope), { attempt }));
|
|
298
|
+
},
|
|
299
|
+
async tick(at) {
|
|
300
|
+
const state = current();
|
|
301
|
+
const jobs = state.registry[INTERNAL].due(at === undefined ? clock() : new Date(at));
|
|
302
|
+
for (const job of jobs) await settle(state, () => state.registry.jobs.run(job));
|
|
303
|
+
return jobs.map((job) => job.cron);
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|