@tsed/pulse 7.77.0
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/lib/cjs/PulseModule.js +141 -0
- package/lib/cjs/PulseModule.js.map +1 -0
- package/lib/cjs/constants/constants.js +5 -0
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/define.js +16 -0
- package/lib/cjs/decorators/define.js.map +1 -0
- package/lib/cjs/decorators/every.js +17 -0
- package/lib/cjs/decorators/every.js.map +1 -0
- package/lib/cjs/decorators/pulse.js +13 -0
- package/lib/cjs/decorators/pulse.js.map +1 -0
- package/lib/cjs/index.js +15 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/PulseStore.js +3 -0
- package/lib/cjs/interfaces/PulseStore.js.map +1 -0
- package/lib/cjs/interfaces/interfaces.js +3 -0
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/PulseFactory.js +16 -0
- package/lib/cjs/services/PulseFactory.js.map +1 -0
- package/lib/esm/PulseModule.js +138 -0
- package/lib/esm/PulseModule.js.map +1 -0
- package/lib/esm/constants/constants.js +2 -0
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/define.js +12 -0
- package/lib/esm/decorators/define.js.map +1 -0
- package/lib/esm/decorators/every.js +13 -0
- package/lib/esm/decorators/every.js.map +1 -0
- package/lib/esm/decorators/pulse.js +9 -0
- package/lib/esm/decorators/pulse.js.map +1 -0
- package/lib/esm/index.js +12 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/PulseStore.js +2 -0
- package/lib/esm/interfaces/PulseStore.js.map +1 -0
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/PulseFactory.js +13 -0
- package/lib/esm/services/PulseFactory.js.map +1 -0
- package/lib/types/PulseModule.d.ts +23 -0
- package/lib/types/constants/constants.d.ts +1 -0
- package/lib/types/decorators/define.d.ts +2 -0
- package/lib/types/decorators/every.d.ts +2 -0
- package/lib/types/decorators/pulse.d.ts +5 -0
- package/lib/types/index.d.ts +11 -0
- package/lib/types/interfaces/PulseStore.d.ts +16 -0
- package/lib/types/interfaces/interfaces.d.ts +15 -0
- package/lib/types/services/PulseFactory.d.ts +3 -0
- package/package.json +44 -0
- package/readme.md +215 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PulseModule = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@tsed/common");
|
|
6
|
+
const di_1 = require("@tsed/di");
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const constants_js_1 = require("./constants/constants.js");
|
|
9
|
+
const PulseFactory_1 = require("./services/PulseFactory");
|
|
10
|
+
let PulseModule = class PulseModule {
|
|
11
|
+
logger;
|
|
12
|
+
injector;
|
|
13
|
+
pulse;
|
|
14
|
+
enabled;
|
|
15
|
+
drainJobsBeforeClose;
|
|
16
|
+
disableJobProcessing;
|
|
17
|
+
async $afterListen() {
|
|
18
|
+
if (this.enabled) {
|
|
19
|
+
const providers = this.getProviders();
|
|
20
|
+
if (!this.disableJobProcessing) {
|
|
21
|
+
this.logger.info({
|
|
22
|
+
event: "PULSE_ADD_DEFINITIONS",
|
|
23
|
+
message: "Pulse add definitions"
|
|
24
|
+
});
|
|
25
|
+
providers.forEach((provider) => this.addPulseDefinitionsForProvider(provider));
|
|
26
|
+
await this.injector.emit("$beforePulseStart");
|
|
27
|
+
}
|
|
28
|
+
await this.pulse.start();
|
|
29
|
+
if (!this.disableJobProcessing) {
|
|
30
|
+
this.logger.info({
|
|
31
|
+
event: "PULSE_ADD_JOBS",
|
|
32
|
+
message: "Pulse add scheduled jobs"
|
|
33
|
+
});
|
|
34
|
+
await Promise.all(providers.map((provider) => this.scheduleJobsForProvider(provider)));
|
|
35
|
+
await this.injector.emit("$afterPulseStart");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async $onDestroy() {
|
|
40
|
+
if (this.enabled) {
|
|
41
|
+
if (this.drainJobsBeforeClose && "drain" in this.pulse) {
|
|
42
|
+
this.logger.info({
|
|
43
|
+
event: "PULSE_DRAIN",
|
|
44
|
+
message: "Pulse is draining all jobs before close"
|
|
45
|
+
});
|
|
46
|
+
await this.pulse.drain();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.logger.info({
|
|
50
|
+
event: "PULSE_STOP",
|
|
51
|
+
message: "Pulse is stopping"
|
|
52
|
+
});
|
|
53
|
+
await this.pulse.stop();
|
|
54
|
+
}
|
|
55
|
+
await this.pulse.close({ force: true });
|
|
56
|
+
this.logger.info({ event: "PULSE_STOP", message: "Pulse stopped" });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
define(name, processor, options) {
|
|
60
|
+
return this.pulse.define(name, (job, ...rest) => {
|
|
61
|
+
const $ctx = new common_1.DIContext({
|
|
62
|
+
injector: this.injector,
|
|
63
|
+
id: (0, uuid_1.v4)(),
|
|
64
|
+
logger: this.injector.logger
|
|
65
|
+
});
|
|
66
|
+
$ctx.set("job", job);
|
|
67
|
+
return (0, common_1.runInContext)($ctx, () => processor(job, ...rest));
|
|
68
|
+
}, options);
|
|
69
|
+
}
|
|
70
|
+
every(interval, name, data, options) {
|
|
71
|
+
return this.pulse.every(interval, name, data, options);
|
|
72
|
+
}
|
|
73
|
+
schedule(when, name, data) {
|
|
74
|
+
return this.pulse.schedule(when, name, data);
|
|
75
|
+
}
|
|
76
|
+
now(name, data) {
|
|
77
|
+
return this.pulse.now(name, data);
|
|
78
|
+
}
|
|
79
|
+
create(name, data) {
|
|
80
|
+
return this.pulse.create(name, data);
|
|
81
|
+
}
|
|
82
|
+
getProviders() {
|
|
83
|
+
return this.injector.getProviders(constants_js_1.PROVIDER_TYPE_PULSE);
|
|
84
|
+
}
|
|
85
|
+
addPulseDefinitionsForProvider(provider) {
|
|
86
|
+
const store = provider.store.get("pulse", {});
|
|
87
|
+
if (!store.define) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
Object.entries(store.define).forEach(([propertyKey, { name, ...options }]) => {
|
|
91
|
+
const instance = this.injector.get(provider.token);
|
|
92
|
+
const jobProcessor = instance[propertyKey].bind(instance);
|
|
93
|
+
const jobName = this.getNameForJob(propertyKey, store.namespace, name);
|
|
94
|
+
this.define(jobName, jobProcessor, options);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async scheduleJobsForProvider(provider) {
|
|
98
|
+
const store = provider.store.get("pulse", {});
|
|
99
|
+
if (!store.every) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const promises = Object.entries(store.every).map(([propertyKey, { interval, name, ...options }]) => {
|
|
103
|
+
const jobName = this.getNameForJob(propertyKey, store.namespace, name);
|
|
104
|
+
return this.every(interval, jobName, {}, options);
|
|
105
|
+
});
|
|
106
|
+
await Promise.all(promises);
|
|
107
|
+
}
|
|
108
|
+
getNameForJob(propertyKey, namespace, customName) {
|
|
109
|
+
const name = customName || propertyKey;
|
|
110
|
+
return namespace ? `${namespace}.${name}` : name;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
tslib_1.__decorate([
|
|
114
|
+
(0, di_1.Inject)(),
|
|
115
|
+
tslib_1.__metadata("design:type", common_1.Logger)
|
|
116
|
+
], PulseModule.prototype, "logger", void 0);
|
|
117
|
+
tslib_1.__decorate([
|
|
118
|
+
(0, di_1.Inject)(),
|
|
119
|
+
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
120
|
+
], PulseModule.prototype, "injector", void 0);
|
|
121
|
+
tslib_1.__decorate([
|
|
122
|
+
(0, di_1.Inject)(),
|
|
123
|
+
tslib_1.__metadata("design:type", PulseFactory_1.PulseService)
|
|
124
|
+
], PulseModule.prototype, "pulse", void 0);
|
|
125
|
+
tslib_1.__decorate([
|
|
126
|
+
(0, di_1.Constant)("pulse.enabled", false),
|
|
127
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
128
|
+
], PulseModule.prototype, "enabled", void 0);
|
|
129
|
+
tslib_1.__decorate([
|
|
130
|
+
(0, di_1.Constant)("pulse.drainJobsBeforeClose", false),
|
|
131
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
132
|
+
], PulseModule.prototype, "drainJobsBeforeClose", void 0);
|
|
133
|
+
tslib_1.__decorate([
|
|
134
|
+
(0, di_1.Constant)("pulse.disableJobProcessing", false),
|
|
135
|
+
tslib_1.__metadata("design:type", Boolean)
|
|
136
|
+
], PulseModule.prototype, "disableJobProcessing", void 0);
|
|
137
|
+
PulseModule = tslib_1.__decorate([
|
|
138
|
+
(0, di_1.Module)()
|
|
139
|
+
], PulseModule);
|
|
140
|
+
exports.PulseModule = PulseModule;
|
|
141
|
+
//# sourceMappingURL=PulseModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseModule.js","sourceRoot":"","sources":["../../src/PulseModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAqF;AACrF,iCAA6E;AAE7E,+BAAgC;AAChC,2DAA6D;AAE7D,0DAAqD;AAG9C,IAAM,WAAW,GAAjB,MAAM,WAAW;IAEZ,MAAM,CAAS;IAGf,QAAQ,CAAkB;IAG1B,KAAK,CAAe;IAGtB,OAAO,CAAU;IAGjB,oBAAoB,CAAU;IAG9B,oBAAoB,CAAU;IAEtC,KAAK,CAAC,YAAY;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;YAEtC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;gBAC9B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;oBACf,KAAK,EAAE,uBAAuB;oBAC9B,OAAO,EAAE,uBAAuB;iBACjC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,EAAE,EAAE;YAC/F,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAEvE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAES,aAAa,CAAC,WAAmB,EAAE,SAAkB,EAAE,UAAmB;QAClF,MAAM,IAAI,GAAG,UAAU,IAAI,WAAW,CAAC;QACvC,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,CAAC;CACF,CAAA;AA3IC;IAAC,IAAA,WAAM,GAAE;sCACS,eAAM;2CAAC;AAEzB;IAAC,IAAA,WAAM,GAAE;sCACW,oBAAe;6CAAC;AAEpC;IAAC,IAAA,WAAM,GAAE;sCACQ,2BAAY;0CAAC;AAE9B;IAAC,IAAA,aAAQ,EAAC,eAAe,EAAE,KAAK,CAAC;;4CACR;AAEzB;IAAC,IAAA,aAAQ,EAAC,4BAA4B,EAAE,KAAK,CAAC;;yDACR;AAEtC;IAAC,IAAA,aAAQ,EAAC,4BAA4B,EAAE,KAAK,CAAC;;yDACR;AAjB3B,WAAW;IADvB,IAAA,WAAM,GAAE;GACI,WAAW,CA4IvB;AA5IY,kCAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Define = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
function Define(options = {}) {
|
|
6
|
+
return (target, propertyKey) => {
|
|
7
|
+
const store = {
|
|
8
|
+
define: {
|
|
9
|
+
[propertyKey]: options
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
core_1.Store.from(target).merge("pulse", store);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.Define = Define;
|
|
16
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/decorators/define.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAGjC,SAAgB,MAAM,CAAC,UAAyB,EAAE;IAChD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAe;YACxB,MAAM,EAAE;gBACN,CAAC,WAAW,CAAC,EAAE,OAAO;aACvB;SACF,CAAC;QAEF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC;AAVD,wBAUC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Every = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const define_js_1 = require("./define.js");
|
|
6
|
+
function Every(interval, options = {}) {
|
|
7
|
+
return (0, core_1.useDecorators)((0, define_js_1.Define)(options), (target, propertyKey) => {
|
|
8
|
+
const store = {
|
|
9
|
+
every: {
|
|
10
|
+
[propertyKey]: { ...options, interval }
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
core_1.Store.from(target).merge("pulse", store);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
exports.Every = Every;
|
|
17
|
+
//# sourceMappingURL=every.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"every.js","sourceRoot":"","sources":["../../../src/decorators/every.ts"],"names":[],"mappings":";;;AAAA,qCAAgD;AAChD,2CAAmC;AAGnC,SAAgB,KAAK,CAAC,QAAgB,EAAE,UAAwB,EAAE;IAChE,OAAO,IAAA,oBAAa,EAAC,IAAA,kBAAM,EAAC,OAAO,CAAC,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACzE,MAAM,KAAK,GAAe;YACxB,KAAK,EAAE;gBACL,CAAC,WAAW,CAAC,EAAE,EAAC,GAAG,OAAO,EAAE,QAAQ,EAAC;aACtC;SACF,CAAC;QACF,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC;AATD,sBASC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pulse = void 0;
|
|
4
|
+
const core_1 = require("@tsed/core");
|
|
5
|
+
const di_1 = require("@tsed/di");
|
|
6
|
+
const constants_js_1 = require("../constants/constants.js");
|
|
7
|
+
function Pulse(options) {
|
|
8
|
+
return (0, core_1.useDecorators)(options?.namespace && (0, core_1.StoreMerge)("pulse", options), (0, di_1.Injectable)({
|
|
9
|
+
type: constants_js_1.PROVIDER_TYPE_PULSE
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
exports.Pulse = Pulse;
|
|
13
|
+
//# sourceMappingURL=pulse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pulse.js","sourceRoot":"","sources":["../../../src/decorators/pulse.ts"],"names":[],"mappings":";;;AAAA,qCAAqD;AACrD,iCAAoC;AACpC,4DAA8D;AAM9D,SAAgB,KAAK,CAAC,OAAsB;IAC1C,OAAO,IAAA,oBAAa,EAClB,OAAO,EAAE,SAAS,IAAI,IAAA,iBAAU,EAAC,OAAO,EAAE,OAAO,CAAC,EAClD,IAAA,eAAU,EAAC;QACT,IAAI,EAAE,kCAAmB;KAC1B,CAAC,CACH,CAAC;AACJ,CAAC;AAPD,sBAOC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/**
|
|
5
|
+
* @file Automatically generated by @tsed/barrels.
|
|
6
|
+
*/
|
|
7
|
+
tslib_1.__exportStar(require("./constants/constants.js"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./decorators/define.js"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/every.js"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./decorators/pulse.js"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./interfaces/interfaces.js"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./interfaces/PulseStore.js"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./PulseModule.js"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./services/PulseFactory.js"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,mEAAyC;AACzC,iEAAuC;AACvC,gEAAsC;AACtC,gEAAsC;AACtC,qEAA2C;AAC3C,qEAA2C;AAC3C,2DAAiC;AACjC,qEAA2C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseStore.js","sourceRoot":"","sources":["../../../src/interfaces/PulseStore.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PulseService = void 0;
|
|
4
|
+
const di_1 = require("@tsed/di");
|
|
5
|
+
const pulse_1 = require("@pulsecron/pulse");
|
|
6
|
+
// create Alias to avoid confusing import between Pulse from "@pulsecron/pulse" and Pulse decorator
|
|
7
|
+
exports.PulseService = pulse_1.Pulse;
|
|
8
|
+
(0, di_1.registerProvider)({
|
|
9
|
+
provide: pulse_1.Pulse,
|
|
10
|
+
deps: [di_1.Configuration],
|
|
11
|
+
useFactory(settings) {
|
|
12
|
+
const opts = settings.get("pulse", { enabled: false });
|
|
13
|
+
return opts.enabled ? new pulse_1.Pulse(opts) : {};
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=PulseFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseFactory.js","sourceRoot":"","sources":["../../../src/services/PulseFactory.ts"],"names":[],"mappings":";;;AAAA,iCAAyD;AACzD,4CAAoD;AAEpD,mGAAmG;AACtF,QAAA,YAAY,GAAG,aAAK,CAAC;AAGlC,IAAA,qBAAgB,EAAC;IACf,OAAO,EAAE,aAAK;IACd,IAAI,EAAE,CAAC,kBAAa,CAAC;IACrB,UAAU,CAAC,QAAuB;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAmC,OAAO,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;QACvF,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,aAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { DIContext, Logger, runInContext } from "@tsed/common";
|
|
3
|
+
import { Constant, Inject, InjectorService, Module } from "@tsed/di";
|
|
4
|
+
import { v4 as uuid } from "uuid";
|
|
5
|
+
import { PROVIDER_TYPE_PULSE } from "./constants/constants.js";
|
|
6
|
+
import { PulseService } from "./services/PulseFactory.js";
|
|
7
|
+
let PulseModule = class PulseModule {
|
|
8
|
+
logger;
|
|
9
|
+
injector;
|
|
10
|
+
pulse;
|
|
11
|
+
enabled;
|
|
12
|
+
drainJobsBeforeClose;
|
|
13
|
+
disableJobProcessing;
|
|
14
|
+
async $afterListen() {
|
|
15
|
+
if (this.enabled) {
|
|
16
|
+
const providers = this.getProviders();
|
|
17
|
+
if (!this.disableJobProcessing) {
|
|
18
|
+
this.logger.info({
|
|
19
|
+
event: "PULSE_ADD_DEFINITIONS",
|
|
20
|
+
message: "Pulse add definitions"
|
|
21
|
+
});
|
|
22
|
+
providers.forEach((provider) => this.addPulseDefinitionsForProvider(provider));
|
|
23
|
+
await this.injector.emit("$beforePulseStart");
|
|
24
|
+
}
|
|
25
|
+
await this.pulse.start();
|
|
26
|
+
if (!this.disableJobProcessing) {
|
|
27
|
+
this.logger.info({
|
|
28
|
+
event: "PULSE_ADD_JOBS",
|
|
29
|
+
message: "Pulse add scheduled jobs"
|
|
30
|
+
});
|
|
31
|
+
await Promise.all(providers.map((provider) => this.scheduleJobsForProvider(provider)));
|
|
32
|
+
await this.injector.emit("$afterPulseStart");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async $onDestroy() {
|
|
37
|
+
if (this.enabled) {
|
|
38
|
+
if (this.drainJobsBeforeClose && "drain" in this.pulse) {
|
|
39
|
+
this.logger.info({
|
|
40
|
+
event: "PULSE_DRAIN",
|
|
41
|
+
message: "Pulse is draining all jobs before close"
|
|
42
|
+
});
|
|
43
|
+
await this.pulse.drain();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.logger.info({
|
|
47
|
+
event: "PULSE_STOP",
|
|
48
|
+
message: "Pulse is stopping"
|
|
49
|
+
});
|
|
50
|
+
await this.pulse.stop();
|
|
51
|
+
}
|
|
52
|
+
await this.pulse.close({ force: true });
|
|
53
|
+
this.logger.info({ event: "PULSE_STOP", message: "Pulse stopped" });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
define(name, processor, options) {
|
|
57
|
+
return this.pulse.define(name, (job, ...rest) => {
|
|
58
|
+
const $ctx = new DIContext({
|
|
59
|
+
injector: this.injector,
|
|
60
|
+
id: uuid(),
|
|
61
|
+
logger: this.injector.logger
|
|
62
|
+
});
|
|
63
|
+
$ctx.set("job", job);
|
|
64
|
+
return runInContext($ctx, () => processor(job, ...rest));
|
|
65
|
+
}, options);
|
|
66
|
+
}
|
|
67
|
+
every(interval, name, data, options) {
|
|
68
|
+
return this.pulse.every(interval, name, data, options);
|
|
69
|
+
}
|
|
70
|
+
schedule(when, name, data) {
|
|
71
|
+
return this.pulse.schedule(when, name, data);
|
|
72
|
+
}
|
|
73
|
+
now(name, data) {
|
|
74
|
+
return this.pulse.now(name, data);
|
|
75
|
+
}
|
|
76
|
+
create(name, data) {
|
|
77
|
+
return this.pulse.create(name, data);
|
|
78
|
+
}
|
|
79
|
+
getProviders() {
|
|
80
|
+
return this.injector.getProviders(PROVIDER_TYPE_PULSE);
|
|
81
|
+
}
|
|
82
|
+
addPulseDefinitionsForProvider(provider) {
|
|
83
|
+
const store = provider.store.get("pulse", {});
|
|
84
|
+
if (!store.define) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
Object.entries(store.define).forEach(([propertyKey, { name, ...options }]) => {
|
|
88
|
+
const instance = this.injector.get(provider.token);
|
|
89
|
+
const jobProcessor = instance[propertyKey].bind(instance);
|
|
90
|
+
const jobName = this.getNameForJob(propertyKey, store.namespace, name);
|
|
91
|
+
this.define(jobName, jobProcessor, options);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async scheduleJobsForProvider(provider) {
|
|
95
|
+
const store = provider.store.get("pulse", {});
|
|
96
|
+
if (!store.every) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const promises = Object.entries(store.every).map(([propertyKey, { interval, name, ...options }]) => {
|
|
100
|
+
const jobName = this.getNameForJob(propertyKey, store.namespace, name);
|
|
101
|
+
return this.every(interval, jobName, {}, options);
|
|
102
|
+
});
|
|
103
|
+
await Promise.all(promises);
|
|
104
|
+
}
|
|
105
|
+
getNameForJob(propertyKey, namespace, customName) {
|
|
106
|
+
const name = customName || propertyKey;
|
|
107
|
+
return namespace ? `${namespace}.${name}` : name;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
__decorate([
|
|
111
|
+
Inject(),
|
|
112
|
+
__metadata("design:type", Logger)
|
|
113
|
+
], PulseModule.prototype, "logger", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
Inject(),
|
|
116
|
+
__metadata("design:type", InjectorService)
|
|
117
|
+
], PulseModule.prototype, "injector", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
Inject(),
|
|
120
|
+
__metadata("design:type", PulseService)
|
|
121
|
+
], PulseModule.prototype, "pulse", void 0);
|
|
122
|
+
__decorate([
|
|
123
|
+
Constant("pulse.enabled", false),
|
|
124
|
+
__metadata("design:type", Boolean)
|
|
125
|
+
], PulseModule.prototype, "enabled", void 0);
|
|
126
|
+
__decorate([
|
|
127
|
+
Constant("pulse.drainJobsBeforeClose", false),
|
|
128
|
+
__metadata("design:type", Boolean)
|
|
129
|
+
], PulseModule.prototype, "drainJobsBeforeClose", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
Constant("pulse.disableJobProcessing", false),
|
|
132
|
+
__metadata("design:type", Boolean)
|
|
133
|
+
], PulseModule.prototype, "disableJobProcessing", void 0);
|
|
134
|
+
PulseModule = __decorate([
|
|
135
|
+
Module()
|
|
136
|
+
], PulseModule);
|
|
137
|
+
export { PulseModule };
|
|
138
|
+
//# sourceMappingURL=PulseModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseModule.js","sourceRoot":"","sources":["../../src/PulseModule.ts"],"names":[],"mapp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AAC;IACnD,CAAC;CACF,CAAA;AA3IC;IAAC,MAAM,EAAE;8BACS,MAAM;2CAAC;AAEzB;IAAC,MAAM,EAAE;8BACW,eAAe;6CAAC;AAEpC;IAAC,MAAM,EAAE;8BACQ,YAAY;0CAAC;AAE9B;IAAC,QAAQ,CAAC,eAAe,EAAE,KAAK,CAAC;;4CACR;AAEzB;IAAC,QAAQ,CAAC,4BAA4B,EAAE,KAAK,CAAC;;yDACR;AAEtC;IAAC,QAAQ,CAAC,4BAA4B,EAAE,KAAK,CAAC;;yDACR;AAjB3B,WAAW;IADvB,MAAM,EAAE;GACI,WAAW,CA4IvB;SA5IY,WAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
export function Define(options = {}) {
|
|
3
|
+
return (target, propertyKey) => {
|
|
4
|
+
const store = {
|
|
5
|
+
define: {
|
|
6
|
+
[propertyKey]: options
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
Store.from(target).merge("pulse", store);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/decorators/define.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAGjC,MAAM,UAAU,MAAM,CAAC,UAAyB,EAAE;IAChD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAe;YACxB,MAAM,EAAE;gBACN,CAAC,WAAW,CAAC,EAAE,OAAO;aACvB;SACF,CAAC;QAEF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Store, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Define } from "./define.js";
|
|
3
|
+
export function Every(interval, options = {}) {
|
|
4
|
+
return useDecorators(Define(options), (target, propertyKey) => {
|
|
5
|
+
const store = {
|
|
6
|
+
every: {
|
|
7
|
+
[propertyKey]: { ...options, interval }
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
Store.from(target).merge("pulse", store);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=every.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"every.js","sourceRoot":"","sources":["../../../src/decorators/every.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AAChD,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAGnC,MAAM,UAAU,KAAK,CAAC,QAAgB,EAAE,UAAwB,EAAE;IAChE,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QACzE,MAAM,KAAK,GAAe;YACxB,KAAK,EAAE;gBACL,CAAC,WAAW,CAAC,EAAE,EAAC,GAAG,OAAO,EAAE,QAAQ,EAAC;aACtC;SACF,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StoreMerge, useDecorators } from "@tsed/core";
|
|
2
|
+
import { Injectable } from "@tsed/di";
|
|
3
|
+
import { PROVIDER_TYPE_PULSE } from "../constants/constants.js";
|
|
4
|
+
export function Pulse(options) {
|
|
5
|
+
return useDecorators(options?.namespace && StoreMerge("pulse", options), Injectable({
|
|
6
|
+
type: PROVIDER_TYPE_PULSE
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=pulse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pulse.js","sourceRoot":"","sources":["../../../src/decorators/pulse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAC,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAM9D,MAAM,UAAU,KAAK,CAAC,OAAsB;IAC1C,OAAO,aAAa,CAClB,OAAO,EAAE,SAAS,IAAI,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,EAClD,UAAU,CAAC;QACT,IAAI,EAAE,mBAAmB;KAC1B,CAAC,CACH,CAAC;AACJ,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./constants/constants.js";
|
|
5
|
+
export * from "./decorators/define.js";
|
|
6
|
+
export * from "./decorators/every.js";
|
|
7
|
+
export * from "./decorators/pulse.js";
|
|
8
|
+
export * from "./interfaces/interfaces.js";
|
|
9
|
+
export * from "./interfaces/PulseStore.js";
|
|
10
|
+
export * from "./PulseModule.js";
|
|
11
|
+
export * from "./services/PulseFactory.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseStore.js","sourceRoot":"","sources":["../../../src/interfaces/PulseStore.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Configuration, registerProvider } from "@tsed/di";
|
|
2
|
+
import { Pulse } from "@pulsecron/pulse";
|
|
3
|
+
// create Alias to avoid confusing import between Pulse from "@pulsecron/pulse" and Pulse decorator
|
|
4
|
+
export const PulseService = Pulse;
|
|
5
|
+
registerProvider({
|
|
6
|
+
provide: Pulse,
|
|
7
|
+
deps: [Configuration],
|
|
8
|
+
useFactory(settings) {
|
|
9
|
+
const opts = settings.get("pulse", { enabled: false });
|
|
10
|
+
return opts.enabled ? new Pulse(opts) : {};
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=PulseFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseFactory.js","sourceRoot":"","sources":["../../../src/services/PulseFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACzD,OAAO,EAAC,KAAK,EAAc,MAAM,kBAAkB,CAAC;AAEpD,mGAAmG;AACnG,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAC;AAGlC,gBAAgB,CAAC;IACf,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,CAAC,aAAa,CAAC;IACrB,UAAU,CAAC,QAAuB;QAChC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAmC,OAAO,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC,CAAC;QACvF,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AfterListen, Logger, OnDestroy } from "@tsed/common";
|
|
2
|
+
import { InjectorService, Provider } from "@tsed/di";
|
|
3
|
+
import { Job, Processor, DefineOptions, JobAttributesData } from "@pulsecron/pulse";
|
|
4
|
+
import { PulseService } from "./services/PulseFactory";
|
|
5
|
+
export declare class PulseModule implements OnDestroy, AfterListen {
|
|
6
|
+
protected logger: Logger;
|
|
7
|
+
protected injector: InjectorService;
|
|
8
|
+
protected pulse: PulseService;
|
|
9
|
+
private enabled;
|
|
10
|
+
private drainJobsBeforeClose;
|
|
11
|
+
private disableJobProcessing;
|
|
12
|
+
$afterListen(): Promise<any>;
|
|
13
|
+
$onDestroy(): Promise<any>;
|
|
14
|
+
define<T extends JobAttributesData>(name: string, processor: Processor<T>, options?: DefineOptions): void;
|
|
15
|
+
every(interval: string, name: string, data?: any, options?: any): Promise<Job<JobAttributesData> | Job<JobAttributesData>[]>;
|
|
16
|
+
schedule(when: Date | string, name: string, data?: any): Promise<Job<{}>[]> | Promise<Job<any>>;
|
|
17
|
+
now(name: string, data?: any): Promise<Job<JobAttributesData>>;
|
|
18
|
+
create(name: string, data?: any): Job<any>;
|
|
19
|
+
protected getProviders(): Provider<any>[];
|
|
20
|
+
protected addPulseDefinitionsForProvider(provider: Provider): void;
|
|
21
|
+
protected scheduleJobsForProvider(provider: Provider<any>): Promise<void>;
|
|
22
|
+
protected getNameForJob(propertyKey: string, namespace?: string, customName?: string): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PROVIDER_TYPE_PULSE = "PROVIDER_TYPE_PULSE";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./constants/constants.js";
|
|
5
|
+
export * from "./decorators/define.js";
|
|
6
|
+
export * from "./decorators/every.js";
|
|
7
|
+
export * from "./decorators/pulse.js";
|
|
8
|
+
export * from "./interfaces/interfaces.js";
|
|
9
|
+
export * from "./interfaces/PulseStore.js";
|
|
10
|
+
export * from "./PulseModule.js";
|
|
11
|
+
export * from "./services/PulseFactory.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DefineOptions as PulseDefineOptions, JobOptions } from "@pulsecron/pulse";
|
|
2
|
+
export interface DefineOptions extends PulseDefineOptions {
|
|
3
|
+
name?: string;
|
|
4
|
+
}
|
|
5
|
+
export type EveryOptions = JobOptions & DefineOptions;
|
|
6
|
+
export interface PulseStore {
|
|
7
|
+
namespace?: string;
|
|
8
|
+
define?: {
|
|
9
|
+
[propertyKey: string]: DefineOptions;
|
|
10
|
+
};
|
|
11
|
+
every?: {
|
|
12
|
+
[propertyKey: string]: EveryOptions & {
|
|
13
|
+
interval: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PulseConfig } from "@pulsecron/pulse";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace TsED {
|
|
4
|
+
interface Configuration {
|
|
5
|
+
pulse?: {
|
|
6
|
+
/**
|
|
7
|
+
* Enable Pulse jobs. Default false.
|
|
8
|
+
*/
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
disableJobProcessing?: boolean;
|
|
11
|
+
drainJobsBeforeClose?: boolean;
|
|
12
|
+
} & PulseConfig;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsed/pulse",
|
|
3
|
+
"version": "7.77.0",
|
|
4
|
+
"description": "@pulsecron/pulse package for Ts.ED framework",
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"main": "./lib/cjs/index.js",
|
|
7
|
+
"module": "./lib/esm/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "yarn barrels && yarn build:ts",
|
|
17
|
+
"barrels": "barrels",
|
|
18
|
+
"test": "jest --runInBand && jest-coverage-thresholds-bumper",
|
|
19
|
+
"build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"tslib": "2.6.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@pulsecron/pulse": "^1.6.1",
|
|
26
|
+
"@tsed/barrels": "7.77.0",
|
|
27
|
+
"@tsed/common": "7.77.0",
|
|
28
|
+
"@tsed/core": "7.77.0",
|
|
29
|
+
"@tsed/di": "7.77.0",
|
|
30
|
+
"@tsed/typescript": "7.77.0",
|
|
31
|
+
"eslint": "^8.57.0",
|
|
32
|
+
"jest": "^29.7.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@pulsecron/pulse": ">=1"
|
|
36
|
+
},
|
|
37
|
+
"repository": "https://github.com/tsedio/tsed",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/tsedio/tsed/issues"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/third-parties/pulse",
|
|
42
|
+
"author": "Romain Lenzotti",
|
|
43
|
+
"license": "MIT"
|
|
44
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<p style="text-align: center" align="center">
|
|
2
|
+
<a href="https://tsed.io" target="_blank"><img src="https://tsed.io/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
|
|
7
|
+
<h1>Pulse</h1>
|
|
8
|
+
|
|
9
|
+
[](https://github.com/tsedio/tsed/actions?query=workflow%3A%22Build+%26+Release%22)
|
|
10
|
+
[](https://github.com/tsedio/tsed/blob/master/CONTRIBUTING.md)
|
|
11
|
+
[](https://badge.fury.io/js/%40tsed%2Fcommon)
|
|
12
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
13
|
+
[](https://github.com/prettier/prettier)
|
|
14
|
+
[](https://github.com/sponsors/romakita)
|
|
15
|
+
[](https://opencollective.com/tsed)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div align="center">
|
|
20
|
+
<a href="https://tsed.io/">Website</a>
|
|
21
|
+
<span> • </span>
|
|
22
|
+
<a href="https://tsed.io/getting-started/">Getting started</a>
|
|
23
|
+
<span> • </span>
|
|
24
|
+
<a href="https://api.tsed.io/rest/slack/tsedio/tsed">Slack</a>
|
|
25
|
+
<span> • </span>
|
|
26
|
+
<a href="https://twitter.com/TsED_io">Twitter</a>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<hr />
|
|
30
|
+
|
|
31
|
+
A package of Ts.ED framework. See website: https://tsed.io
|
|
32
|
+
|
|
33
|
+
## Feature
|
|
34
|
+
|
|
35
|
+
@pulsecron/pulse is maintained fork of the Agenda.
|
|
36
|
+
|
|
37
|
+
Currently, `@tsed/pulse` allows you to decorate classes with `@Pulse` and
|
|
38
|
+
corresponding methods to have them picked up by the @pulsecron/pulse library to be
|
|
39
|
+
scheduled automatically (`@Every`) or programmatically (`@Define`) via the PulseService.
|
|
40
|
+
|
|
41
|
+
For more information about Pulse look at the documentation [here](https://github.com/pulsecron/pulse);
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
To begin, install the Pulse module for Ts.ED:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install --save @tsed/pulse
|
|
49
|
+
npm install --save @pulsecron/pulse
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configure your server
|
|
53
|
+
|
|
54
|
+
Import `@tsed/pulse` in your Server:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import {Configuration} from "@tsed/common";
|
|
58
|
+
import "@tsed/pulse"; // import pulse ts.ed module
|
|
59
|
+
|
|
60
|
+
const mongoConnectionString = "mongodb://127.0.0.1/pulse";
|
|
61
|
+
|
|
62
|
+
@Configuration({
|
|
63
|
+
pulse: {
|
|
64
|
+
enabled: true, // Enable Pulse jobs for this instance.
|
|
65
|
+
// drainJobsBeforeStop: true, // Wait for jobs to finish before stopping the pulse process.
|
|
66
|
+
// disableJobProcessing: true, // Prevents jobs from being processed.
|
|
67
|
+
// pass any options that you would normally pass to new Pulse(), e.g.
|
|
68
|
+
db: {
|
|
69
|
+
address: mongoConnectionString
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
export class Server {}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Create a new Service
|
|
77
|
+
|
|
78
|
+
Decorate the class with `@Pulse`. The `namespace` option is optional and will
|
|
79
|
+
prefix the job name with `namespace.`
|
|
80
|
+
|
|
81
|
+
Use the `@Every` decorator to define a cron-like job that gets automatically
|
|
82
|
+
scheduled based on the given interval. The name is optional and by default the
|
|
83
|
+
method name is used as job name.
|
|
84
|
+
|
|
85
|
+
Use the `@Define` decorator on methods that you would like to schedule
|
|
86
|
+
programmatically via the PulseService and Pulse instance access.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import {Pulse, Every, Define} from "@tsed/pulse";
|
|
90
|
+
import {Job} from "@pulsecron/pulse";
|
|
91
|
+
|
|
92
|
+
@Pulse({namespace: "email"})
|
|
93
|
+
export class EmailJobService {
|
|
94
|
+
@Every("60 minutes", {
|
|
95
|
+
name: "maintenanceJob"
|
|
96
|
+
/* ... and any option you would normally pass to pulse.every/define */
|
|
97
|
+
})
|
|
98
|
+
async sendAdminStatistics(job: Job) {
|
|
99
|
+
// implement something here
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Define({
|
|
103
|
+
name: "sendWelcomeEmail"
|
|
104
|
+
/* ... and any option you would normally pass to pulse.define(...) */
|
|
105
|
+
})
|
|
106
|
+
async sendWelcomeEmail(job: Job) {
|
|
107
|
+
// implement something here
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Define({name: "sendFollowUpEmail"})
|
|
111
|
+
async sendFollowUpEmail(job: Job) {
|
|
112
|
+
// implement something here
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Define a job processor manually
|
|
118
|
+
|
|
119
|
+
PulseModule exposes methods to manually define a job processor. It can be useful to define a job processor when you need to fetch data beforehand and dynamically build job name / options.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import {Pulse, PulseModule, Define} from "@tsed/pulse";
|
|
123
|
+
|
|
124
|
+
@Pulse({namespace: "email"})
|
|
125
|
+
export class EmailJobService {
|
|
126
|
+
@Inject()
|
|
127
|
+
pulse: PulseModule;
|
|
128
|
+
|
|
129
|
+
@Inject()
|
|
130
|
+
httpClient: HttpClient;
|
|
131
|
+
|
|
132
|
+
cache: Map<string, Job[]> = new Map();
|
|
133
|
+
|
|
134
|
+
@Define({
|
|
135
|
+
name: "sendWelcomeEmail",
|
|
136
|
+
concurrency: 3
|
|
137
|
+
/* ... and any option you would normally pass to pulse.define(...) */
|
|
138
|
+
})
|
|
139
|
+
async sendWelcomeEmail(job: Job) {
|
|
140
|
+
// implement something here
|
|
141
|
+
console.log(job.attrs.data.locale);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async $beforePulseStart() {
|
|
145
|
+
const locales = await this.httpClient.get("/locales");
|
|
146
|
+
|
|
147
|
+
this.cache.set(
|
|
148
|
+
"sendWelcomeEmail",
|
|
149
|
+
locales.map((locale) => {
|
|
150
|
+
return this.pulse.create("sendWelcomeEmail", {locale});
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async $afterPulseStart() {
|
|
156
|
+
const jobs = this.cache.get("sendWelcomeEmail");
|
|
157
|
+
|
|
158
|
+
await Promise.all(jobs.map((job) => job.repeatEvery("1 week").save()));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Inject Pulse
|
|
164
|
+
|
|
165
|
+
Inject the PulseService instance to interact with it directly, e.g. to schedule
|
|
166
|
+
a job manually.
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import {Service, AfterRoutesInit} from "@tsed/common";
|
|
170
|
+
import {PulseModule} from "@tsed/pulse";
|
|
171
|
+
|
|
172
|
+
@Service()
|
|
173
|
+
export class UsersService {
|
|
174
|
+
@Inject()
|
|
175
|
+
private pulse: PulseModule;
|
|
176
|
+
|
|
177
|
+
async create(user: User): Promise<User> {
|
|
178
|
+
// do something
|
|
179
|
+
// ...
|
|
180
|
+
// then schedule some jobs
|
|
181
|
+
await this.pulse.now("email.sendWelcomeEmail", {user});
|
|
182
|
+
await this.pulse.schedule("in 2 hours", "email.sendFollowUpEmail", {user});
|
|
183
|
+
|
|
184
|
+
return user;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Contributors
|
|
190
|
+
|
|
191
|
+
Please read [contributing guidelines here](https://tsed.io/contributing.html)
|
|
192
|
+
|
|
193
|
+
<a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
194
|
+
|
|
195
|
+
## Backers
|
|
196
|
+
|
|
197
|
+
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
198
|
+
|
|
199
|
+
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
200
|
+
|
|
201
|
+
## Sponsors
|
|
202
|
+
|
|
203
|
+
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
The MIT License (MIT)
|
|
208
|
+
|
|
209
|
+
Copyright (c) 2016 - 2021 Romain Lenzotti
|
|
210
|
+
|
|
211
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
212
|
+
|
|
213
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
214
|
+
|
|
215
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|