@nexusts/schedule 0.7.0 → 0.7.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/README.md +2 -2
- package/dist/backends/cloudflare.d.ts +54 -0
- package/dist/backends/index.d.ts +2 -0
- package/dist/backends/memory.d.ts +38 -0
- package/dist/cron-parser.d.ts +47 -0
- package/dist/decorators/cron.d.ts +70 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +3 -3
- package/dist/schedule.module.d.ts +43 -0
- package/dist/schedule.service.d.ts +50 -0
- package/dist/types.d.ts +149 -0
- package/package.json +6 -11
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ This module is part of the NexusTS monorepo. Each module is published as its own
|
|
|
15
15
|
Most apps start with just the core:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
bun add @nexusts/core
|
|
18
|
+
bun add @nexusts/core
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Then add this module only if you need it:
|
|
@@ -26,7 +26,7 @@ bun add @nexusts/schedule
|
|
|
26
26
|
|
|
27
27
|
## Peer dependencies
|
|
28
28
|
|
|
29
|
-
None.
|
|
29
|
+
**None.** No external dependencies. In-tree cron parser; no `cron` or `node-cron` needed.
|
|
30
30
|
|
|
31
31
|
## Usage
|
|
32
32
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloudflare Cron Triggers backend.
|
|
3
|
+
*
|
|
4
|
+
* Cloudflare Cron Triggers are configured in `wrangler.toml`:
|
|
5
|
+
*
|
|
6
|
+
* [[triggers.crons]]
|
|
7
|
+
* cron = "every 15m (your expression)"
|
|
8
|
+
*
|
|
9
|
+
* The trigger fires a Worker's `scheduled(event, env, ctx)` handler.
|
|
10
|
+
* We dispatch that to the registered task by name.
|
|
11
|
+
*
|
|
12
|
+
* This backend is a **registration-only facade**: tasks are stored
|
|
13
|
+
* locally (so `nx route:list`-style introspection works), but the
|
|
14
|
+
* actual scheduling is at the platform level. The worker's `scheduled`
|
|
15
|
+
* export calls `dispatch(event)` to run the matching task.
|
|
16
|
+
*/
|
|
17
|
+
import type { ScheduleRegistry, ScheduleHandler, ScheduledTask, CronExpression, CronOptions, ScheduleEventListener } from "../types.js";
|
|
18
|
+
/** Shape of the Worker's `scheduled` event. Mirrors `cloudflare-types`. */
|
|
19
|
+
export interface CloudflareScheduledEvent {
|
|
20
|
+
cron: string;
|
|
21
|
+
/** ISO timestamp of when the trigger fired. */
|
|
22
|
+
scheduledTime: Date | number;
|
|
23
|
+
}
|
|
24
|
+
export interface CloudflareSchedulesOptions {
|
|
25
|
+
/** Validate that registered expressions match the wrangler.toml trigger. Default: true. */
|
|
26
|
+
validateAgainstTrigger?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare class CloudflareSchedulesBackend implements ScheduleRegistry {
|
|
29
|
+
#private;
|
|
30
|
+
constructor(options?: CloudflareSchedulesOptions);
|
|
31
|
+
addCron(name: string, expression: CronExpression, handler: ScheduleHandler, options?: CronOptions): string;
|
|
32
|
+
addInterval(): string;
|
|
33
|
+
addTimeout(): string;
|
|
34
|
+
delete(idOrName: string): boolean;
|
|
35
|
+
list(): ScheduledTask[];
|
|
36
|
+
get(idOrName: string): ScheduledTask | undefined;
|
|
37
|
+
pause(): boolean;
|
|
38
|
+
resume(): boolean;
|
|
39
|
+
stop(): Promise<void>;
|
|
40
|
+
on(listener: ScheduleEventListener): () => void;
|
|
41
|
+
/**
|
|
42
|
+
* Return the Worker's `scheduled()` handler. Mount it in the
|
|
43
|
+
* default export:
|
|
44
|
+
*
|
|
45
|
+
* export default {
|
|
46
|
+
* fetch: app.fetch,
|
|
47
|
+
* scheduled: backend.scheduledHandler(),
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* The handler dispatches based on the trigger's cron expression
|
|
51
|
+
* (or, when validation is disabled, by event ordering).
|
|
52
|
+
*/
|
|
53
|
+
scheduledHandler(): (event: CloudflareScheduledEvent) => Promise<void>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process scheduler backend.
|
|
3
|
+
*
|
|
4
|
+
* Runs on a single setInterval tick (default 1s) and dispatches due
|
|
5
|
+
* tasks. Honors cron expressions via `CronExpression.next()`, fixed
|
|
6
|
+
* intervals via `setInterval`, and one-shot delays via `setTimeout`.
|
|
7
|
+
*
|
|
8
|
+
* Use for Bun / Node long-running servers. For Cloudflare Workers,
|
|
9
|
+
* use the dedicated `CloudflareSchedulesBackend` which integrates
|
|
10
|
+
* with Cron Triggers.
|
|
11
|
+
*/
|
|
12
|
+
import type { ScheduleRegistry, ScheduleHandler, ScheduledTask, CronExpression, CronOptions, ScheduleEventListener } from "../types.js";
|
|
13
|
+
import { CronExpression as CronExpr } from "../cron-parser.js";
|
|
14
|
+
export interface MemoryBackendOptions {
|
|
15
|
+
/** Tick interval in ms. Default: 1000. */
|
|
16
|
+
tickMs?: number;
|
|
17
|
+
/** Default cron timezone. */
|
|
18
|
+
defaultTimezone?: string;
|
|
19
|
+
/** Skip tasks that fall behind by more than this many ms. Default: 60_000. */
|
|
20
|
+
maxDriftMs?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class MemorySchedulesBackend implements ScheduleRegistry {
|
|
23
|
+
#private;
|
|
24
|
+
constructor(options?: MemoryBackendOptions);
|
|
25
|
+
addCron(name: string, expression: CronExpression, handler: ScheduleHandler, options?: CronOptions): string;
|
|
26
|
+
addInterval(name: string, ms: number, handler: ScheduleHandler): string;
|
|
27
|
+
addTimeout(name: string, ms: number, handler: ScheduleHandler): string;
|
|
28
|
+
delete(idOrName: string): boolean;
|
|
29
|
+
list(): ScheduledTask[];
|
|
30
|
+
get(idOrName: string): ScheduledTask | undefined;
|
|
31
|
+
pause(idOrName: string): boolean;
|
|
32
|
+
resume(idOrName: string): boolean;
|
|
33
|
+
stop(): Promise<void>;
|
|
34
|
+
on(listener: ScheduleEventListener): () => void;
|
|
35
|
+
/** Start the tick loop. Idempotent. */
|
|
36
|
+
start(): void;
|
|
37
|
+
}
|
|
38
|
+
export { CronExpr };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron expression parser + next-run calculator.
|
|
3
|
+
*
|
|
4
|
+
* Supports the standard 5-field crontab syntax, an optional 6-field
|
|
5
|
+
* variant (with seconds), common aliases, and "@every <duration>".
|
|
6
|
+
*
|
|
7
|
+
* * * * * * every minute
|
|
8
|
+
* 0 * * * * every hour
|
|
9
|
+
* star-slash-15 every 15m
|
|
10
|
+
* 0 9 * * 1-5 9am on weekdays
|
|
11
|
+
* 0 0 1 * * first of the month
|
|
12
|
+
* 30 14 1 4 * Apr 1st at 14:30
|
|
13
|
+
* @yearly @annually 0 0 1 1 *
|
|
14
|
+
* @monthly 0 0 1 * *
|
|
15
|
+
* @weekly 0 0 * * 0
|
|
16
|
+
* @daily @midnight 0 0 * * *
|
|
17
|
+
* @hourly 0 * * * *
|
|
18
|
+
* @every 1h30m every 90 minutes
|
|
19
|
+
*
|
|
20
|
+
* Field names (JAN, FEB, SUN, MON, ...) are accepted case-insensitively.
|
|
21
|
+
*/
|
|
22
|
+
/** A single field expanded into a set of allowed numeric values. */
|
|
23
|
+
export declare class CronField {
|
|
24
|
+
readonly values: Set<number>;
|
|
25
|
+
constructor(field: string, range: [number, number]);
|
|
26
|
+
contains(n: number): boolean;
|
|
27
|
+
}
|
|
28
|
+
/** A fully-parsed cron expression. */
|
|
29
|
+
export declare class CronExpression {
|
|
30
|
+
readonly fields: CronField[];
|
|
31
|
+
readonly hasSeconds: boolean;
|
|
32
|
+
constructor(raw: string);
|
|
33
|
+
/**
|
|
34
|
+
* Return the next Date at or after `from` that matches this
|
|
35
|
+
* expression. Returns null if no match is found within `maxYears`
|
|
36
|
+
* (default 5) — which would indicate a misconfigured expression.
|
|
37
|
+
*/
|
|
38
|
+
next(from: Date, maxYears?: number): Date | null;
|
|
39
|
+
private matches;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a cron expression. Throws on invalid syntax. The returned
|
|
43
|
+
* object can be queried for the next match (`expr.next(new Date())`).
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseCron(expression: string): CronExpression;
|
|
46
|
+
/** Convenience: return the next Date matching `expression` after `from`. */
|
|
47
|
+
export declare function nextCron(expression: string, from?: Date): Date | null;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@Cron(expression)` — schedule a method as a cron task.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors `@nestjs/schedule`'s decorator. The decorated method runs
|
|
5
|
+
* on the cron schedule; pair it with `ScheduleModule.scanForSchedulers`
|
|
6
|
+
* to register at boot.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* @Injectable()
|
|
10
|
+
* class CleanupWorker {
|
|
11
|
+
* constructor(@Inject(ScheduleService.TOKEN) private schedule: ScheduleService) {}
|
|
12
|
+
*
|
|
13
|
+
* @Cron('0 * * * *') // every hour
|
|
14
|
+
* async hourly() {
|
|
15
|
+
* // ...
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @Cron('@daily', { timezone: 'UTC' })
|
|
19
|
+
* async dailyDigest() {
|
|
20
|
+
* // ...
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // src/app/main.ts
|
|
25
|
+
* const app = new Application(AppModule);
|
|
26
|
+
* const schedule = app.container.resolve(ScheduleService);
|
|
27
|
+
* for (const instance of getInjectables(app)) {
|
|
28
|
+
* await schedule.scanForSchedulers(instance);
|
|
29
|
+
* }
|
|
30
|
+
* schedule.start();
|
|
31
|
+
*/
|
|
32
|
+
import "reflect-metadata";
|
|
33
|
+
import type { ScheduleService } from "../schedule.service.js";
|
|
34
|
+
import type { CronExpression, CronOptions } from "../types.js";
|
|
35
|
+
/**
|
|
36
|
+
* Schedule the decorated method as a cron task.
|
|
37
|
+
*/
|
|
38
|
+
export declare function Cron(expression: CronExpression, options?: CronOptions): MethodDecorator;
|
|
39
|
+
/**
|
|
40
|
+
* Schedule the decorated method to run every `milliseconds`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function Interval(milliseconds: number, name?: string): MethodDecorator;
|
|
43
|
+
/**
|
|
44
|
+
* Schedule the decorated method to run once after `milliseconds`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function Timeout(milliseconds: number, name?: string): MethodDecorator;
|
|
47
|
+
/**
|
|
48
|
+
* Get the cron hooks declared on a class.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getCronHooks(target: unknown): Array<{
|
|
51
|
+
method: string;
|
|
52
|
+
expression: CronExpression;
|
|
53
|
+
options: CronOptions;
|
|
54
|
+
}>;
|
|
55
|
+
export declare function getIntervalHooks(target: unknown): Array<{
|
|
56
|
+
method: string;
|
|
57
|
+
milliseconds: number;
|
|
58
|
+
name?: string;
|
|
59
|
+
}>;
|
|
60
|
+
export declare function getTimeoutHooks(target: unknown): Array<{
|
|
61
|
+
method: string;
|
|
62
|
+
milliseconds: number;
|
|
63
|
+
name?: string;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Scan an instance for `@Cron` / `@Interval` / `@Timeout` hooks and
|
|
67
|
+
* register them with the `ScheduleService`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function scanForSchedulers(instance: object, service: ScheduleService): Promise<string[]>;
|
|
70
|
+
export type { ScheduleService };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API for the NexusTS schedule module.
|
|
3
|
+
*
|
|
4
|
+
* Two backends out of the box:
|
|
5
|
+
* - In-process — runs on Bun / Node via setInterval + cron tick.
|
|
6
|
+
* - Cloudflare Cron Triggers — Workers-native, fires from wrangler.toml.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors `@nestjs/schedule`'s decorator API: `@Cron`, `@Interval`,
|
|
9
|
+
* `@Timeout`. Plus a programmatic `ScheduleService` for dynamic
|
|
10
|
+
* registration.
|
|
11
|
+
*
|
|
12
|
+
* Quick start:
|
|
13
|
+
*
|
|
14
|
+
* // src/app/app.module.ts
|
|
15
|
+
* import { Module } from 'nexusjs';
|
|
16
|
+
* import { ScheduleModule } from 'nexusjs/schedule';
|
|
17
|
+
*
|
|
18
|
+
* @Module({
|
|
19
|
+
* imports: [ScheduleModule.forRoot({ backend: 'memory' })],
|
|
20
|
+
* })
|
|
21
|
+
* export class AppModule {}
|
|
22
|
+
*
|
|
23
|
+
* // any service
|
|
24
|
+
* import { ScheduleService, Cron, Interval, scanForSchedulers } from 'nexusjs/schedule';
|
|
25
|
+
*
|
|
26
|
+
* @Injectable()
|
|
27
|
+
* class CleanupWorker {
|
|
28
|
+
* constructor(@Inject(ScheduleService.TOKEN) private schedule: ScheduleService) {}
|
|
29
|
+
*
|
|
30
|
+
* @Cron('0 * * * *') // every hour
|
|
31
|
+
* async hourly() { /* ... *\/ }
|
|
32
|
+
*
|
|
33
|
+
* @Interval(60_000) // every minute
|
|
34
|
+
* async tick() { /* ... *\/ }
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // bootstrap
|
|
38
|
+
* const app = new Application(AppModule);
|
|
39
|
+
* const schedule = app.container.resolve(ScheduleService);
|
|
40
|
+
* await scanForSchedulers(worker, schedule);
|
|
41
|
+
* schedule.start();
|
|
42
|
+
*/
|
|
43
|
+
export * from "./types.js";
|
|
44
|
+
export { MemorySchedulesBackend, CloudflareSchedulesBackend, CronExpr, } from "./backends/index.js";
|
|
45
|
+
export type { MemoryBackendOptions } from "./backends/memory.js";
|
|
46
|
+
export type { CloudflareScheduledEvent, CloudflareSchedulesOptions, } from "./backends/cloudflare.js";
|
|
47
|
+
export { ScheduleService } from "./schedule.service.js";
|
|
48
|
+
export { ScheduleModule } from "./schedule.module.js";
|
|
49
|
+
export { Cron, Interval, Timeout, scanForSchedulers, getCronHooks, getIntervalHooks, getTimeoutHooks, } from "./decorators/cron.js";
|
|
50
|
+
export { parseCron, nextCron, CronExpression as CronExpressionClass, CronField, } from "./cron-parser.js";
|
package/dist/index.js
CHANGED
|
@@ -647,7 +647,7 @@ class CloudflareSchedulesBackend {
|
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
// packages/schedule/src/schedule.service.ts
|
|
650
|
-
import { Inject, Injectable } from "@nexusts/core
|
|
650
|
+
import { Inject, Injectable } from "@nexusts/core";
|
|
651
651
|
class ScheduleService {
|
|
652
652
|
config;
|
|
653
653
|
static TOKEN = Symbol.for("nexus:ScheduleService");
|
|
@@ -739,7 +739,7 @@ ScheduleService = __legacyDecorateClassTS([
|
|
|
739
739
|
], ScheduleService);
|
|
740
740
|
// packages/schedule/src/schedule.module.ts
|
|
741
741
|
import"reflect-metadata";
|
|
742
|
-
import { Module } from "@nexusts/core
|
|
742
|
+
import { Module } from "@nexusts/core";
|
|
743
743
|
class ScheduleModule {
|
|
744
744
|
static forRoot(config = {}) {
|
|
745
745
|
class ConfiguredScheduleModule {
|
|
@@ -866,5 +866,5 @@ export {
|
|
|
866
866
|
CloudflareSchedulesBackend
|
|
867
867
|
};
|
|
868
868
|
|
|
869
|
-
//# debugId=
|
|
869
|
+
//# debugId=BE7269D6BACECC6B64756E2164756E21
|
|
870
870
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"/**\n * Cron expression parser + next-run calculator.\n *\n * Supports the standard 5-field crontab syntax, an optional 6-field\n * variant (with seconds), common aliases, and \"@every <duration>\".\n *\n * * * * * * every minute\n * 0 * * * * every hour\n * star-slash-15 every 15m\n * 0 9 * * 1-5 9am on weekdays\n * 0 0 1 * * first of the month\n * 30 14 1 4 * Apr 1st at 14:30\n * @yearly @annually 0 0 1 1 *\n * @monthly 0 0 1 * *\n * @weekly 0 0 * * 0\n * @daily @midnight 0 0 * * *\n * @hourly 0 * * * *\n * @every 1h30m every 90 minutes\n *\n * Field names (JAN, FEB, SUN, MON, ...) are accepted case-insensitively.\n */\n\nconst FIELD_RANGES: Array<[number, number]> = [\n\t[0, 59], // minute\n\t[0, 23], // hour\n\t[1, 31], // day of month\n\t[1, 12], // month\n\t[0, 7], // day of week (0 or 7 = Sunday)\n];\n\nconst FIELD_NAMES: Record<string, number> = {\n\tJAN: 1,\n\tFEB: 2,\n\tMAR: 3,\n\tAPR: 4,\n\tMAY: 5,\n\tJUN: 6,\n\tJUL: 7,\n\tAUG: 8,\n\tSEP: 9,\n\tOCT: 10,\n\tNOV: 11,\n\tDEC: 12,\n\tSUN: 0,\n\tMON: 1,\n\tTUE: 2,\n\tWED: 3,\n\tTHU: 4,\n\tFRI: 5,\n\tSAT: 6,\n};\n\nconst ALIASES: Record<string, string> = {\n\t\"@yearly\": \"0 0 1 1 *\",\n\t\"@annually\": \"0 0 1 1 *\",\n\t\"@monthly\": \"0 0 1 * *\",\n\t\"@weekly\": \"0 0 * * 0\",\n\t\"@daily\": \"0 0 * * *\",\n\t\"@midnight\": \"0 0 * * *\",\n\t\"@hourly\": \"0 * * * *\",\n};\n\n/** A single field expanded into a set of allowed numeric values. */\nexport class CronField {\n\treadonly values: Set<number>;\n\n\tconstructor(field: string, range: [number, number]) {\n\t\tthis.values = parseField(field, range);\n\t}\n\n\tcontains(n: number): boolean {\n\t\treturn this.values.has(n);\n\t}\n}\n\n/** A fully-parsed cron expression. */\nexport class CronExpression {\n\treadonly fields: CronField[]; // 5 or 6 entries\n\treadonly hasSeconds: boolean;\n\n\tconstructor(raw: string) {\n\t\tconst expanded = expandAlias(raw);\n\t\tconst every = expandEvery(expanded);\n\n\t\tif (every) {\n\t\t\t// \"@every Nd|Nh|Nm|Ns\" → uniform interval\n\t\t\tthis.hasSeconds = true;\n\t\t\tthis.fields = everyToFields(every);\n\t\t\treturn;\n\t\t}\n\n\t\tconst parts = expanded.trim().split(/\\s+/);\n\t\tif (parts.length === 5) {\n\t\t\tthis.hasSeconds = false;\n\t\t\tthis.fields = parts.map((p, i) => new CronField(p, FIELD_RANGES[i]!));\n\t\t} else if (parts.length === 6) {\n\t\t\tthis.hasSeconds = true;\n\t\t\tconst sec: [number, number] = [0, 59];\n\t\t\tthis.fields = [\n\t\t\t\tnew CronField(parts[0]!, sec),\n\t\t\t\t...parts.slice(1).map((p, i) => new CronField(p, FIELD_RANGES[i]!)),\n\t\t\t];\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid cron expression: \"${raw}\" (expected 5 or 6 fields, got ${parts.length})`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Return the next Date at or after `from` that matches this\n\t * expression. Returns null if no match is found within `maxYears`\n\t * (default 5) — which would indicate a misconfigured expression.\n\t */\n\tnext(from: Date, maxYears = 5): Date | null {\n\t\tconst cap = new Date(from.getTime() + maxYears * 365 * 24 * 60 * 60 * 1000);\n\t\tlet cur = new Date(from.getTime() + 1000);\n\t\tcur.setMilliseconds(0);\n\n\t\t// Brute-force: step minute-by-minute, but skip ahead when a\n\t\t// higher-order field doesn't match. For most crons this is\n\t\t// fast enough; for very sparse crons we use a forwarder.\n\t\tlet safety = 0;\n\t\twhile (cur <= cap) {\n\t\t\tif (this.matches(cur)) {\n\t\t\t\treturn cur;\n\t\t\t}\n\t\t\t// Fast-forward: if the month doesn't match, jump to next month.\n\t\t\tif (!this.fields[this.hasSeconds ? 4 : 3]!.contains(cur.getMonth() + 1)) {\n\t\t\t\tcur = new Date(cur.getFullYear(), cur.getMonth() + 1, 1, 0, 0, 0, 0);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// If day-of-month is restricted and current day doesn't match,\n\t\t\t// jump to next month at the first allowed day.\n\t\t\tconst domIdx = this.hasSeconds ? 3 : 2;\n\t\t\tconst domField = this.fields[domIdx]!;\n\t\t\tif (!domField.contains(cur.getDate())) {\n\t\t\t\t// Find the first allowed day in the set, or jump to next month.\n\t\t\t\tconst sortedDays = [...domField.values].sort((a, b) => a - b);\n\t\t\t\tconst nextDay = sortedDays.find((d) => d >= cur.getDate());\n\t\t\t\tif (nextDay !== undefined) {\n\t\t\t\t\tcur = new Date(\n\t\t\t\t\t\tcur.getFullYear(),\n\t\t\t\t\t\tcur.getMonth(),\n\t\t\t\t\t\tnextDay,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tcur = new Date(\n\t\t\t\t\t\tcur.getFullYear(),\n\t\t\t\t\t\tcur.getMonth() + 1,\n\t\t\t\t\t\tsortedDays[0]!,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\t0,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// If the hour doesn't match, jump to next hour.\n\t\t\tif (!this.fields[this.hasSeconds ? 2 : 1]!.contains(cur.getHours())) {\n\t\t\t\tcur = new Date(\n\t\t\t\t\tcur.getFullYear(),\n\t\t\t\t\tcur.getMonth(),\n\t\t\t\t\tcur.getDate(),\n\t\t\t\t\tcur.getHours() + 1,\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// If the minute doesn't match, jump to next minute.\n\t\t\tif (!this.fields[this.hasSeconds ? 1 : 0]!.contains(cur.getMinutes())) {\n\t\t\t\tcur = new Date(\n\t\t\t\t\tcur.getFullYear(),\n\t\t\t\t\tcur.getMonth(),\n\t\t\t\t\tcur.getDate(),\n\t\t\t\t\tcur.getHours(),\n\t\t\t\t\tcur.getMinutes() + 1,\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// If seconds field exists and doesn't match, jump to next second.\n\t\t\tif (this.hasSeconds && !this.fields[0]!.contains(cur.getSeconds())) {\n\t\t\t\tcur = new Date(cur.getTime() + 1000);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Fallback: step 1 second (shouldn't normally hit).\n\t\t\tcur = new Date(cur.getTime() + 1000);\n\t\t\tif (++safety > 1_000_000) return null;\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate matches(d: Date): boolean {\n\t\tconst fields = this.hasSeconds\n\t\t\t? [\n\t\t\t\t\td.getSeconds(),\n\t\t\t\t\td.getMinutes(),\n\t\t\t\t\td.getHours(),\n\t\t\t\t\td.getDate(),\n\t\t\t\t\td.getMonth() + 1,\n\t\t\t\t\td.getDay(),\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\td.getMinutes(),\n\t\t\t\t\td.getHours(),\n\t\t\t\t\td.getDate(),\n\t\t\t\t\td.getMonth() + 1,\n\t\t\t\t\td.getDay(),\n\t\t\t\t];\n\t\t// Day-of-week in crontab: 0 = Sunday. Day-of-month is OR'd with\n\t\t// day-of-week when both are restricted (standard crontab behavior).\n\t\tconst domField = this.fields[this.hasSeconds ? 3 : 2]!;\n\t\tconst dowField = this.fields[this.hasSeconds ? 4 : 3]!;\n\t\tconst isWildDom = domField.values.size === FIELD_RANGES[2]![1]!;\n\t\tconst isWildDow = dowField.values.size === FIELD_RANGES[4]![1]! + 1;\n\t\tconst dayMatch =\n\t\t\tisWildDom || isWildDow\n\t\t\t\t? domField.contains(d.getDate()) || dowField.contains(d.getDay())\n\t\t\t\t: domField.contains(d.getDate()) || dowField.contains(d.getDay());\n\n\t\tfor (let i = 0; i < this.fields.length; i++) {\n\t\t\tif (i === (this.hasSeconds ? 3 : 2)) continue;\n\t\t\tif (!this.fields[i]!.contains(fields[i]!)) return false;\n\t\t}\n\t\treturn dayMatch;\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction expandAlias(raw: string): string {\n\tconst trimmed = raw.trim();\n\tconst alias = ALIASES[trimmed.toLowerCase()];\n\treturn alias ?? trimmed;\n}\n\nfunction expandEvery(raw: string): number | null {\n\tconst m = /^@every\\s+(\\d+)\\s*(s|m|h|d)?$/i.exec(raw.trim());\n\tif (!m) return null;\n\tconst n = Number(m[1]);\n\tconst unit = (m[2] ?? \"s\").toLowerCase();\n\tswitch (unit) {\n\t\tcase \"s\":\n\t\t\treturn n * 1000;\n\t\tcase \"m\":\n\t\t\treturn n * 60 * 1000;\n\t\tcase \"h\":\n\t\t\treturn n * 60 * 60 * 1000;\n\t\tcase \"d\":\n\t\t\treturn n * 24 * 60 * 60 * 1000;\n\t}\n\treturn null;\n}\n\nfunction everyToFields(intervalMs: number): CronField[] {\n\t// Generate a 6-field expression that fires every `intervalMs`\n\t// starting from the next round minute.\n\tconst seconds = Math.floor(intervalMs / 1000);\n\tif (seconds < 60) {\n\t\t// fire every N seconds (only if it divides 60)\n\t\tif (60 % seconds === 0) {\n\t\t\treturn [\n\t\t\t\tnew CronField(`*/${seconds}`, [0, 59]),\n\t\t\t\tnew CronField(\"*\", [0, 59]),\n\t\t\t\tnew CronField(\"*\", [0, 23]),\n\t\t\t\tnew CronField(\"*\", [1, 31]),\n\t\t\t\tnew CronField(\"*\", [1, 12]),\n\t\t\t\tnew CronField(\"*\", [0, 7]),\n\t\t\t];\n\t\t}\n\t}\n\t// Otherwise just allow every minute; the registry layer handles\n\t// throttling via setInterval.\n\treturn [\n\t\tnew CronField(\"0\", [0, 59]),\n\t\tnew CronField(\"*\", [0, 59]),\n\t\tnew CronField(\"*\", [0, 23]),\n\t\tnew CronField(\"*\", [1, 31]),\n\t\tnew CronField(\"*\", [1, 12]),\n\t\tnew CronField(\"*\", [0, 7]),\n\t];\n}\n\nfunction parseField(field: string, range: [number, number]): Set<number> {\n\tconst out = new Set<number>();\n\tconst [lo, hi] = range;\n\tconst parts = field.split(\",\");\n\tfor (const partRaw of parts) {\n\t\tconst part = partRaw.trim();\n\t\t// step: e.g. \"*/2\" or \"0-30/2\"\n\t\tconst stepMatch = /^(.+?)\\/(\\d+)$/.exec(part);\n\t\tlet base = part;\n\t\tlet step = 1;\n\t\tif (stepMatch) {\n\t\t\tbase = stepMatch[1]!;\n\t\t\tstep = Number(stepMatch[2]);\n\t\t}\n\t\tlet start: number;\n\t\tlet end: number;\n\t\tif (base === \"*\") {\n\t\t\tstart = lo;\n\t\t\tend = hi;\n\t\t} else if (base.includes(\"-\")) {\n\t\t\tconst [a, b] = base.split(\"-\").map((s) => resolveValue(s, lo, hi));\n\t\t\tstart = a;\n\t\t\tend = b;\n\t\t} else {\n\t\t\tconst v = resolveValue(base, lo, hi);\n\t\t\tstart = v;\n\t\t\tend = stepMatch ? hi : v;\n\t\t}\n\t\tif (start > end) {\n\t\t\tthrow new Error(`Invalid range in cron field: \"${part}\"`);\n\t\t}\n\t\tfor (let i = start; i <= end; i += step) {\n\t\t\tout.add(i);\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction resolveValue(token: string, lo: number, hi: number): number {\n\tconst t = token.trim();\n\tif (t === \"*\") return lo;\n\tconst named = FIELD_NAMES[t.toUpperCase()];\n\tif (named !== undefined) return named;\n\tconst n = Number(t);\n\tif (Number.isNaN(n)) {\n\t\tthrow new Error(`Invalid cron field value: \"${token}\"`);\n\t}\n\tif (n < lo || n > hi) {\n\t\tthrow new Error(`Cron value ${n} out of range [${lo}, ${hi}]`);\n\t}\n\treturn n;\n}\n\n/**\n * Parse a cron expression. Throws on invalid syntax. The returned\n * object can be queried for the next match (`expr.next(new Date())`).\n */\nexport function parseCron(expression: string): CronExpression {\n\treturn new CronExpression(expression);\n}\n\n/** Convenience: return the next Date matching `expression` after `from`. */\nexport function nextCron(\n\texpression: string,\n\tfrom: Date = new Date(),\n): Date | null {\n\treturn parseCron(expression).next(from);\n}\n",
|
|
6
6
|
"/**\n * In-process scheduler backend.\n *\n * Runs on a single setInterval tick (default 1s) and dispatches due\n * tasks. Honors cron expressions via `CronExpression.next()`, fixed\n * intervals via `setInterval`, and one-shot delays via `setTimeout`.\n *\n * Use for Bun / Node long-running servers. For Cloudflare Workers,\n * use the dedicated `CloudflareSchedulesBackend` which integrates\n * with Cron Triggers.\n */\n\nimport type {\n\tScheduleRegistry,\n\tScheduleHandler,\n\tScheduledTask,\n\tCronExpression,\n\tCronOptions,\n\tScheduleEvent,\n\tScheduleEventListener,\n\tTaskKind,\n} from \"../types.js\";\nimport { CronExpression as CronExpr, nextCron } from \"../cron-parser.js\";\n\ninterface InternalTask {\n\tid: string;\n\tname: string;\n\tkind: TaskKind;\n\texpression: string;\n\t/** Next run time (epoch ms). */\n\tnextRunAt: number;\n\t/** Last run time (epoch ms). */\n\tlastRunAt?: number;\n\tinvocations: number;\n\tlastError?: string;\n\tstatus: \"running\" | \"stopped\" | \"paused\";\n\thandler: ScheduleHandler;\n\t/** Interval handle for `interval` / `timeout` tasks. */\n\ttimer?: ReturnType<typeof setInterval> | ReturnType<typeof setTimeout>;\n}\n\nexport interface MemoryBackendOptions {\n\t/** Tick interval in ms. Default: 1000. */\n\ttickMs?: number;\n\t/** Default cron timezone. */\n\tdefaultTimezone?: string;\n\t/** Skip tasks that fall behind by more than this many ms. Default: 60_000. */\n\tmaxDriftMs?: number;\n}\n\nexport class MemorySchedulesBackend implements ScheduleRegistry {\n\t#tasks = new Map<string, InternalTask>();\n\t#byName = new Map<string, string>(); // name → id\n\t#listeners = new Set<ScheduleEventListener>();\n\t#tickHandle: ReturnType<typeof setInterval> | null = null;\n\t#tickMs: number;\n\t#maxDriftMs: number;\n\t#defaultTimezone: string | undefined = undefined;\n\t#nextId = 1;\n\n\tconstructor(options: MemoryBackendOptions = {}) {\n\t\tthis.#tickMs = options.tickMs ?? 1000;\n\t\tthis.#maxDriftMs = options.maxDriftMs ?? 60_000;\n\t\tthis.#defaultTimezone = options.defaultTimezone;\n\t}\n\n\t// ===========================================================================\n\t// Public API\n\t// ===========================================================================\n\n\taddCron(\n\t\tname: string,\n\t\texpression: CronExpression,\n\t\thandler: ScheduleHandler,\n\t\toptions: CronOptions = {},\n\t): string {\n\t\tconst id = this.#allocateId();\n\t\tconst next = nextCron(\n\t\t\texpression,\n\t\t\toptions.runOnInit ? new Date(Date.now() - 1000) : new Date(),\n\t\t);\n\t\tconst task: InternalTask = {\n\t\t\tid,\n\t\t\tname,\n\t\t\tkind: \"cron\",\n\t\t\texpression,\n\t\t\tnextRunAt: next?.getTime() ?? Date.now() + 60_000,\n\t\t\tinvocations: 0,\n\t\t\tstatus: \"running\",\n\t\t\thandler,\n\t\t};\n\t\tthis.#tasks.set(id, task);\n\t\tthis.#byName.set(name, id);\n\t\tthis.#emit({\n\t\t\tkind: \"task:registered\",\n\t\t\tid,\n\t\t\tname,\n\t\t\ttaskKind: \"cron\",\n\t\t\texpression,\n\t\t});\n\t\treturn id;\n\t}\n\n\taddInterval(name: string, ms: number, handler: ScheduleHandler): string {\n\t\tconst id = this.#allocateId();\n\t\tconst task: InternalTask = {\n\t\t\tid,\n\t\t\tname,\n\t\t\tkind: \"interval\",\n\t\t\texpression: `${ms}ms`,\n\t\t\tnextRunAt: Date.now() + ms,\n\t\t\tinvocations: 0,\n\t\t\tstatus: \"running\",\n\t\t\thandler,\n\t\t};\n\t\ttask.timer = setInterval(() => this.#runTask(id), ms);\n\t\tthis.#tasks.set(id, task);\n\t\tthis.#byName.set(name, id);\n\t\tthis.#emit({\n\t\t\tkind: \"task:registered\",\n\t\t\tid,\n\t\t\tname,\n\t\t\ttaskKind: \"interval\",\n\t\t\texpression: `${ms}ms`,\n\t\t});\n\t\treturn id;\n\t}\n\n\taddTimeout(name: string, ms: number, handler: ScheduleHandler): string {\n\t\tconst id = this.#allocateId();\n\t\tconst task: InternalTask = {\n\t\t\tid,\n\t\t\tname,\n\t\t\tkind: \"timeout\",\n\t\t\texpression: `${ms}ms`,\n\t\t\tnextRunAt: Date.now() + ms,\n\t\t\tinvocations: 0,\n\t\t\tstatus: \"running\",\n\t\t\thandler,\n\t\t};\n\t\ttask.timer = setTimeout(() => this.#runOnceAndRemove(id), ms);\n\t\tthis.#tasks.set(id, task);\n\t\tthis.#byName.set(name, id);\n\t\tthis.#emit({\n\t\t\tkind: \"task:registered\",\n\t\t\tid,\n\t\t\tname,\n\t\t\ttaskKind: \"timeout\",\n\t\t\texpression: `${ms}ms`,\n\t\t});\n\t\treturn id;\n\t}\n\n\tdelete(idOrName: string): boolean {\n\t\tconst id = this.#resolveId(idOrName);\n\t\tif (!id) return false;\n\t\tconst task = this.#tasks.get(id);\n\t\tif (!task) return false;\n\t\tthis.#clearTimer(task);\n\t\tthis.#tasks.delete(id);\n\t\tthis.#byName.delete(task.name);\n\t\tthis.#emit({ kind: \"task:deleted\", id });\n\t\treturn true;\n\t}\n\n\tlist(): ScheduledTask[] {\n\t\treturn [...this.#tasks.values()].map((t) => this.#toPublic(t));\n\t}\n\n\tget(idOrName: string): ScheduledTask | undefined {\n\t\tconst id = this.#resolveId(idOrName);\n\t\tif (!id) return undefined;\n\t\tconst task = this.#tasks.get(id);\n\t\treturn task ? this.#toPublic(task) : undefined;\n\t}\n\n\tpause(idOrName: string): boolean {\n\t\tconst id = this.#resolveId(idOrName);\n\t\tif (!id) return false;\n\t\tconst task = this.#tasks.get(id);\n\t\tif (!task) return false;\n\t\tthis.#clearTimer(task);\n\t\ttask.status = \"paused\";\n\t\tthis.#emit({ kind: \"task:paused\", id });\n\t\treturn true;\n\t}\n\n\tresume(idOrName: string): boolean {\n\t\tconst id = this.#resolveId(idOrName);\n\t\tif (!id) return false;\n\t\tconst task = this.#tasks.get(id);\n\t\tif (!task) return false;\n\t\tif (task.kind === \"interval\" && !task.timer) {\n\t\t\ttask.timer = setInterval(\n\t\t\t\t() => this.#runTask(id),\n\t\t\t\tNumber(task.expression.replace(\"ms\", \"\")),\n\t\t\t);\n\t\t}\n\t\ttask.status = \"running\";\n\t\tthis.#emit({ kind: \"task:resumed\", id });\n\t\treturn true;\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tfor (const task of this.#tasks.values()) {\n\t\t\tthis.#clearTimer(task);\n\t\t}\n\t\tthis.#tasks.clear();\n\t\tthis.#byName.clear();\n\t\tif (this.#tickHandle) clearInterval(this.#tickHandle);\n\t\tthis.#tickHandle = null;\n\t}\n\n\t// ===========================================================================\n\t// Events\n\t// ===========================================================================\n\n\ton(listener: ScheduleEventListener): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t// ===========================================================================\n\t// Lifecycle\n\t// ===========================================================================\n\n\t/** Start the tick loop. Idempotent. */\n\tstart(): void {\n\t\tif (this.#tickHandle) return;\n\t\tthis.#tickHandle = setInterval(() => this.#tick(), this.#tickMs);\n\t\t// Don't keep Node alive just for the tick.\n\t\tconst handle = this.#tickHandle as unknown as { unref?: () => void };\n\t\tif (typeof handle.unref === \"function\") handle.unref();\n\t}\n\n\t// ===========================================================================\n\t// Internal\n\t// ===========================================================================\n\n\t#allocateId(): string {\n\t\treturn `sched-${this.#nextId++}`;\n\t}\n\n\t#resolveId(idOrName: string): string | null {\n\t\tif (this.#tasks.has(idOrName)) return idOrName;\n\t\treturn this.#byName.get(idOrName) ?? null;\n\t}\n\n\t#toPublic(t: InternalTask): ScheduledTask {\n\t\tconst public_: ScheduledTask = {\n\t\t\tid: t.id,\n\t\t\tname: t.name,\n\t\t\tkind: t.kind,\n\t\t\texpression: t.expression,\n\t\t\tstatus: t.status,\n\t\t\tinvocations: t.invocations,\n\t\t};\n\t\tif (t.lastRunAt !== undefined) {\n\t\t\tpublic_.lastRunAt = new Date(t.lastRunAt).toISOString();\n\t\t}\n\t\tpublic_.nextRunAt = new Date(t.nextRunAt).toISOString();\n\t\tif (t.lastError !== undefined) public_.lastError = t.lastError;\n\t\treturn public_;\n\t}\n\n\t#clearTimer(task: InternalTask): void {\n\t\tif (task.timer) {\n\t\t\tclearInterval(task.timer as ReturnType<typeof setInterval>);\n\t\t\tclearTimeout(task.timer as ReturnType<typeof setTimeout>);\n\t\t\ttask.timer = undefined;\n\t\t}\n\t}\n\n\t#tick(): void {\n\t\tconst now = Date.now();\n\t\tfor (const [id, task] of this.#tasks) {\n\t\t\tif (task.status !== \"running\") continue;\n\t\t\tif (task.kind !== \"cron\") continue; // intervals/timeouts fire via their own timer\n\t\t\tif (task.nextRunAt > now) continue;\n\t\t\tvoid this.#runTask(id);\n\t\t}\n\t}\n\n\tasync #runTask(id: string): Promise<void> {\n\t\tconst task = this.#tasks.get(id);\n\t\tif (!task) return;\n\t\tconst startedAt = new Date();\n\t\tthis.#emit({\n\t\t\tkind: \"task:invoked\",\n\t\t\tid,\n\t\t\tname: task.name,\n\t\t\tstartedAt: startedAt.toISOString(),\n\t\t});\n\t\tconst start = Date.now();\n\t\ttry {\n\t\t\tconst result = await task.handler();\n\t\t\ttask.invocations++;\n\t\t\ttask.lastRunAt = start;\n\t\t\ttask.lastError = undefined;\n\t\t\tthis.#emit({\n\t\t\t\tkind: \"task:completed\",\n\t\t\t\tid,\n\t\t\t\tname: task.name,\n\t\t\t\tdurationMs: Date.now() - start,\n\t\t\t\treturnvalue: result,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\ttask.invocations++;\n\t\t\ttask.lastRunAt = start;\n\t\t\tconst error = err instanceof Error ? err : new Error(String(err));\n\t\t\ttask.lastError = error.message;\n\t\t\tthis.#emit({ kind: \"task:failed\", id, name: task.name, error });\n\t\t} finally {\n\t\t\t// Schedule the next cron run.\n\t\t\tif (task.kind === \"cron\" && task.status === \"running\") {\n\t\t\t\tconst next = nextCron(task.expression, new Date());\n\t\t\t\tif (next) {\n\t\t\t\t\tconst drift = next.getTime() - Date.now();\n\t\t\t\t\ttask.nextRunAt =\n\t\t\t\t\t\tdrift > this.#maxDriftMs ? Date.now() + 60_000 : next.getTime();\n\t\t\t\t} else {\n\t\t\t\t\ttask.nextRunAt = Date.now() + 60_000;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t#runOnceAndRemove(id: string): void {\n\t\tvoid this.#runTask(id);\n\t\tconst task = this.#tasks.get(id);\n\t\tif (task) {\n\t\t\tthis.#tasks.delete(id);\n\t\t\tthis.#byName.delete(task.name);\n\t\t\tthis.#emit({ kind: \"task:deleted\", id });\n\t\t}\n\t}\n\n\t#emit(event: ScheduleEvent): void {\n\t\tfor (const l of this.#listeners) {\n\t\t\tvoid Promise.resolve(l(event));\n\t\t}\n\t}\n}\n\n// Re-export the parser's CronExpression class for users who want to\n// parse expressions manually.\nexport { CronExpr };\n",
|
|
7
7
|
"/**\n * Cloudflare Cron Triggers backend.\n *\n * Cloudflare Cron Triggers are configured in `wrangler.toml`:\n *\n * [[triggers.crons]]\n * cron = \"every 15m (your expression)\"\n *\n * The trigger fires a Worker's `scheduled(event, env, ctx)` handler.\n * We dispatch that to the registered task by name.\n *\n * This backend is a **registration-only facade**: tasks are stored\n * locally (so `nx route:list`-style introspection works), but the\n * actual scheduling is at the platform level. The worker's `scheduled`\n * export calls `dispatch(event)` to run the matching task.\n */\n\nimport type {\n\tScheduleRegistry,\n\tScheduleHandler,\n\tScheduledTask,\n\tCronExpression,\n\tCronOptions,\n\tScheduleEvent,\n\tScheduleEventListener,\n} from \"../types.js\";\n\ninterface InternalTask {\n\tid: string;\n\tname: string;\n\texpression: string;\n\thandler: ScheduleHandler;\n\toptions: CronOptions;\n}\n\n/** Shape of the Worker's `scheduled` event. Mirrors `cloudflare-types`. */\nexport interface CloudflareScheduledEvent {\n\tcron: string;\n\t/** ISO timestamp of when the trigger fired. */\n\tscheduledTime: Date | number;\n}\n\nexport interface CloudflareSchedulesOptions {\n\t/** Validate that registered expressions match the wrangler.toml trigger. Default: true. */\n\tvalidateAgainstTrigger?: boolean;\n}\n\nexport class CloudflareSchedulesBackend implements ScheduleRegistry {\n\t#tasks = new Map<string, InternalTask>();\n\t#byName = new Map<string, string>();\n\t#listeners = new Set<ScheduleEventListener>();\n\t#nextId = 1;\n\t#validate: boolean;\n\n\tconstructor(options: CloudflareSchedulesOptions = {}) {\n\t\tthis.#validate = options.validateAgainstTrigger ?? true;\n\t}\n\n\taddCron(\n\t\tname: string,\n\t\texpression: CronExpression,\n\t\thandler: ScheduleHandler,\n\t\toptions: CronOptions = {},\n\t): string {\n\t\tconst id = `sched-${this.#nextId++}`;\n\t\tthis.#tasks.set(id, { id, name, expression, handler, options });\n\t\tthis.#byName.set(name, id);\n\t\tthis.#emit({\n\t\t\tkind: \"task:registered\",\n\t\t\tid,\n\t\t\tname,\n\t\t\ttaskKind: \"cron\",\n\t\t\texpression,\n\t\t});\n\t\treturn id;\n\t}\n\n\taddInterval(): string {\n\t\tthrow new Error(\n\t\t\t\"[schedule/cloudflare] setInterval is not supported on Workers. \" +\n\t\t\t\t\"Use @Cron with a short interval or use the memory backend for in-process scheduling.\",\n\t\t);\n\t}\n\n\taddTimeout(): string {\n\t\tthrow new Error(\n\t\t\t\"[schedule/cloudflare] setTimeout is not supported on Workers. \" +\n\t\t\t\t'Use @Cron with a delay (e.g. \"@every 30s\") or run the work from a request handler.',\n\t\t);\n\t}\n\n\tdelete(idOrName: string): boolean {\n\t\tconst id = this.#resolveId(idOrName);\n\t\tif (!id) return false;\n\t\tconst task = this.#tasks.get(id);\n\t\tif (!task) return false;\n\t\tthis.#tasks.delete(id);\n\t\tthis.#byName.delete(task.name);\n\t\tthis.#emit({ kind: \"task:deleted\", id });\n\t\treturn true;\n\t}\n\n\tlist(): ScheduledTask[] {\n\t\treturn [...this.#tasks.values()].map((t) => ({\n\t\t\tid: t.id,\n\t\t\tname: t.name,\n\t\t\tkind: \"cron\",\n\t\t\texpression: t.expression,\n\t\t\tstatus: \"running\",\n\t\t\tinvocations: 0,\n\t\t}));\n\t}\n\n\tget(idOrName: string): ScheduledTask | undefined {\n\t\tconst id = this.#resolveId(idOrName);\n\t\tif (!id) return undefined;\n\t\tconst t = this.#tasks.get(id);\n\t\treturn t\n\t\t\t? {\n\t\t\t\t\tid: t.id,\n\t\t\t\t\tname: t.name,\n\t\t\t\t\tkind: \"cron\",\n\t\t\t\t\texpression: t.expression,\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tinvocations: 0,\n\t\t\t\t}\n\t\t\t: undefined;\n\t}\n\n\tpause(): boolean {\n\t\t// No-op — Cloudflare controls the trigger. Edit wrangler.toml to disable.\n\t\treturn false;\n\t}\n\n\tresume(): boolean {\n\t\treturn false;\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tthis.#tasks.clear();\n\t\tthis.#byName.clear();\n\t}\n\n\t// ===========================================================================\n\t// Events\n\t// ===========================================================================\n\n\ton(listener: ScheduleEventListener): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t// ===========================================================================\n\t// Worker integration\n\t// ===========================================================================\n\n\t/**\n\t * Return the Worker's `scheduled()` handler. Mount it in the\n\t * default export:\n\t *\n\t * export default {\n\t * fetch: app.fetch,\n\t * scheduled: backend.scheduledHandler(),\n\t * };\n\t *\n\t * The handler dispatches based on the trigger's cron expression\n\t * (or, when validation is disabled, by event ordering).\n\t */\n\tscheduledHandler(): (event: CloudflareScheduledEvent) => Promise<void> {\n\t\treturn async (event) => {\n\t\t\tfor (const task of this.#tasks.values()) {\n\t\t\t\tif (this.#validate && task.expression !== event.cron) continue;\n\t\t\t\tawait this.#dispatch(task, event);\n\t\t\t}\n\t\t};\n\t}\n\n\tasync #dispatch(\n\t\ttask: InternalTask,\n\t\tevent: CloudflareScheduledEvent,\n\t): Promise<void> {\n\t\tconst startedAt = new Date();\n\t\tthis.#emit({\n\t\t\tkind: \"task:invoked\",\n\t\t\tid: task.id,\n\t\t\tname: task.name,\n\t\t\tstartedAt: startedAt.toISOString(),\n\t\t});\n\t\ttry {\n\t\t\tconst result = await task.handler();\n\t\t\tthis.#emit({\n\t\t\t\tkind: \"task:completed\",\n\t\t\t\tid: task.id,\n\t\t\t\tname: task.name,\n\t\t\t\tdurationMs: Date.now() - startedAt.getTime(),\n\t\t\t\treturnvalue: result,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tconst error = err instanceof Error ? err : new Error(String(err));\n\t\t\tthis.#emit({ kind: \"task:failed\", id: task.id, name: task.name, error });\n\t\t}\n\t\tvoid event; // (kept for future event-based logic)\n\t}\n\n\t// ===========================================================================\n\t// Internal\n\t// ===========================================================================\n\n\t#resolveId(idOrName: string): string | null {\n\t\tif (this.#tasks.has(idOrName)) return idOrName;\n\t\treturn this.#byName.get(idOrName) ?? null;\n\t}\n\n\t#emit(event: ScheduleEvent): void {\n\t\tfor (const l of this.#listeners) {\n\t\t\tvoid Promise.resolve(l(event));\n\t\t}\n\t}\n}\n",
|
|
8
|
-
"/**\n * `ScheduleService` — DI-friendly facade over a `ScheduleRegistry`.\n *\n * Mirrors the `@nestjs/schedule` API for familiarity. Controllers and\n * services can:\n * - Inject this and call `addCron / addInterval / addTimeout` to\n * schedule dynamically.\n * - Inject this and call `list / get / pause / resume / delete` to\n * introspect or mutate registered tasks.\n *\n * For static registration, use the `@Cron`, `@Interval`, `@Timeout`\n * decorators plus `ScheduleModule.scanForSchedulers(instance)`.\n */\n\nimport { Inject, Injectable } from '@nexusts/core
|
|
9
|
-
"/**\n * `ScheduleModule` — drop-in module for adding scheduled tasks to a\n * NexusTS app.\n *\n * Usage:\n * // src/app/app.module.ts\n * @Module({\n * imports: [\n * ScheduleModule.forRoot({\n * backend: 'memory', // or 'cloudflare'\n * defaultTimezone: 'UTC',\n * }),\n * ],\n * })\n * export class AppModule {}\n *\n * // any service\n * @Injectable()\n * class CleanupWorker {\n * constructor(@Inject(ScheduleService.TOKEN) private schedule: ScheduleService) {}\n *\n * @Cron('0 * * * *') // every hour\n * async hourly() {\n * // ...\n * }\n * }\n *\n * // bootstrap\n * const app = new Application(AppModule);\n * const schedule = app.container.resolve(ScheduleService);\n * await scanForSchedulers(worker, schedule);\n * schedule.start();\n */\n\nimport \"reflect-metadata\";\nimport { Module } from \"@nexusts/core
|
|
8
|
+
"/**\n * `ScheduleService` — DI-friendly facade over a `ScheduleRegistry`.\n *\n * Mirrors the `@nestjs/schedule` API for familiarity. Controllers and\n * services can:\n * - Inject this and call `addCron / addInterval / addTimeout` to\n * schedule dynamically.\n * - Inject this and call `list / get / pause / resume / delete` to\n * introspect or mutate registered tasks.\n *\n * For static registration, use the `@Cron`, `@Interval`, `@Timeout`\n * decorators plus `ScheduleModule.scanForSchedulers(instance)`.\n */\n\nimport { Inject, Injectable } from '@nexusts/core';\nimport type {\n\tScheduleRegistry,\n\tScheduleConfig,\n\tCronExpression,\n\tCronOptions,\n\tScheduledTask,\n\tScheduleHandler,\n\tScheduleEvent,\n\tScheduleEventListener,\n} from './types.js';\nimport {\n\tMemorySchedulesBackend,\n\tCloudflareSchedulesBackend,\n} from './backends/index.js';\n\n@Injectable()\nexport class ScheduleService {\n\t/** DI token — use with `@Inject(ScheduleService.TOKEN)`. */\n\tstatic readonly TOKEN = Symbol.for('nexus:ScheduleService');\n\n\treadonly registry: ScheduleRegistry;\n\t#listeners = new Set<ScheduleEventListener>();\n\t#started = false;\n\t#memoryBackend: MemorySchedulesBackend | null = null;\n\n\tconstructor(@Inject('SCHEDULE_CONFIG') private readonly config: ScheduleConfig = {}) {\n\t\tthis.registry = this.#createBackend(config);\n\t}\n\n\t// ===========================================================================\n\t// Static-style API (used by @Cron / @Interval / @Timeout decorators)\n\t// ===========================================================================\n\n\t/**\n\t * Schedule a cron task. Returns the assigned task id.\n\t */\n\taddCron(\n\t\texpression: CronExpression,\n\t\thandler: ScheduleHandler,\n\t\toptions: CronOptions & { name?: string } = {},\n\t): string {\n\t\tconst name = options.name ?? `cron-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;\n\t\treturn this.registry.addCron(name, expression, handler, options);\n\t}\n\n\taddInterval(milliseconds: number, handler: ScheduleHandler, name?: string): string {\n\t\treturn this.registry.addInterval(name ?? `interval-${Date.now()}`, milliseconds, handler);\n\t}\n\n\taddTimeout(milliseconds: number, handler: ScheduleHandler, name?: string): string {\n\t\treturn this.registry.addTimeout(name ?? `timeout-${Date.now()}`, milliseconds, handler);\n\t}\n\n\t// ===========================================================================\n\t// Introspection / mutation\n\t// ===========================================================================\n\n\tlist(): ScheduledTask[] {\n\t\treturn this.registry.list();\n\t}\n\n\tget(idOrName: string): ScheduledTask | undefined {\n\t\treturn this.registry.get(idOrName);\n\t}\n\n\tpause(idOrName: string): boolean {\n\t\treturn this.registry.pause(idOrName);\n\t}\n\n\tresume(idOrName: string): boolean {\n\t\treturn this.registry.resume(idOrName);\n\t}\n\n\tdelete(idOrName: string): boolean {\n\t\treturn this.registry.delete(idOrName);\n\t}\n\n\t// ===========================================================================\n\t// Events\n\t// ===========================================================================\n\n\ton(listener: ScheduleEventListener): () => void {\n\t\tthis.#listeners.add(listener);\n\t\treturn () => this.#listeners.delete(listener);\n\t}\n\n\t// ===========================================================================\n\t// Lifecycle\n\t// ===========================================================================\n\n\t/** Start the in-process scheduler tick. Idempotent. */\n\tstart(): void {\n\t\tif (this.#started) return;\n\t\tthis.#started = true;\n\t\tif (this.#memoryBackend) {\n\t\t\tthis.#memoryBackend.start();\n\t\t}\n\t\t// Bridge backend events.\n\t\tthis.registry.on((event) => this.#broadcast(event));\n\t}\n\n\tasync stop(): Promise<void> {\n\t\tif (!this.#started) return;\n\t\tthis.#started = false;\n\t\tawait this.registry.stop();\n\t}\n\n\t/**\n\t * Get the underlying in-process backend (for tests / `nx dev`).\n\t * Returns null when the configured backend isn't memory.\n\t */\n\tgetMemoryBackend(): MemorySchedulesBackend | null {\n\t\treturn this.#memoryBackend;\n\t}\n\n\t/**\n\t * Get the underlying Cloudflare backend (for Workers). Returns\n\t * null when the configured backend isn't Cloudflare.\n\t */\n\tgetCloudflareBackend(): CloudflareSchedulesBackend | null {\n\t\treturn this.registry instanceof CloudflareSchedulesBackend ? this.registry : null;\n\t}\n\n\t// ===========================================================================\n\t// Internal\n\t// ===========================================================================\n\n\t#createBackend(config: ScheduleConfig): ScheduleRegistry {\n\t\tswitch (config.backend ?? 'memory') {\n\t\t\tcase 'memory': {\n\t\t\t\tconst backend = new MemorySchedulesBackend({\n\t\t\t\t\ttickMs: config.memory?.tickMs ?? 1000,\n\t\t\t\t\tmaxDriftMs: config.memory?.maxDriftMs,\n\t\t\t\t\tdefaultTimezone: config.defaultTimezone,\n\t\t\t\t});\n\t\t\t\tthis.#memoryBackend = backend;\n\t\t\t\treturn backend;\n\t\t\t}\n\t\t\tcase 'cloudflare':\n\t\t\t\treturn new CloudflareSchedulesBackend();\n\t\t}\n\t}\n\n\t#broadcast(event: ScheduleEvent): void {\n\t\tfor (const l of this.#listeners) {\n\t\t\tvoid Promise.resolve(l(event));\n\t\t}\n\t}\n}",
|
|
9
|
+
"/**\n * `ScheduleModule` — drop-in module for adding scheduled tasks to a\n * NexusTS app.\n *\n * Usage:\n * // src/app/app.module.ts\n * @Module({\n * imports: [\n * ScheduleModule.forRoot({\n * backend: 'memory', // or 'cloudflare'\n * defaultTimezone: 'UTC',\n * }),\n * ],\n * })\n * export class AppModule {}\n *\n * // any service\n * @Injectable()\n * class CleanupWorker {\n * constructor(@Inject(ScheduleService.TOKEN) private schedule: ScheduleService) {}\n *\n * @Cron('0 * * * *') // every hour\n * async hourly() {\n * // ...\n * }\n * }\n *\n * // bootstrap\n * const app = new Application(AppModule);\n * const schedule = app.container.resolve(ScheduleService);\n * await scanForSchedulers(worker, schedule);\n * schedule.start();\n */\n\nimport \"reflect-metadata\";\nimport { Module } from \"@nexusts/core\";\nimport { ScheduleService } from \"./schedule.service.js\";\nimport type { ScheduleConfig } from \"./types.js\";\n\n@Module({\n\tproviders: [\n\t\tScheduleService,\n\t\t{ provide: ScheduleService.TOKEN, useExisting: ScheduleService },\n\t],\n\texports: [ScheduleService, ScheduleService.TOKEN],\n})\nexport class ScheduleModule {\n\t/**\n\t * Build a configured `ScheduleModule` class.\n\t */\n\tstatic forRoot(config: ScheduleConfig = {}) {\n\t\t@Module({\n\t\t\tproviders: [\n\t\t\t\tScheduleService,\n\t\t\t\t{ provide: ScheduleService.TOKEN, useExisting: ScheduleService },\n\t\t\t\t{ provide: \"SCHEDULE_CONFIG\", useValue: config },\n\t\t\t],\n\t\t\texports: [ScheduleService, ScheduleService.TOKEN],\n\t\t})\n\t\tclass ConfiguredScheduleModule {}\n\n\t\tObject.defineProperty(ConfiguredScheduleModule, \"name\", {\n\t\t\tvalue: \"ConfiguredScheduleModule\",\n\t\t});\n\n\t\treturn ConfiguredScheduleModule;\n\t}\n}\n",
|
|
10
10
|
"/**\n * `@Cron(expression)` — schedule a method as a cron task.\n *\n * Mirrors `@nestjs/schedule`'s decorator. The decorated method runs\n * on the cron schedule; pair it with `ScheduleModule.scanForSchedulers`\n * to register at boot.\n *\n * Usage:\n * @Injectable()\n * class CleanupWorker {\n * constructor(@Inject(ScheduleService.TOKEN) private schedule: ScheduleService) {}\n *\n * @Cron('0 * * * *') // every hour\n * async hourly() {\n * // ...\n * }\n *\n * @Cron('@daily', { timezone: 'UTC' })\n * async dailyDigest() {\n * // ...\n * }\n * }\n *\n * // src/app/main.ts\n * const app = new Application(AppModule);\n * const schedule = app.container.resolve(ScheduleService);\n * for (const instance of getInjectables(app)) {\n * await schedule.scanForSchedulers(instance);\n * }\n * schedule.start();\n */\n\nimport \"reflect-metadata\";\nimport type { ScheduleService } from \"../schedule.service.js\";\nimport type { CronExpression, CronOptions, ScheduleHandler } from \"../types.js\";\n\nconst CRON_META = \"nexus:schedule:cron\";\nconst INTERVAL_META = \"nexus:schedule:interval\";\nconst TIMEOUT_META = \"nexus:schedule:timeout\";\n\n/**\n * Schedule the decorated method as a cron task.\n */\nexport function Cron(\n\texpression: CronExpression,\n\toptions: CronOptions = {},\n): MethodDecorator {\n\treturn (target, propertyKey, descriptor) => {\n\t\tif (!descriptor || typeof descriptor.value !== \"function\") {\n\t\t\tthrow new Error(\"@Cron can only decorate methods.\");\n\t\t}\n\t\tconst ctor = target.constructor as object;\n\t\tconst hooks: Array<{\n\t\t\tmethod: string;\n\t\t\texpression: CronExpression;\n\t\t\toptions: CronOptions;\n\t\t}> =\n\t\t\t(Reflect.getMetadata(CRON_META, ctor) as\n\t\t\t\t| Array<{\n\t\t\t\t\t\tmethod: string;\n\t\t\t\t\t\texpression: CronExpression;\n\t\t\t\t\t\toptions: CronOptions;\n\t\t\t\t }>\n\t\t\t\t| undefined) ?? [];\n\t\thooks.push({ method: String(propertyKey), expression, options });\n\t\tReflect.defineMetadata(CRON_META, hooks, ctor);\n\t};\n}\n\n/**\n * Schedule the decorated method to run every `milliseconds`.\n */\nexport function Interval(milliseconds: number, name?: string): MethodDecorator {\n\treturn (target, propertyKey, descriptor) => {\n\t\tif (!descriptor || typeof descriptor.value !== \"function\") {\n\t\t\tthrow new Error(\"@Interval can only decorate methods.\");\n\t\t}\n\t\tconst ctor = target.constructor as object;\n\t\tconst hooks: Array<{\n\t\t\tmethod: string;\n\t\t\tmilliseconds: number;\n\t\t\tname?: string;\n\t\t}> =\n\t\t\t(Reflect.getMetadata(INTERVAL_META, ctor) as\n\t\t\t\t| Array<{ method: string; milliseconds: number; name?: string }>\n\t\t\t\t| undefined) ?? [];\n\t\thooks.push({ method: String(propertyKey), milliseconds, name });\n\t\tReflect.defineMetadata(INTERVAL_META, hooks, ctor);\n\t};\n}\n\n/**\n * Schedule the decorated method to run once after `milliseconds`.\n */\nexport function Timeout(milliseconds: number, name?: string): MethodDecorator {\n\treturn (target, propertyKey, descriptor) => {\n\t\tif (!descriptor || typeof descriptor.value !== \"function\") {\n\t\t\tthrow new Error(\"@Timeout can only decorate methods.\");\n\t\t}\n\t\tconst ctor = target.constructor as object;\n\t\tconst hooks: Array<{\n\t\t\tmethod: string;\n\t\t\tmilliseconds: number;\n\t\t\tname?: string;\n\t\t}> =\n\t\t\t(Reflect.getMetadata(TIMEOUT_META, ctor) as\n\t\t\t\t| Array<{ method: string; milliseconds: number; name?: string }>\n\t\t\t\t| undefined) ?? [];\n\t\thooks.push({ method: String(propertyKey), milliseconds, name });\n\t\tReflect.defineMetadata(TIMEOUT_META, hooks, ctor);\n\t};\n}\n\n/**\n * Get the cron hooks declared on a class.\n */\nexport function getCronHooks(\n\ttarget: unknown,\n): Array<{ method: string; expression: CronExpression; options: CronOptions }> {\n\tconst ctor =\n\t\t(target as { constructor?: object }).constructor ?? (target as object);\n\treturn (\n\t\t(Reflect.getMetadata(CRON_META, ctor) as\n\t\t\t| Array<{\n\t\t\t\t\tmethod: string;\n\t\t\t\t\texpression: CronExpression;\n\t\t\t\t\toptions: CronOptions;\n\t\t\t }>\n\t\t\t| undefined) ?? []\n\t);\n}\n\nexport function getIntervalHooks(\n\ttarget: unknown,\n): Array<{ method: string; milliseconds: number; name?: string }> {\n\tconst ctor =\n\t\t(target as { constructor?: object }).constructor ?? (target as object);\n\treturn (\n\t\t(Reflect.getMetadata(INTERVAL_META, ctor) as\n\t\t\t| Array<{ method: string; milliseconds: number; name?: string }>\n\t\t\t| undefined) ?? []\n\t);\n}\n\nexport function getTimeoutHooks(\n\ttarget: unknown,\n): Array<{ method: string; milliseconds: number; name?: string }> {\n\tconst ctor =\n\t\t(target as { constructor?: object }).constructor ?? (target as object);\n\treturn (\n\t\t(Reflect.getMetadata(TIMEOUT_META, ctor) as\n\t\t\t| Array<{ method: string; milliseconds: number; name?: string }>\n\t\t\t| undefined) ?? []\n\t);\n}\n\n/**\n * Scan an instance for `@Cron` / `@Interval` / `@Timeout` hooks and\n * register them with the `ScheduleService`.\n */\nexport async function scanForSchedulers(\n\tinstance: object,\n\tservice: ScheduleService,\n): Promise<string[]> {\n\tconst ids: string[] = [];\n\n\tfor (const h of getCronHooks(instance)) {\n\t\tconst fn = (instance as Record<string, unknown>)[h.method] as\n\t\t\t| ScheduleHandler\n\t\t\t| undefined;\n\t\tif (typeof fn !== \"function\") continue;\n\t\tconst id = service.addCron(h.expression, fn.bind(instance), {\n\t\t\t...h.options,\n\t\t\tname: h.options.name ?? `${instance.constructor.name}.${h.method}`,\n\t\t});\n\t\tids.push(id);\n\t}\n\n\tfor (const h of getIntervalHooks(instance)) {\n\t\tconst fn = (instance as Record<string, unknown>)[h.method] as\n\t\t\t| ScheduleHandler\n\t\t\t| undefined;\n\t\tif (typeof fn !== \"function\") continue;\n\t\tconst id = service.addInterval(\n\t\t\th.milliseconds,\n\t\t\tfn.bind(instance),\n\t\t\th.name ?? `${instance.constructor.name}.${h.method}`,\n\t\t);\n\t\tids.push(id);\n\t}\n\n\tfor (const h of getTimeoutHooks(instance)) {\n\t\tconst fn = (instance as Record<string, unknown>)[h.method] as\n\t\t\t| ScheduleHandler\n\t\t\t| undefined;\n\t\tif (typeof fn !== \"function\") continue;\n\t\tconst id = service.addTimeout(\n\t\t\th.milliseconds,\n\t\t\tfn.bind(instance),\n\t\t\th.name ?? `${instance.constructor.name}.${h.method}`,\n\t\t);\n\t\tids.push(id);\n\t}\n\n\treturn ids;\n}\n\n// Re-export for convenience.\nexport type { ScheduleService };\n"
|
|
11
11
|
],
|
|
12
12
|
"mappings": ";;;;;;;;;;;;;;;;;AAsBA,IAAM,eAAwC;AAAA,EAC7C,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,EAAE;AAAA,EACN,CAAC,GAAG,CAAC;AACN;AAEA,IAAM,cAAsC;AAAA,EAC3C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAEA,IAAM,UAAkC;AAAA,EACvC,WAAW;AAAA,EACX,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa;AAAA,EACb,WAAW;AACZ;AAAA;AAGO,MAAM,UAAU;AAAA,EACb;AAAA,EAET,WAAW,CAAC,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,GAAG,KAAK,QAAQ,GAAG;AAAA,SACxD,EAAE;AAAA,MACL,MAAM,EAAE,QAAQ,QAAQ,GAAG,SAAS,YAAY,QAAQ,EAAE;AAAA,IAC3D,CAAC;AAAA,IACD,IAAI,KAAK,EAAE;AAAA,EACZ;AAAA,EAEA,WAAW,KAAK,iBAAiB,QAAQ,GAAG;AAAA,IAC3C,MAAM,KAAM,SAAqC,EAAE;AAAA,IAGnD,IAAI,OAAO,OAAO;AAAA,MAAY;AAAA,IAC9B,MAAM,KAAK,QAAQ,YAClB,EAAE,cACF,GAAG,KAAK,QAAQ,GAChB,EAAE,QAAQ,GAAG,SAAS,YAAY,QAAQ,EAAE,QAC7C;AAAA,IACA,IAAI,KAAK,EAAE;AAAA,EACZ;AAAA,EAEA,WAAW,KAAK,gBAAgB,QAAQ,GAAG;AAAA,IAC1C,MAAM,KAAM,SAAqC,EAAE;AAAA,IAGnD,IAAI,OAAO,OAAO;AAAA,MAAY;AAAA,IAC9B,MAAM,KAAK,QAAQ,WAClB,EAAE,cACF,GAAG,KAAK,QAAQ,GAChB,EAAE,QAAQ,GAAG,SAAS,YAAY,QAAQ,EAAE,QAC7C;AAAA,IACA,IAAI,KAAK,EAAE;AAAA,EACZ;AAAA,EAEA,OAAO;AAAA;",
|
|
13
|
-
"debugId": "
|
|
13
|
+
"debugId": "BE7269D6BACECC6B64756E2164756E21",
|
|
14
14
|
"names": []
|
|
15
15
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ScheduleModule` — drop-in module for adding scheduled tasks to a
|
|
3
|
+
* NexusTS app.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* // src/app/app.module.ts
|
|
7
|
+
* @Module({
|
|
8
|
+
* imports: [
|
|
9
|
+
* ScheduleModule.forRoot({
|
|
10
|
+
* backend: 'memory', // or 'cloudflare'
|
|
11
|
+
* defaultTimezone: 'UTC',
|
|
12
|
+
* }),
|
|
13
|
+
* ],
|
|
14
|
+
* })
|
|
15
|
+
* export class AppModule {}
|
|
16
|
+
*
|
|
17
|
+
* // any service
|
|
18
|
+
* @Injectable()
|
|
19
|
+
* class CleanupWorker {
|
|
20
|
+
* constructor(@Inject(ScheduleService.TOKEN) private schedule: ScheduleService) {}
|
|
21
|
+
*
|
|
22
|
+
* @Cron('0 * * * *') // every hour
|
|
23
|
+
* async hourly() {
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* // bootstrap
|
|
29
|
+
* const app = new Application(AppModule);
|
|
30
|
+
* const schedule = app.container.resolve(ScheduleService);
|
|
31
|
+
* await scanForSchedulers(worker, schedule);
|
|
32
|
+
* schedule.start();
|
|
33
|
+
*/
|
|
34
|
+
import "reflect-metadata";
|
|
35
|
+
import type { ScheduleConfig } from "./types.js";
|
|
36
|
+
export declare class ScheduleModule {
|
|
37
|
+
/**
|
|
38
|
+
* Build a configured `ScheduleModule` class.
|
|
39
|
+
*/
|
|
40
|
+
static forRoot(config?: ScheduleConfig): {
|
|
41
|
+
new (): {};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ScheduleService` — DI-friendly facade over a `ScheduleRegistry`.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the `@nestjs/schedule` API for familiarity. Controllers and
|
|
5
|
+
* services can:
|
|
6
|
+
* - Inject this and call `addCron / addInterval / addTimeout` to
|
|
7
|
+
* schedule dynamically.
|
|
8
|
+
* - Inject this and call `list / get / pause / resume / delete` to
|
|
9
|
+
* introspect or mutate registered tasks.
|
|
10
|
+
*
|
|
11
|
+
* For static registration, use the `@Cron`, `@Interval`, `@Timeout`
|
|
12
|
+
* decorators plus `ScheduleModule.scanForSchedulers(instance)`.
|
|
13
|
+
*/
|
|
14
|
+
import type { ScheduleRegistry, ScheduleConfig, CronExpression, CronOptions, ScheduledTask, ScheduleHandler, ScheduleEventListener } from './types.js';
|
|
15
|
+
import { MemorySchedulesBackend, CloudflareSchedulesBackend } from './backends/index.js';
|
|
16
|
+
export declare class ScheduleService {
|
|
17
|
+
#private;
|
|
18
|
+
private readonly config;
|
|
19
|
+
/** DI token — use with `@Inject(ScheduleService.TOKEN)`. */
|
|
20
|
+
static readonly TOKEN: unique symbol;
|
|
21
|
+
readonly registry: ScheduleRegistry;
|
|
22
|
+
constructor(config?: ScheduleConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Schedule a cron task. Returns the assigned task id.
|
|
25
|
+
*/
|
|
26
|
+
addCron(expression: CronExpression, handler: ScheduleHandler, options?: CronOptions & {
|
|
27
|
+
name?: string;
|
|
28
|
+
}): string;
|
|
29
|
+
addInterval(milliseconds: number, handler: ScheduleHandler, name?: string): string;
|
|
30
|
+
addTimeout(milliseconds: number, handler: ScheduleHandler, name?: string): string;
|
|
31
|
+
list(): ScheduledTask[];
|
|
32
|
+
get(idOrName: string): ScheduledTask | undefined;
|
|
33
|
+
pause(idOrName: string): boolean;
|
|
34
|
+
resume(idOrName: string): boolean;
|
|
35
|
+
delete(idOrName: string): boolean;
|
|
36
|
+
on(listener: ScheduleEventListener): () => void;
|
|
37
|
+
/** Start the in-process scheduler tick. Idempotent. */
|
|
38
|
+
start(): void;
|
|
39
|
+
stop(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Get the underlying in-process backend (for tests / `nx dev`).
|
|
42
|
+
* Returns null when the configured backend isn't memory.
|
|
43
|
+
*/
|
|
44
|
+
getMemoryBackend(): MemorySchedulesBackend | null;
|
|
45
|
+
/**
|
|
46
|
+
* Get the underlying Cloudflare backend (for Workers). Returns
|
|
47
|
+
* null when the configured backend isn't Cloudflare.
|
|
48
|
+
*/
|
|
49
|
+
getCloudflareBackend(): CloudflareSchedulesBackend | null;
|
|
50
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedule types — the public contract for `nexusjs/schedule`.
|
|
3
|
+
*
|
|
4
|
+
* The schedule module wraps three kinds of recurring work:
|
|
5
|
+
*
|
|
6
|
+
* - @Cron(expr) — runs on a cron expression (`* * * * *`)
|
|
7
|
+
* - @Interval(ms) — runs every N milliseconds
|
|
8
|
+
* - @Timeout(ms) — runs once after N milliseconds
|
|
9
|
+
*
|
|
10
|
+
* Behind a `ScheduleBackend` interface, with two implementations:
|
|
11
|
+
* - in-process (Bun / Node) — setInterval-driven, in-memory
|
|
12
|
+
* - Cloudflare Cron Triggers — Workers-native, declared in wrangler.toml
|
|
13
|
+
*
|
|
14
|
+
* The shape mirrors nestjs/schedule so users coming from that
|
|
15
|
+
* ecosystem feel at home.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* A cron expression as a string. Supports:
|
|
19
|
+
* - 5 fields: `* * * * *` (minute hour day month weekday)
|
|
20
|
+
* - 6 fields: `* * * * * *` (second + the above)
|
|
21
|
+
* - Aliases: @yearly, @annually, @monthly, @weekly, @daily,
|
|
22
|
+
* @midnight, @hourly
|
|
23
|
+
* - Intervals: @every 1h, @every 30m, @every 15s, @every 1d
|
|
24
|
+
* - Wildcards, lists, ranges, steps: *, 1\,3\,5, 1-5, star-slash-2
|
|
25
|
+
* - Names: JAN-DEC, SUN-SAT (case-insensitive)
|
|
26
|
+
*/
|
|
27
|
+
export type CronExpression = string;
|
|
28
|
+
/** Options applied to a scheduled task. */
|
|
29
|
+
export interface CronOptions {
|
|
30
|
+
/** Display name. Default: method name. */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** IANA timezone, e.g. `America/New_York`. Default: host's local TZ. */
|
|
33
|
+
timezone?: string;
|
|
34
|
+
/** Run immediately on register instead of waiting for the first tick. */
|
|
35
|
+
runOnInit?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/** A scheduled task's status. */
|
|
38
|
+
export type TaskStatus = "running" | "stopped" | "paused";
|
|
39
|
+
/** What kind of schedule a task uses. */
|
|
40
|
+
export type TaskKind = "cron" | "interval" | "timeout";
|
|
41
|
+
/** A registered scheduled task. */
|
|
42
|
+
export interface ScheduledTask {
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
kind: TaskKind;
|
|
46
|
+
expression: string;
|
|
47
|
+
/** Current status. */
|
|
48
|
+
status: TaskStatus;
|
|
49
|
+
/** Number of invocations so far. */
|
|
50
|
+
invocations: number;
|
|
51
|
+
/** When the task last started (ISO). */
|
|
52
|
+
lastRunAt?: string;
|
|
53
|
+
/** When the next invocation is scheduled (ISO), if known. */
|
|
54
|
+
nextRunAt?: string;
|
|
55
|
+
/** Last error message, if any. */
|
|
56
|
+
lastError?: string;
|
|
57
|
+
}
|
|
58
|
+
/** A handler invoked by the scheduler. */
|
|
59
|
+
export type ScheduleHandler = () => void | Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Registry contract — every backend implements this. The
|
|
62
|
+
* ScheduleService is the user-facing facade.
|
|
63
|
+
*/
|
|
64
|
+
export interface ScheduleRegistry {
|
|
65
|
+
/**
|
|
66
|
+
* Register a cron task. Returns the assigned task id.
|
|
67
|
+
*/
|
|
68
|
+
addCron(name: string, expression: CronExpression, handler: ScheduleHandler, options?: CronOptions): string;
|
|
69
|
+
/**
|
|
70
|
+
* Register a recurring task.
|
|
71
|
+
*/
|
|
72
|
+
addInterval(name: string, milliseconds: number, handler: ScheduleHandler): string;
|
|
73
|
+
/**
|
|
74
|
+
* Register a one-shot delayed task.
|
|
75
|
+
*/
|
|
76
|
+
addTimeout(name: string, milliseconds: number, handler: ScheduleHandler): string;
|
|
77
|
+
/** Delete a task by id. Returns true if it existed. */
|
|
78
|
+
delete(id: string): boolean;
|
|
79
|
+
/** List all registered tasks. */
|
|
80
|
+
list(): ScheduledTask[];
|
|
81
|
+
/** Get one task by id (or by name — first match). */
|
|
82
|
+
get(idOrName: string): ScheduledTask | undefined;
|
|
83
|
+
/** Pause a task without removing it. */
|
|
84
|
+
pause(idOrName: string): boolean;
|
|
85
|
+
/** Resume a paused task. */
|
|
86
|
+
resume(idOrName: string): boolean;
|
|
87
|
+
/** Stop the registry entirely. Workers / intervals are cleared. */
|
|
88
|
+
stop(): Promise<void>;
|
|
89
|
+
/** Subscribe to schedule events. Returns an unsubscribe function. */
|
|
90
|
+
on(listener: ScheduleEventListener): () => void;
|
|
91
|
+
}
|
|
92
|
+
export type ScheduleBackendKind = "memory" | "cloudflare";
|
|
93
|
+
export interface ScheduleConfig {
|
|
94
|
+
/** Backend to use. Default: memory. */
|
|
95
|
+
backend?: ScheduleBackendKind;
|
|
96
|
+
/** Default timezone applied to every cron task. Default: host local. */
|
|
97
|
+
defaultTimezone?: string;
|
|
98
|
+
/** Run tasks in-process even when the configured backend is Cloudflare. */
|
|
99
|
+
/** Cloudflare Cron Triggers run separately at the platform level; */
|
|
100
|
+
/** this flag is mostly useful for tests. */
|
|
101
|
+
dualRun?: boolean;
|
|
102
|
+
/** Cron config specific to the in-process backend. */
|
|
103
|
+
memory?: {
|
|
104
|
+
/** Tick interval in ms. Default: 1000. */
|
|
105
|
+
tickMs?: number;
|
|
106
|
+
/** Skip tasks that fall behind by more than N ms. Default: 60_000. */
|
|
107
|
+
maxDriftMs?: number;
|
|
108
|
+
};
|
|
109
|
+
/** Cron config specific to Cloudflare. */
|
|
110
|
+
cloudflare?: {
|
|
111
|
+
/** Cron trigger name (matches wrangler.toml). */
|
|
112
|
+
triggerName: string;
|
|
113
|
+
/** Cron expression forwarded to the trigger. */
|
|
114
|
+
expression: CronExpression;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export type ScheduleEvent = {
|
|
118
|
+
kind: "task:registered";
|
|
119
|
+
id: string;
|
|
120
|
+
name: string;
|
|
121
|
+
taskKind: TaskKind;
|
|
122
|
+
expression: string;
|
|
123
|
+
} | {
|
|
124
|
+
kind: "task:invoked";
|
|
125
|
+
id: string;
|
|
126
|
+
name: string;
|
|
127
|
+
startedAt: string;
|
|
128
|
+
} | {
|
|
129
|
+
kind: "task:completed";
|
|
130
|
+
id: string;
|
|
131
|
+
name: string;
|
|
132
|
+
durationMs: number;
|
|
133
|
+
returnvalue?: unknown;
|
|
134
|
+
} | {
|
|
135
|
+
kind: "task:failed";
|
|
136
|
+
id: string;
|
|
137
|
+
name: string;
|
|
138
|
+
error: Error;
|
|
139
|
+
} | {
|
|
140
|
+
kind: "task:paused";
|
|
141
|
+
id: string;
|
|
142
|
+
} | {
|
|
143
|
+
kind: "task:resumed";
|
|
144
|
+
id: string;
|
|
145
|
+
} | {
|
|
146
|
+
kind: "task:deleted";
|
|
147
|
+
id: string;
|
|
148
|
+
};
|
|
149
|
+
export type ScheduleEventListener = (event: ScheduleEvent) => void | Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexusts/schedule",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Cron scheduling (@Cron / @Interval / @Timeout)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,20 +12,15 @@
|
|
|
12
12
|
"import": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist",
|
|
17
|
-
"README.md"
|
|
18
|
-
],
|
|
15
|
+
"files": ["dist", "README.md"],
|
|
19
16
|
"scripts": {
|
|
20
17
|
"build": "bun run ../../build.ts"
|
|
21
18
|
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"nexusts",
|
|
24
|
-
"framework",
|
|
25
|
-
"bun"
|
|
26
|
-
],
|
|
19
|
+
"keywords": ["nexusts", "framework", "bun"],
|
|
27
20
|
"license": "MIT",
|
|
21
|
+
|
|
22
|
+
|
|
28
23
|
"dependencies": {
|
|
29
|
-
"@nexusts/core": "
|
|
24
|
+
"@nexusts/core": "file:../core"
|
|
30
25
|
}
|
|
31
26
|
}
|