@nest-boot/schedule 7.0.0-beta.0 → 7.0.0-beta.10

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from "./schedule.decorator";
2
2
  export * from "./schedule.module";
3
- export * from "./schedule.service";
3
+ export * from "./schedule.registry";
4
4
  export * from "./schedule-module-options.interface";
5
5
  export * from "./schedule-options.interface";
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./schedule.decorator"), exports);
18
18
  __exportStar(require("./schedule.module"), exports);
19
- __exportStar(require("./schedule.service"), exports);
19
+ __exportStar(require("./schedule.registry"), exports);
20
20
  __exportStar(require("./schedule-module-options.interface"), exports);
21
21
  __exportStar(require("./schedule-options.interface"), exports);
22
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,oDAAkC;AAClC,qDAAmC;AACnC,sEAAoD;AACpD,+DAA6C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,oDAAkC;AAClC,sDAAoC;AACpC,sEAAoD;AACpD,+DAA6C"}
@@ -1,2 +1,5 @@
1
- import { type QueueModuleOptions } from "@nest-boot/queue";
2
- export type ScheduleModuleOptions = QueueModuleOptions;
1
+ import { type RegisterQueueOptions } from "@nestjs/bullmq";
2
+ export interface ScheduleModuleOptions extends RegisterQueueOptions {
3
+ autorun?: boolean;
4
+ concurrency?: number;
5
+ }
@@ -1,4 +1,5 @@
1
- export interface ScheduleOptions {
1
+ import { JobSchedulerTemplateOptions } from "bullmq";
2
+ export interface ScheduleOptions extends JobSchedulerTemplateOptions {
2
3
  type: "cron" | "interval";
3
4
  value: number | string;
4
5
  timezone?: string;
@@ -1,4 +1,4 @@
1
1
  import { type ScheduleOptions } from "./schedule-options.interface";
2
2
  export declare const Schedule: (options: ScheduleOptions) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
3
3
  export declare const Cron: (value: string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
4
- export declare const Interval: (value: number | string) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
4
+ export declare const Interval: (value: number | string, options?: Omit<ScheduleOptions, "type" | "value">) => <T>(target: object, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => void;
@@ -13,9 +13,10 @@ const Cron = (value, options) => (0, exports.Schedule)({
13
13
  ...(options ?? {}),
14
14
  });
15
15
  exports.Cron = Cron;
16
- const Interval = (value) => (0, exports.Schedule)({
16
+ const Interval = (value, options) => (0, exports.Schedule)({
17
17
  type: "interval",
18
18
  value,
19
+ ...(options ?? {}),
19
20
  });
20
21
  exports.Interval = Interval;
21
22
  //# sourceMappingURL=schedule.decorator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6EAAqE;AAG9D,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;AAEG,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;AAEE,MAAM,QAAQ,GAAG,CAAC,KAAsB,EAAE,EAAE,CACjD,IAAA,gBAAQ,EAAC;IACP,IAAI,EAAE,UAAU;IAChB,KAAK;CACN,CAAC,CAAC;AAJQ,QAAA,QAAQ,YAIhB"}
1
+ {"version":3,"file":"schedule.decorator.js","sourceRoot":"","sources":["../src/schedule.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6EAAqE;AAG9D,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;AAEG,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;AAEE,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"}
@@ -1,3 +1,4 @@
1
+ import { type ScheduleModuleOptions } from "./schedule-module-options.interface";
1
2
  export declare const SCHEDULE_QUEUE_NAME = "schedule";
2
3
  export declare const SCHEDULE_METADATA_KEY: `${string}-${string}-${string}-${string}-${string}`;
3
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<import("@nest-boot/queue").QueueModuleOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: import("@nest-boot/queue").QueueModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<import("@nest-boot/queue").QueueModuleOptions, "create"> & Partial<{}>;
4
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ScheduleModuleOptions, "forRoot", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: ScheduleModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<ScheduleModuleOptions, "create"> & Partial<{}>;
@@ -6,5 +6,7 @@ const common_1 = require("@nestjs/common");
6
6
  const crypto_1 = require("crypto");
7
7
  exports.SCHEDULE_QUEUE_NAME = "schedule";
8
8
  exports.SCHEDULE_METADATA_KEY = (0, crypto_1.randomUUID)();
9
- _a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
9
+ _a = new common_1.ConfigurableModuleBuilder()
10
+ .setClassMethodName("forRoot")
11
+ .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
10
12
  //# 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,KAKT,IAAI,kCAAyB,EAAyB,CAAC,KAAK,EAAE,EAJhE,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAC+C"}
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,KAKT,IAAI,kCAAyB,EAAyB;KACvD,kBAAkB,CAAC,SAAS,CAAC;KAC7B,KAAK,EAAE,EANR,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAGT"}
@@ -1,7 +1,7 @@
1
1
  import { type DynamicModule } from "@nestjs/common";
2
2
  import { type ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, type OPTIONS_TYPE } from "./schedule.module-definition";
3
3
  export declare class ScheduleModule extends ConfigurableModuleClass {
4
- static register(options: typeof OPTIONS_TYPE): DynamicModule;
5
- static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
6
- private static withQueue;
4
+ private static patchDynamicModule;
5
+ static forRoot(options: typeof OPTIONS_TYPE): DynamicModule;
6
+ static forRootAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
7
7
  }
@@ -7,38 +7,46 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ScheduleModule = void 0;
10
- const queue_1 = require("@nest-boot/queue");
10
+ const bullmq_1 = require("@nest-boot/bullmq");
11
11
  const common_1 = require("@nestjs/common");
12
12
  const core_1 = require("@nestjs/core");
13
13
  const schedule_module_definition_1 = require("./schedule.module-definition");
14
- const schedule_service_1 = require("./schedule.service");
14
+ const schedule_processor_1 = require("./schedule.processor");
15
+ const schedule_registry_1 = require("./schedule.registry");
15
16
  let ScheduleModule = class ScheduleModule extends schedule_module_definition_1.ConfigurableModuleClass {
16
- static register(options) {
17
- return this.withQueue(super.register(options));
18
- }
19
- static registerAsync(options) {
20
- return this.withQueue(super.registerAsync(options));
21
- }
22
- static withQueue(dynamicModule) {
23
- const ScheduleQueueDynamicModule = queue_1.QueueModule.registerAsync({
24
- name: "schedule",
25
- imports: [dynamicModule],
26
- inject: [schedule_module_definition_1.MODULE_OPTIONS_TOKEN],
27
- useFactory: (options) => options,
28
- });
29
- dynamicModule.imports = [
30
- ...(dynamicModule.imports ?? []),
31
- ScheduleQueueDynamicModule,
32
- ];
17
+ static patchDynamicModule(dynamicModule) {
33
18
  dynamicModule.exports = [schedule_module_definition_1.MODULE_OPTIONS_TOKEN];
34
19
  return dynamicModule;
35
20
  }
21
+ static forRoot(options) {
22
+ return this.patchDynamicModule(super.forRoot(options));
23
+ }
24
+ static forRootAsync(options) {
25
+ return this.patchDynamicModule(super.forRootAsync(options));
26
+ }
36
27
  };
37
28
  exports.ScheduleModule = ScheduleModule;
38
29
  exports.ScheduleModule = ScheduleModule = __decorate([
30
+ (0, common_1.Global)(),
39
31
  (0, common_1.Module)({
40
- imports: [core_1.DiscoveryModule],
41
- providers: [common_1.Logger, schedule_service_1.ScheduleService],
32
+ imports: [
33
+ core_1.DiscoveryModule,
34
+ bullmq_1.BullModule.registerQueueAsync({
35
+ name: "schedule",
36
+ inject: [{ token: schedule_module_definition_1.MODULE_OPTIONS_TOKEN, optional: true }],
37
+ useFactory: (options) => {
38
+ return {
39
+ ...options,
40
+ defaultJobOptions: {
41
+ removeOnComplete: true,
42
+ removeOnFail: true,
43
+ ...options?.defaultJobOptions,
44
+ },
45
+ };
46
+ },
47
+ }),
48
+ ],
49
+ providers: [common_1.Logger, schedule_registry_1.ScheduleRegistry, schedule_processor_1.ScheduleProcessor],
42
50
  exports: [],
43
51
  })
44
52
  ], ScheduleModule);
@@ -1 +1 @@
1
- {"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4CAA+C;AAC/C,2CAAoE;AACpE,uCAA+C;AAE/C,6EAKsC;AACtC,yDAAqD;AAQ9C,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,oDAAuB;IACzD,MAAM,CAAC,QAAQ,CAAC,OAA4B;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,OAAkC;QACrD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;IAEO,MAAM,CAAC,SAAS,CAAC,aAA4B;QACnD,MAAM,0BAA0B,GAAG,mBAAW,CAAC,aAAa,CAAC;YAC3D,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,CAAC,aAAa,CAAC;YACxB,MAAM,EAAE,CAAC,iDAAoB,CAAC;YAC9B,UAAU,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,OAAO;SACxD,CAAC,CAAC;QAEH,aAAa,CAAC,OAAO,GAAG;YACtB,GAAG,CAAC,aAAa,CAAC,OAAO,IAAI,EAAE,CAAC;YAChC,0BAA0B;SAC3B,CAAC;QAEF,aAAa,CAAC,OAAO,GAAG,CAAC,iDAAoB,CAAC,CAAC;QAE/C,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAA;AA1BY,wCAAc;yBAAd,cAAc;IAL1B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,CAAC;QAC1B,SAAS,EAAE,CAAC,eAAM,EAAE,kCAAe,CAAC;QACpC,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,cAAc,CA0B1B"}
1
+ {"version":3,"file":"schedule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-0,0 +1 @@
1
+ import "dotenv/config";
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("dotenv/config");
4
+ const bullmq_1 = require("@nest-boot/bullmq");
5
+ const testing_1 = require("@nestjs/testing");
6
+ const _1 = require(".");
7
+ describe("BullModule", () => {
8
+ let app;
9
+ it(`ScheduleModule`, async () => {
10
+ const moduleRef = await testing_1.Test.createTestingModule({
11
+ imports: [bullmq_1.BullModule, _1.ScheduleModule],
12
+ }).compile();
13
+ app = moduleRef.createNestApplication();
14
+ await app.init();
15
+ await app.close();
16
+ });
17
+ it(`ScheduleModule.forRoot`, async () => {
18
+ const moduleRef = await testing_1.Test.createTestingModule({
19
+ imports: [bullmq_1.BullModule, _1.ScheduleModule.forRoot({})],
20
+ }).compile();
21
+ app = moduleRef.createNestApplication();
22
+ await app.init();
23
+ await app.close();
24
+ });
25
+ it(`ScheduleModule.forRootAsync`, async () => {
26
+ const moduleRef = await testing_1.Test.createTestingModule({
27
+ imports: [
28
+ bullmq_1.BullModule,
29
+ _1.ScheduleModule.forRootAsync({
30
+ useFactory: () => ({}),
31
+ }),
32
+ ],
33
+ }).compile();
34
+ app = moduleRef.createNestApplication();
35
+ await app.init();
36
+ await app.close();
37
+ });
38
+ });
39
+ //# sourceMappingURL=schedule.module.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.module.spec.js","sourceRoot":"","sources":["../src/schedule.module.spec.ts"],"names":[],"mappings":";;AAAA,yBAAuB;AAEvB,8CAA+C;AAE/C,6CAAuC;AAEvC,wBAAmC;AAEnC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,GAAqB,CAAC;IAE1B,EAAE,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;QAC9B,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE,CAAC,mBAAU,EAAE,iBAAc,CAAC;SACtC,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE,CAAC,mBAAU,EAAE,iBAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;SAClD,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,SAAS,GAAG,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC/C,OAAO,EAAE;gBACP,mBAAU;gBACV,iBAAc,CAAC,YAAY,CAAC;oBAC1B,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;iBACvB,CAAC;aACH;SACF,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { WorkerHost } from "@nestjs/bullmq";
2
+ import { OnApplicationBootstrap } from "@nestjs/common";
3
+ import { Job } from "bullmq";
4
+ import { ScheduleRegistry } from "./schedule.registry";
5
+ import { ScheduleModuleOptions } from "./schedule-module-options.interface";
6
+ export declare class ScheduleProcessor extends WorkerHost implements OnApplicationBootstrap {
7
+ private readonly scheduleRegistry;
8
+ private readonly options?;
9
+ constructor(scheduleRegistry: ScheduleRegistry, options?: ScheduleModuleOptions | undefined);
10
+ process(job: Job): Promise<void>;
11
+ onApplicationBootstrap(): Promise<void>;
12
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ScheduleProcessor = void 0;
16
+ const bullmq_1 = require("@nestjs/bullmq");
17
+ const common_1 = require("@nestjs/common");
18
+ const schedule_module_definition_1 = require("./schedule.module-definition");
19
+ const schedule_registry_1 = require("./schedule.registry");
20
+ let ScheduleProcessor = class ScheduleProcessor extends bullmq_1.WorkerHost {
21
+ constructor(scheduleRegistry, options) {
22
+ super();
23
+ this.scheduleRegistry = scheduleRegistry;
24
+ this.options = options;
25
+ }
26
+ async process(job) {
27
+ await this.scheduleRegistry.get(job.name)?.handler();
28
+ }
29
+ async onApplicationBootstrap() {
30
+ if (this.options?.concurrency) {
31
+ this.worker.concurrency = this.options.concurrency;
32
+ }
33
+ if (this.options?.autorun !== false && this.worker.isPaused()) {
34
+ await this.worker.run();
35
+ }
36
+ }
37
+ };
38
+ exports.ScheduleProcessor = ScheduleProcessor;
39
+ exports.ScheduleProcessor = ScheduleProcessor = __decorate([
40
+ (0, bullmq_1.Processor)("schedule", { autorun: false }),
41
+ __param(1, (0, common_1.Optional)()),
42
+ __param(1, (0, common_1.Inject)(schedule_module_definition_1.MODULE_OPTIONS_TOKEN)),
43
+ __metadata("design:paramtypes", [schedule_registry_1.ScheduleRegistry, Object])
44
+ ], ScheduleProcessor);
45
+ //# sourceMappingURL=schedule.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.processor.js","sourceRoot":"","sources":["../src/schedule.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAuD;AACvD,2CAA0E;AAG1E,6EAAoE;AACpE,2DAAuD;AAIhD,IAAM,iBAAiB,GAAvB,MAAM,iBACX,SAAQ,mBAAU;IAGlB,YACmB,gBAAkC,EAGlC,OAA+B;QAEhD,KAAK,EAAE,CAAC;QALS,qBAAgB,GAAhB,gBAAgB,CAAkB;QAGlC,YAAO,GAAP,OAAO,CAAwB;IAGlD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAQ;QACpB,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,sBAAsB;QAC1B,IAAI,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;QACrD,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YAC9D,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAC1B,CAAC;IACH,CAAC;CACF,CAAA;AA1BY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,kBAAS,EAAC,UAAU,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAOrC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,iDAAoB,CAAC,CAAA;qCAFM,oCAAgB;GAL1C,iBAAiB,CA0B7B"}
@@ -1,7 +1,8 @@
1
- import { Job, Queue } from "@nest-boot/queue";
2
1
  import { type OnApplicationBootstrap } from "@nestjs/common";
3
2
  import { DiscoveryService, MetadataScanner, Reflector } from "@nestjs/core";
4
- export declare class ScheduleService implements OnApplicationBootstrap {
3
+ import { Queue } from "bullmq";
4
+ import { type ScheduleOptions } from "./schedule-options.interface";
5
+ export declare class ScheduleRegistry implements OnApplicationBootstrap {
5
6
  private readonly queue;
6
7
  private readonly reflector;
7
8
  private readonly discoveryService;
@@ -9,7 +10,10 @@ export declare class ScheduleService implements OnApplicationBootstrap {
9
10
  private readonly logger;
10
11
  private readonly schedules;
11
12
  constructor(queue: Queue, reflector: Reflector, discoveryService: DiscoveryService, metadataScanner: MetadataScanner);
12
- consume(job: Job): Promise<void>;
13
+ get(name: string): {
14
+ handler: () => Promise<void>;
15
+ options: ScheduleOptions;
16
+ } | undefined;
13
17
  private discoverySchedules;
14
18
  private cleanUnregisteredSchedules;
15
19
  private registerSchedules;
@@ -11,31 +11,25 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- var ScheduleService_1;
14
+ var ScheduleRegistry_1;
18
15
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.ScheduleService = void 0;
20
- const queue_1 = require("@nest-boot/queue");
16
+ exports.ScheduleRegistry = void 0;
17
+ const bullmq_1 = require("@nestjs/bullmq");
21
18
  const common_1 = require("@nestjs/common");
22
19
  const core_1 = require("@nestjs/core");
23
- const ms_1 = __importDefault(require("ms"));
20
+ const bullmq_2 = require("bullmq");
24
21
  const schedule_module_definition_1 = require("./schedule.module-definition");
25
- let ScheduleService = ScheduleService_1 = class ScheduleService {
22
+ let ScheduleRegistry = ScheduleRegistry_1 = class ScheduleRegistry {
26
23
  constructor(queue, reflector, discoveryService, metadataScanner) {
27
24
  this.queue = queue;
28
25
  this.reflector = reflector;
29
26
  this.discoveryService = discoveryService;
30
27
  this.metadataScanner = metadataScanner;
31
- this.logger = new common_1.Logger(ScheduleService_1.name);
28
+ this.logger = new common_1.Logger(ScheduleRegistry_1.name);
32
29
  this.schedules = new Map();
33
30
  }
34
- async consume(job) {
35
- const schedule = this.schedules.get(job.name);
36
- if (typeof schedule !== "undefined") {
37
- await schedule.handler();
38
- }
31
+ get(name) {
32
+ return this.schedules.get(name);
39
33
  }
40
34
  discoverySchedules() {
41
35
  [
@@ -62,29 +56,31 @@ let ScheduleService = ScheduleService_1 = class ScheduleService {
62
56
  });
63
57
  }
64
58
  async cleanUnregisteredSchedules() {
65
- const repeatableJobs = await this.queue.getRepeatableJobs();
66
- await Promise.all(repeatableJobs
67
- .filter((repeatableJob) => this.schedules
68
- .get(repeatableJob.name)
69
- ?.options?.value.toString() !== repeatableJob.pattern)
70
- .map(async (repeatableJob) => {
71
- await this.queue.removeRepeatableByKey(repeatableJob.key);
72
- this.logger.log(`Removed {${repeatableJob.name}, ${String(repeatableJob.pattern ?? "null")}}`);
73
- }));
59
+ const jobSchedulers = await this.queue.getJobSchedulers();
60
+ for (const jobScheduler of jobSchedulers) {
61
+ if (!this.schedules.get(jobScheduler.name)) {
62
+ await this.queue.removeJobScheduler(jobScheduler.name);
63
+ this.logger.log(`Removed {${jobScheduler.name}, ${jobScheduler.pattern ? "cron" : "interval"}, ${String(jobScheduler.pattern ?? jobScheduler.every)}}`);
64
+ }
65
+ }
74
66
  }
75
67
  async registerSchedules() {
76
- await Promise.all([...this.schedules.entries()].map(async ([name, { options: { type, value, timezone }, },]) => {
77
- await this.queue.add(name, {}, {
78
- repeat: type === "cron"
79
- ? { pattern: value.toString(), tz: timezone }
68
+ for (const [name, { options: { type, value, timezone, ...jobOptions }, },] of this.schedules.entries()) {
69
+ await this.queue.upsertJobScheduler(name, {
70
+ tz: timezone ?? "UTC",
71
+ ...(type === "cron"
72
+ ? {
73
+ pattern: value.toString(),
74
+ }
80
75
  : {
81
- every: typeof value === "string" ? (0, ms_1.default)(value) : value,
82
- },
83
- removeOnFail: true,
84
- removeOnComplete: true,
76
+ every: Number(value),
77
+ }),
78
+ }, {
79
+ name,
80
+ opts: jobOptions,
85
81
  });
86
82
  this.logger.log(`Registered {${name}, ${type}, ${String(value)}}`);
87
- }));
83
+ }
88
84
  }
89
85
  async onApplicationBootstrap() {
90
86
  this.discoverySchedules();
@@ -92,13 +88,12 @@ let ScheduleService = ScheduleService_1 = class ScheduleService {
92
88
  await this.registerSchedules();
93
89
  }
94
90
  };
95
- exports.ScheduleService = ScheduleService;
96
- exports.ScheduleService = ScheduleService = ScheduleService_1 = __decorate([
97
- (0, queue_1.Consumer)(schedule_module_definition_1.SCHEDULE_QUEUE_NAME),
98
- __param(0, (0, queue_1.InjectQueue)(schedule_module_definition_1.SCHEDULE_QUEUE_NAME)),
99
- __metadata("design:paramtypes", [queue_1.Queue,
91
+ exports.ScheduleRegistry = ScheduleRegistry;
92
+ exports.ScheduleRegistry = ScheduleRegistry = ScheduleRegistry_1 = __decorate([
93
+ __param(0, (0, bullmq_1.InjectQueue)(schedule_module_definition_1.SCHEDULE_QUEUE_NAME)),
94
+ __metadata("design:paramtypes", [bullmq_2.Queue,
100
95
  core_1.Reflector,
101
96
  core_1.DiscoveryService,
102
97
  core_1.MetadataScanner])
103
- ], ScheduleService);
104
- //# sourceMappingURL=schedule.service.js.map
98
+ ], ScheduleRegistry);
99
+ //# sourceMappingURL=schedule.registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.registry.js","sourceR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