@nest-boot/schedule 7.0.1 → 7.0.3
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/dist/schedule-module-options.interface.d.ts +12 -0
- package/dist/schedule-options.interface.d.ts +4 -0
- package/dist/schedule.decorator.d.ts +17 -0
- package/dist/schedule.decorator.js +17 -0
- package/dist/schedule.decorator.js.map +1 -1
- package/dist/schedule.module-definition.d.ts +1 -1
- package/dist/schedule.module-definition.js +2 -2
- package/dist/schedule.module-definition.js.map +1 -1
- package/dist/schedule.module.d.ts +21 -1
- package/dist/schedule.module.js +24 -1
- package/dist/schedule.module.js.map +1 -1
- package/dist/schedule.registry.d.ts +29 -0
- package/dist/schedule.registry.js +27 -0
- package/dist/schedule.registry.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +22 -13
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { type RegisterQueueOptions } from "@nest-boot/bullmq";
|
|
2
|
+
import { type ConnectionOptions } from "bullmq";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the schedule module.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Extends BullMQ queue options with schedule-specific settings
|
|
8
|
+
* for controlling job processing behavior.
|
|
9
|
+
*/
|
|
2
10
|
export interface ScheduleModuleOptions extends RegisterQueueOptions {
|
|
11
|
+
/** Whether to automatically start processing scheduled jobs on module init. */
|
|
3
12
|
autorun?: boolean;
|
|
13
|
+
/** Maximum number of concurrent scheduled jobs to process. */
|
|
4
14
|
concurrency?: number;
|
|
15
|
+
/** Optional Redis connection options for the schedule queue. */
|
|
16
|
+
connection?: ConnectionOptions;
|
|
5
17
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { JobSchedulerTemplateOptions } from "bullmq";
|
|
2
|
+
/** Options for configuring a scheduled job. */
|
|
2
3
|
export interface ScheduleOptions extends JobSchedulerTemplateOptions {
|
|
4
|
+
/** Type of schedule: `"cron"` for cron expressions or `"interval"` for millisecond intervals. */
|
|
3
5
|
type: "cron" | "interval";
|
|
6
|
+
/** Cron expression (for `"cron"` type) or millisecond interval (for `"interval"` type). */
|
|
4
7
|
value: number | string;
|
|
8
|
+
/** Timezone for cron expressions (defaults to `"UTC"`). */
|
|
5
9
|
timezone?: string;
|
|
6
10
|
}
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
import { type ScheduleOptions } from "./schedule-options.interface";
|
|
2
|
+
/**
|
|
3
|
+
* Decorator that registers a method as a scheduled job.
|
|
4
|
+
* @param options - Schedule configuration (type, value, timezone, etc.)
|
|
5
|
+
* @returns Method decorator
|
|
6
|
+
*/
|
|
2
7
|
export declare const Schedule: (options: ScheduleOptions) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Decorator that registers a method as a cron-scheduled job.
|
|
10
|
+
* @param value - Cron expression (e.g. `"0 * * * *"`)
|
|
11
|
+
* @param options - Additional schedule options (timezone, etc.)
|
|
12
|
+
* @returns Method decorator
|
|
13
|
+
*/
|
|
3
14
|
export declare const Cron: (value: string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Decorator that registers a method as an interval-scheduled job.
|
|
17
|
+
* @param value - Interval in milliseconds
|
|
18
|
+
* @param options - Additional schedule options
|
|
19
|
+
* @returns Method decorator
|
|
20
|
+
*/
|
|
4
21
|
export declare const Interval: (value: number | string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
@@ -3,16 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Interval = exports.Cron = exports.Schedule = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const schedule_module_definition_1 = require("./schedule.module-definition");
|
|
6
|
+
/**
|
|
7
|
+
* Decorator that registers a method as a scheduled job.
|
|
8
|
+
* @param options - Schedule configuration (type, value, timezone, etc.)
|
|
9
|
+
* @returns Method decorator
|
|
10
|
+
*/
|
|
6
11
|
const Schedule = (options) => (target, propertyKey, descriptor) => {
|
|
7
12
|
(0, common_1.SetMetadata)(schedule_module_definition_1.SCHEDULE_METADATA_KEY, options)(target, propertyKey, descriptor);
|
|
8
13
|
};
|
|
9
14
|
exports.Schedule = Schedule;
|
|
15
|
+
/**
|
|
16
|
+
* Decorator that registers a method as a cron-scheduled job.
|
|
17
|
+
* @param value - Cron expression (e.g. `"0 * * * *"`)
|
|
18
|
+
* @param options - Additional schedule options (timezone, etc.)
|
|
19
|
+
* @returns Method decorator
|
|
20
|
+
*/
|
|
10
21
|
const Cron = (value, options) => (0, exports.Schedule)({
|
|
11
22
|
type: "cron",
|
|
12
23
|
value,
|
|
13
24
|
...(options ?? {}),
|
|
14
25
|
});
|
|
15
26
|
exports.Cron = Cron;
|
|
27
|
+
/**
|
|
28
|
+
* Decorator that registers a method as an interval-scheduled job.
|
|
29
|
+
* @param value - Interval in milliseconds
|
|
30
|
+
* @param options - Additional schedule options
|
|
31
|
+
* @returns Method decorator
|
|
32
|
+
*/
|
|
16
33
|
const Interval = (value, options) => (0, exports.Schedule)({
|
|
17
34
|
type: "interval",
|
|
18
35
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6EAAqE;
|
|
1
|
+
{"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6EAAqE;AAGrE;;;;GAIG;AACI,MAAM,QAAQ,GACnB,CAAC,OAAwB,EAAE,EAAE,CAC7B,CACE,MAAc,EACd,WAAmB,EACnB,UAAsC,EACtC,EAAE;IACF,IAAA,oBAAW,EAA0B,kDAAqB,EAAE,OAAO,CAAC,CAClE,MAAM,EACN,WAAW,EACX,UAAU,CACX,CAAC;AACJ,CAAC,CAAC;AAZS,QAAA,QAAQ,YAYjB;AAEJ;;;;;GAKG;AACI,MAAM,IAAI,GAAG,CAClB,KAAa,EACb,OAAiD,EACjD,EAAE,CACF,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,MAAM;IACZ,KAAK;IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC;AARQ,QAAA,IAAI,QAQZ;AAEL;;;;;GAKG;AACI,MAAM,QAAQ,GAAG,CACtB,KAAsB,EACtB,OAAiD,EACjD,EAAE,CACF,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,UAAU;IAChB,KAAK;IACL,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;CACnB,CAAC,CAAC;AARQ,QAAA,QAAQ,YAQhB"}
|
|
@@ -2,4 +2,4 @@ import { type ScheduleModuleOptions } from "./schedule-module-options.interface"
|
|
|
2
2
|
export declare const SCHEDULE_QUEUE_NAME = "schedule";
|
|
3
3
|
export declare const SCHEDULE_METADATA_KEY: `${string}-${string}-${string}-${string}-${string}`;
|
|
4
4
|
export declare const MODULE_OPTIONS_TOKEN: unique symbol;
|
|
5
|
-
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ScheduleModuleOptions, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol
|
|
5
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ScheduleModuleOptions, "forRoot", "create", {}>, BASE_MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: ScheduleModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<ScheduleModuleOptions, "create"> & Partial<{}>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = exports.SCHEDULE_METADATA_KEY = exports.SCHEDULE_QUEUE_NAME = void 0;
|
|
4
|
+
exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.BASE_MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = exports.MODULE_OPTIONS_TOKEN = exports.SCHEDULE_METADATA_KEY = exports.SCHEDULE_QUEUE_NAME = void 0;
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const crypto_1 = require("crypto");
|
|
7
7
|
exports.SCHEDULE_QUEUE_NAME = "schedule";
|
|
@@ -9,5 +9,5 @@ exports.SCHEDULE_METADATA_KEY = (0, crypto_1.randomUUID)();
|
|
|
9
9
|
exports.MODULE_OPTIONS_TOKEN = Symbol("ScheduleModuleOptions");
|
|
10
10
|
_a = new common_1.ConfigurableModuleBuilder()
|
|
11
11
|
.setClassMethodName("forRoot")
|
|
12
|
-
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN;
|
|
12
|
+
.build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.BASE_MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
|
|
13
13
|
//# sourceMappingURL=schedule.module-definition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.module-definition.js","sourceRoot":"","sources":["../src/schedule.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,mCAAoC;AAIvB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAEjC,QAAA,qBAAqB,GAAG,IAAA,mBAAU,GAAE,CAAC;AAErC,QAAA,oBAAoB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAEvD,
|
|
1
|
+
{"version":3,"file":"schedule.module-definition.js","sourceRoot":"","sources":["../src/schedule.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAC3D,mCAAoC;AAIvB,QAAA,mBAAmB,GAAG,UAAU,CAAC;AAEjC,QAAA,qBAAqB,GAAG,IAAA,mBAAU,GAAE,CAAC;AAErC,QAAA,oBAAoB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAEvD,KAKT,IAAI,kCAAyB,EAAyB;KACvD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EANR,+BAAuB,+BACD,iCAAyB,4BAC/C,oBAAY,oBACZ,0BAAkB,yBAGT"}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./schedule.module-definition";
|
|
3
|
+
/**
|
|
4
|
+
* Job scheduling module powered by BullMQ.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Provides cron-like job scheduling using BullMQ queues.
|
|
8
|
+
* Supports decorator-based schedule registration and configurable concurrency.
|
|
9
|
+
*/
|
|
2
10
|
export declare class ScheduleModule extends ConfigurableModuleClass {
|
|
11
|
+
/**
|
|
12
|
+
* Registers the ScheduleModule with the given options.
|
|
13
|
+
* @param options - Configuration options including connection and concurrency
|
|
14
|
+
* @returns Dynamic module configuration
|
|
15
|
+
*/
|
|
16
|
+
static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
17
|
+
/**
|
|
18
|
+
* Registers the ScheduleModule asynchronously with factory functions.
|
|
19
|
+
* @param options - Async configuration options
|
|
20
|
+
* @returns Dynamic module configuration
|
|
21
|
+
*/
|
|
22
|
+
static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
|
|
3
23
|
}
|
package/dist/schedule.module.js
CHANGED
|
@@ -13,7 +13,30 @@ const core_1 = require("@nestjs/core");
|
|
|
13
13
|
const schedule_module_definition_1 = require("./schedule.module-definition");
|
|
14
14
|
const schedule_processor_1 = require("./schedule.processor");
|
|
15
15
|
const schedule_registry_1 = require("./schedule.registry");
|
|
16
|
+
/**
|
|
17
|
+
* Job scheduling module powered by BullMQ.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Provides cron-like job scheduling using BullMQ queues.
|
|
21
|
+
* Supports decorator-based schedule registration and configurable concurrency.
|
|
22
|
+
*/
|
|
16
23
|
let ScheduleModule = class ScheduleModule extends schedule_module_definition_1.ConfigurableModuleClass {
|
|
24
|
+
/**
|
|
25
|
+
* Registers the ScheduleModule with the given options.
|
|
26
|
+
* @param options - Configuration options including connection and concurrency
|
|
27
|
+
* @returns Dynamic module configuration
|
|
28
|
+
*/
|
|
29
|
+
static forRoot(options) {
|
|
30
|
+
return super.forRoot(options);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Registers the ScheduleModule asynchronously with factory functions.
|
|
34
|
+
* @param options - Async configuration options
|
|
35
|
+
* @returns Dynamic module configuration
|
|
36
|
+
*/
|
|
37
|
+
static forRootAsync(options) {
|
|
38
|
+
return super.forRootAsync(options);
|
|
39
|
+
}
|
|
17
40
|
};
|
|
18
41
|
exports.ScheduleModule = ScheduleModule;
|
|
19
42
|
exports.ScheduleModule = ScheduleModule = __decorate([
|
|
@@ -34,7 +57,7 @@ exports.ScheduleModule = ScheduleModule = __decorate([
|
|
|
34
57
|
{
|
|
35
58
|
provide: schedule_module_definition_1.MODULE_OPTIONS_TOKEN,
|
|
36
59
|
inject: [{ token: schedule_module_definition_1.BASE_MODULE_OPTIONS_TOKEN, optional: true }],
|
|
37
|
-
useFactory: (options
|
|
60
|
+
useFactory: (options) => options ?? {},
|
|
38
61
|
},
|
|
39
62
|
],
|
|
40
63
|
exports: [schedule_module_definition_1.MODULE_OPTIONS_TOKEN],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,8CAA+C;AAC/C,2CAA4E;AAC5E,uCAA+C;AAE/C,6EAMsC;AACtC,6DAAyD;AACzD,2DAAuD;AAGvD;;;;;;GAMG;AAuBI,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,oDAAuB;IACzD;;;;OAIG;IACH,MAAM,CAAU,OAAO,CAAC,OAA4B;QAClD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAU,YAAY,CAC1B,OAAkC;QAElC,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACF,CAAA;AApBY,wCAAc;yBAAd,cAAc;IAtB1B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,sBAAe;YACf,mBAAU,CAAC,kBAAkB,CAAC;gBAC5B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,CAAC,iDAAoB,CAAC;gBAC9B,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,OAAO;aACxD,CAAC;SACH;QACD,SAAS,EAAE;YACT,eAAM;YACN,oCAAgB;YAChB,sCAAiB;YACjB;gBACE,OAAO,EAAE,iDAAoB;gBAC7B,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,sDAAyB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAC9D,UAAU,EAAE,CAAC,OAA+B,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE;aAC/D;SACF;QACD,OAAO,EAAE,CAAC,iDAAoB,CAAC;KAChC,CAAC;GACW,cAAc,CAoB1B"}
|
|
@@ -2,20 +2,49 @@ import { OnApplicationBootstrap } from "@nestjs/common";
|
|
|
2
2
|
import { DiscoveryService, MetadataScanner, Reflector } from "@nestjs/core";
|
|
3
3
|
import { Queue } from "bullmq";
|
|
4
4
|
import { type ScheduleOptions } from "./schedule-options.interface";
|
|
5
|
+
/**
|
|
6
|
+
* Registry that discovers and manages scheduled jobs at application startup.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Scans all controllers and providers for methods decorated with
|
|
10
|
+
* {@link Schedule}, {@link Cron}, or {@link Interval}, then registers
|
|
11
|
+
* them as BullMQ job schedulers. Removes stale schedulers that are no
|
|
12
|
+
* longer defined in the codebase.
|
|
13
|
+
*/
|
|
5
14
|
export declare class ScheduleRegistry implements OnApplicationBootstrap {
|
|
6
15
|
private readonly queue;
|
|
7
16
|
private readonly reflector;
|
|
8
17
|
private readonly discoveryService;
|
|
9
18
|
private readonly metadataScanner;
|
|
19
|
+
/** Logger instance for the schedule registry. @internal */
|
|
10
20
|
private readonly logger;
|
|
21
|
+
/** Map of schedule names to their handlers and options. @internal */
|
|
11
22
|
private readonly schedules;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new ScheduleRegistry instance.
|
|
25
|
+
* @param queue - BullMQ queue for managing scheduled jobs
|
|
26
|
+
* @param reflector - NestJS reflector for reading decorator metadata
|
|
27
|
+
* @param discoveryService - NestJS discovery service for scanning providers
|
|
28
|
+
* @param metadataScanner - Scanner for extracting method metadata
|
|
29
|
+
*/
|
|
12
30
|
constructor(queue: Queue, reflector: Reflector, discoveryService: DiscoveryService, metadataScanner: MetadataScanner);
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a registered schedule entry by name.
|
|
33
|
+
* @param name - The schedule identifier (className.methodName)
|
|
34
|
+
* @returns The schedule handler and options, or undefined
|
|
35
|
+
*/
|
|
13
36
|
get(name: string): {
|
|
37
|
+
/** Handler function bound to the original instance. */
|
|
14
38
|
handler: () => Promise<void>;
|
|
39
|
+
/** Schedule options from the decorator. */
|
|
15
40
|
options: ScheduleOptions;
|
|
16
41
|
} | undefined;
|
|
42
|
+
/** Scans controllers and providers for schedule-decorated methods. @internal */
|
|
17
43
|
private discoverySchedules;
|
|
44
|
+
/** Removes job schedulers that are no longer defined. @internal */
|
|
18
45
|
private cleanUnregisteredSchedules;
|
|
46
|
+
/** Registers all discovered schedules as BullMQ job schedulers. @internal */
|
|
19
47
|
private registerSchedules;
|
|
48
|
+
/** Discovers all scheduled methods and registers them as BullMQ job schedulers. */
|
|
20
49
|
onApplicationBootstrap(): Promise<void>;
|
|
21
50
|
}
|
|
@@ -19,18 +19,42 @@ const common_1 = require("@nestjs/common");
|
|
|
19
19
|
const core_1 = require("@nestjs/core");
|
|
20
20
|
const bullmq_2 = require("bullmq");
|
|
21
21
|
const schedule_module_definition_1 = require("./schedule.module-definition");
|
|
22
|
+
/**
|
|
23
|
+
* Registry that discovers and manages scheduled jobs at application startup.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Scans all controllers and providers for methods decorated with
|
|
27
|
+
* {@link Schedule}, {@link Cron}, or {@link Interval}, then registers
|
|
28
|
+
* them as BullMQ job schedulers. Removes stale schedulers that are no
|
|
29
|
+
* longer defined in the codebase.
|
|
30
|
+
*/
|
|
22
31
|
let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new ScheduleRegistry instance.
|
|
34
|
+
* @param queue - BullMQ queue for managing scheduled jobs
|
|
35
|
+
* @param reflector - NestJS reflector for reading decorator metadata
|
|
36
|
+
* @param discoveryService - NestJS discovery service for scanning providers
|
|
37
|
+
* @param metadataScanner - Scanner for extracting method metadata
|
|
38
|
+
*/
|
|
23
39
|
constructor(queue, reflector, discoveryService, metadataScanner) {
|
|
24
40
|
this.queue = queue;
|
|
25
41
|
this.reflector = reflector;
|
|
26
42
|
this.discoveryService = discoveryService;
|
|
27
43
|
this.metadataScanner = metadataScanner;
|
|
44
|
+
/** Logger instance for the schedule registry. @internal */
|
|
28
45
|
this.logger = new common_1.Logger(ScheduleRegistry_1.name);
|
|
46
|
+
/** Map of schedule names to their handlers and options. @internal */
|
|
29
47
|
this.schedules = new Map();
|
|
30
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves a registered schedule entry by name.
|
|
51
|
+
* @param name - The schedule identifier (className.methodName)
|
|
52
|
+
* @returns The schedule handler and options, or undefined
|
|
53
|
+
*/
|
|
31
54
|
get(name) {
|
|
32
55
|
return this.schedules.get(name);
|
|
33
56
|
}
|
|
57
|
+
/** Scans controllers and providers for schedule-decorated methods. @internal */
|
|
34
58
|
discoverySchedules() {
|
|
35
59
|
[
|
|
36
60
|
...this.discoveryService.getControllers(),
|
|
@@ -55,6 +79,7 @@ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
|
|
|
55
79
|
}
|
|
56
80
|
});
|
|
57
81
|
}
|
|
82
|
+
/** Removes job schedulers that are no longer defined. @internal */
|
|
58
83
|
async cleanUnregisteredSchedules() {
|
|
59
84
|
const jobSchedulers = await this.queue.getJobSchedulers();
|
|
60
85
|
for (const jobScheduler of jobSchedulers) {
|
|
@@ -64,6 +89,7 @@ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
|
|
|
64
89
|
}
|
|
65
90
|
}
|
|
66
91
|
}
|
|
92
|
+
/** Registers all discovered schedules as BullMQ job schedulers. @internal */
|
|
67
93
|
async registerSchedules() {
|
|
68
94
|
for (const [name, { options: { type, value, timezone, ...jobOptions }, },] of this.schedules.entries()) {
|
|
69
95
|
await this.queue.upsertJobScheduler(name, {
|
|
@@ -82,6 +108,7 @@ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
|
|
|
82
108
|
this.logger.log(`Registered {${name}, ${type}, ${String(value)}}`);
|
|
83
109
|
}
|
|
84
110
|
}
|
|
111
|
+
/** Discovers all scheduled methods and registers them as BullMQ job schedulers. */
|
|
85
112
|
async onApplicationBootstrap() {
|
|
86
113
|
this.discoverySchedules();
|
|
87
114
|
await this.cleanUnregisteredSchedules();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.registry.js","sourceRoot":"","sources":["../src/schedule.registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAgD;AAChD,2CAAgE;AAChE,uCAA4E;AAC5E,mCAA+B;AAE/B,6EAGsC;AAGtC,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"schedule.registry.js","sourceRoot":"","sources":["../src/schedule.registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAgD;AAChD,2CAAgE;AAChE,uCAA4E;AAC5E,mCAA+B;AAE/B,6EAGsC;AAGtC;;;;;;;;GAQG;AACH,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAe3B;;;;;;OAMG;IACH,YAEE,KAA6B,EACZ,SAAoB,EACpB,gBAAkC,EAClC,eAAgC;QAHhC,UAAK,GAAL,KAAK,CAAO;QACZ,cAAS,GAAT,SAAS,CAAW;QACpB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,oBAAe,GAAf,eAAe,CAAiB;QA1BnD,2DAA2D;QAC1C,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;QAE5D,qEAAqE;QACpD,cAAS,GAAG,IAAI,GAAG,EAQjC,CAAC;IAeD,CAAC;IAEJ;;;;OAIG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,gFAAgF;IACxE,kBAAkB;QACxB;YACE,GAAG,IAAI,CAAC,gBAAgB,CAAC,cAAc,EAAE;YACzC,GAAG,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE;SACx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