@nest-boot/schedule 7.0.0-beta.3 → 7.0.0-beta.4
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 +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/schedule-module-options.interface.d.ts +4 -2
- package/dist/schedule-options.interface.d.ts +2 -1
- package/dist/schedule.decorator.d.ts +1 -1
- package/dist/schedule.decorator.js +2 -1
- package/dist/schedule.decorator.js.map +1 -1
- package/dist/schedule.module-definition.d.ts +2 -1
- package/dist/schedule.module.js +5 -4
- package/dist/schedule.module.js.map +1 -1
- package/dist/schedule.processor.d.ts +12 -0
- package/dist/schedule.processor.js +53 -0
- package/dist/schedule.processor.js.map +1 -0
- package/dist/{schedule.service.d.ts → schedule.registry.d.ts} +7 -3
- package/dist/{schedule.service.js → schedule.registry.js} +34 -39
- package/dist/schedule.registry.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/schedule.service.js.map +0 -1
package/dist/index.d.ts
CHANGED
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.
|
|
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,
|
|
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,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export
|
|
1
|
+
import { type RegisterQueueOptions } from "@nestjs/bullmq";
|
|
2
|
+
export interface ScheduleModuleOptions extends RegisterQueueOptions {
|
|
3
|
+
concurrency?: number;
|
|
4
|
+
}
|
|
@@ -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,
|
|
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<
|
|
4
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<ScheduleModuleOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: ScheduleModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<ScheduleModuleOptions, "create"> & Partial<{}>;
|
package/dist/schedule.module.js
CHANGED
|
@@ -7,11 +7,12 @@ 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
|
|
10
|
+
const bullmq_1 = require("@nestjs/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
|
|
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
17
|
static register(options) {
|
|
17
18
|
return this.withQueue(super.register(options));
|
|
@@ -20,7 +21,7 @@ let ScheduleModule = class ScheduleModule extends schedule_module_definition_1.C
|
|
|
20
21
|
return this.withQueue(super.registerAsync(options));
|
|
21
22
|
}
|
|
22
23
|
static withQueue(dynamicModule) {
|
|
23
|
-
const ScheduleQueueDynamicModule =
|
|
24
|
+
const ScheduleQueueDynamicModule = bullmq_1.BullModule.registerQueueAsync({
|
|
24
25
|
name: "schedule",
|
|
25
26
|
imports: [dynamicModule],
|
|
26
27
|
inject: [schedule_module_definition_1.MODULE_OPTIONS_TOKEN],
|
|
@@ -38,7 +39,7 @@ exports.ScheduleModule = ScheduleModule;
|
|
|
38
39
|
exports.ScheduleModule = ScheduleModule = __decorate([
|
|
39
40
|
(0, common_1.Module)({
|
|
40
41
|
imports: [core_1.DiscoveryModule],
|
|
41
|
-
providers: [common_1.Logger,
|
|
42
|
+
providers: [common_1.Logger, schedule_registry_1.ScheduleRegistry, schedule_processor_1.ScheduleProcessor],
|
|
42
43
|
exports: [],
|
|
43
44
|
})
|
|
44
45
|
], ScheduleModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"schedule.module.js","sourceRoot":"","sources":["../src/schedule.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,2CAAoE;AACpE,uCAA+C;AAE/C,6EAKsC;AACtC,6DAAyD;AACzD,2DAAuD;AAQhD,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,mBAAU,CAAC,kBAAkB,CAAC;YAC/D,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,oCAAgB,EAAE,sCAAiB,CAAC;QACxD,OAAO,EAAE,EAAE;KACZ,CAAC;GACW,cAAc,CA0B1B"}
|
|
@@ -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 options;
|
|
8
|
+
private readonly scheduleRegistry;
|
|
9
|
+
constructor(options: ScheduleModuleOptions, scheduleRegistry: ScheduleRegistry);
|
|
10
|
+
process(job: Job): Promise<void>;
|
|
11
|
+
onApplicationBootstrap(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 request_context_1 = require("@nest-boot/request-context");
|
|
17
|
+
const bullmq_1 = require("@nestjs/bullmq");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const bullmq_2 = require("bullmq");
|
|
20
|
+
const schedule_module_definition_1 = require("./schedule.module-definition");
|
|
21
|
+
const schedule_registry_1 = require("./schedule.registry");
|
|
22
|
+
let ScheduleProcessor = class ScheduleProcessor extends bullmq_1.WorkerHost {
|
|
23
|
+
constructor(options, scheduleRegistry) {
|
|
24
|
+
super();
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.scheduleRegistry = scheduleRegistry;
|
|
27
|
+
}
|
|
28
|
+
async process(job) {
|
|
29
|
+
await this.scheduleRegistry.get(job.name)?.handler();
|
|
30
|
+
}
|
|
31
|
+
onApplicationBootstrap() {
|
|
32
|
+
if (this.options.concurrency) {
|
|
33
|
+
this.worker.concurrency = this.options.concurrency;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.ScheduleProcessor = ScheduleProcessor;
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, request_context_1.CreateRequestContext)((_, job) => {
|
|
40
|
+
const ctx = new request_context_1.RequestContext({ type: "job", id: job.id });
|
|
41
|
+
ctx.set(bullmq_1.JOB_REF, job);
|
|
42
|
+
return ctx;
|
|
43
|
+
}),
|
|
44
|
+
__metadata("design:type", Function),
|
|
45
|
+
__metadata("design:paramtypes", [bullmq_2.Job]),
|
|
46
|
+
__metadata("design:returntype", Promise)
|
|
47
|
+
], ScheduleProcessor.prototype, "process", null);
|
|
48
|
+
exports.ScheduleProcessor = ScheduleProcessor = __decorate([
|
|
49
|
+
(0, bullmq_1.Processor)("schedule"),
|
|
50
|
+
__param(0, (0, common_1.Inject)(schedule_module_definition_1.MODULE_OPTIONS_TOKEN)),
|
|
51
|
+
__metadata("design:paramtypes", [Object, schedule_registry_1.ScheduleRegistry])
|
|
52
|
+
], ScheduleProcessor);
|
|
53
|
+
//# sourceMappingURL=schedule.processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedule.processor.js","sourceRoot":"","sources":["../src/schedule.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAGoC;AACpC,2CAAgE;AAChE,2CAAgE;AAChE,mCAA6B;AAE7B,6EAAoE;AACpE,2DAAuD;AAIhD,IAAM,iBAAiB,GAAvB,MAAM,iBACX,SAAQ,mBAAU;IAGlB,YAEmB,OAA8B,EAC9B,gBAAkC;QAEnD,KAAK,EAAE,CAAC;QAHS,YAAO,GAAP,OAAO,CAAuB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;IAGrD,CAAC;IAOK,AAAN,KAAK,CAAC,OAAO,CAAC,GAAQ;QACpB,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACvD,CAAC;IAED,sBAAsB;QACpB,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;QACrD,CAAC;IACH,CAAC;CACF,CAAA;AA1BY,8CAAiB;AAiBtB;IALL,IAAA,sCAAoB,EAAC,CAAC,CAAC,EAAE,GAAQ,EAAE,EAAE;QACpC,MAAM,GAAG,GAAG,IAAI,gCAAc,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5D,GAAG,CAAC,GAAG,CAAC,gBAAO,EAAE,GAAG,CAAC,CAAC;QACtB,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;;qCACiB,YAAG;;gDAErB;4BAnBU,iBAAiB;IAD7B,IAAA,kBAAS,EAAC,UAAU,CAAC;IAMjB,WAAA,IAAA,eAAM,EAAC,iDAAoB,CAAC,CAAA;6CAEM,oCAAgB;GAP1C,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
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
20
|
-
const
|
|
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
|
|
20
|
+
const bullmq_2 = require("bullmq");
|
|
24
21
|
const schedule_module_definition_1 = require("./schedule.module-definition");
|
|
25
|
-
let
|
|
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(
|
|
28
|
+
this.logger = new common_1.Logger(ScheduleRegistry_1.name);
|
|
32
29
|
this.schedules = new Map();
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.logger.log(`Removed {${repeatableJob.name}, ${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
|
-
|
|
77
|
-
await this.queue.
|
|
78
|
-
|
|
79
|
-
|
|
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:
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
|
|
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.
|
|
96
|
-
exports.
|
|
97
|
-
(0,
|
|
98
|
-
|
|
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
|
-
],
|
|
104
|
-
//# sourceMappingURL=schedule.
|
|
98
|
+
], ScheduleRegistry);
|
|
99
|
+
//# sourceMappingURL=schedule.registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedule.registry.js","sourceRoot":"","sources":["../src/schedule.registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA6C;AAC7C,2CAAqE;AACrE,uCAA4E;AAC5E,mCAA+B;AAE/B,6EAGsC;AAGtC,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAW3B,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;QAflC,WAAM,GAAG,IAAI,eAAM,CAAC,kBAAgB,CAAC,IAAI,CAAC,CAAC;QAE3C,cAAS,GAAG,IAAI,GAAG,EAMjC,CAAC;IAQD,CAAC;IAEJ,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IAEO,kBAAkB;QACxB;YACE,GAAG,IAAI,CAAC,g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