@resolveio/server-lib 12.5.72 → 12.6.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/cron/cron.d.ts +14 -5
- package/cron/cron.js +86 -143
- package/cron/cron.js.map +1 -1
- package/managers/cron.manager.js +9 -22
- package/managers/cron.manager.js.map +1 -1
- package/package.json +2 -2
package/cron/cron.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { CronJob, CronCommand, CronOnCompleteCommand, CronJobParams } from 'cron';
|
|
2
|
+
export declare class CronJobManager {
|
|
3
|
+
private jobs;
|
|
4
|
+
constructor(key?: string, tab?: string | Date, task?: CronCommand<any, boolean>, onComplete?: CronOnCompleteCommand, start?: boolean, timeZone?: string, context?: CronJobParams, runOnInit?: boolean);
|
|
5
|
+
getJob(key: string): CronJob;
|
|
6
|
+
getJobs(): string[];
|
|
7
|
+
add(key: string, tab: string | Date, task: CronCommand<any, boolean>, onComplete?: CronOnCompleteCommand, start?: boolean, timeZone?: string, context?: CronJobParams, runOnInit?: boolean): void;
|
|
8
|
+
update(key: string, tab?: string | Date, task?: CronCommand<any, boolean>, onComplete?: () => void, start?: boolean, timeZone?: string, context?: any, runOnInit?: boolean): void;
|
|
9
|
+
delete(key: string): void;
|
|
10
|
+
start(key: string): void;
|
|
11
|
+
stop(key: string): void;
|
|
12
|
+
stopAll(): void;
|
|
13
|
+
exists(key: string): boolean;
|
|
14
|
+
}
|
package/cron/cron.js
CHANGED
|
@@ -1,162 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CronJobManager = void 0;
|
|
4
|
+
var cron_1 = require("cron");
|
|
5
|
+
var CronJobManager = /** @class */ (function () {
|
|
6
|
+
function CronJobManager(key, tab, task, onComplete, start, timeZone, context, runOnInit) {
|
|
7
|
+
this.jobs = {};
|
|
8
|
+
if (key && tab && task) {
|
|
9
|
+
this.add(key, tab, task, onComplete, start, timeZone, context, runOnInit);
|
|
10
|
+
}
|
|
6
11
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
CronJobManager.prototype.getJob = function (key) {
|
|
13
|
+
return this.jobs[key];
|
|
14
|
+
};
|
|
15
|
+
CronJobManager.prototype.getJobs = function () {
|
|
16
|
+
return Object.keys(this.jobs);
|
|
17
|
+
};
|
|
18
|
+
CronJobManager.prototype.add = function (key, tab, task, onComplete, start, timeZone, context, runOnInit) {
|
|
19
|
+
if ((typeof tab === 'string' || tab instanceof Date) && typeof key === 'string' && task instanceof Function) {
|
|
20
|
+
try {
|
|
21
|
+
if (this.jobs[key]) {
|
|
22
|
+
this.delete(key);
|
|
23
|
+
console.warn("".concat(key, " already existed and was deleted from the manager..."));
|
|
24
|
+
}
|
|
25
|
+
this.jobs[key] = new cron_1.CronJob(tab, task, onComplete, start, timeZone, context, runOnInit);
|
|
26
|
+
}
|
|
27
|
+
catch (fooBaredByUser) {
|
|
28
|
+
console.error("crontab: ".concat(tab, " possibly not valid, job ").concat(key, " not started...").concat(fooBaredByUser.message));
|
|
21
29
|
}
|
|
22
|
-
this.jobs[key] = new CronJobPackage(options);
|
|
23
|
-
}
|
|
24
|
-
catch (fooBaredByUser) {
|
|
25
|
-
console.error("crontab: ".concat(tab, " possibly not valid, job ").concat(key, " not started...").concat(fooBaredByUser.message));
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.warn("couldn't add: ".concat(key, " improper arguments"));
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
CrontabManager.prototype.update = function () {
|
|
33
|
-
if (arguments.length === 2) {
|
|
34
|
-
if (typeof arguments[1] === 'string' || arguments[1] instanceof Date) {
|
|
35
|
-
updateTab.call(this, arguments[0], arguments[1]);
|
|
31
|
+
else {
|
|
32
|
+
console.warn("couldn't add: ".concat(key, " improper arguments"));
|
|
36
33
|
}
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
};
|
|
35
|
+
CronJobManager.prototype.update = function (key, tab, task, onComplete, start, timeZone, context, runOnInit) {
|
|
36
|
+
// Check if the job exists
|
|
37
|
+
if (!this.jobs[key]) {
|
|
38
|
+
console.warn("Job with key ".concat(key, " does not exist."));
|
|
39
|
+
return;
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
else if (arguments.length === 3) {
|
|
42
|
-
updateTab.call(this, arguments[0], arguments[1]);
|
|
43
|
-
updateTask.call(this, arguments[0], arguments[2]);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
console.error("incorrect number of arguents passed to update.. won't update.. ".concat(arguments[0]));
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
CrontabManager.prototype.deleteJob = function (key) {
|
|
50
|
-
try {
|
|
41
|
+
// Stop the existing job
|
|
51
42
|
this.jobs[key].stop();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (this.jobs[key].running) {
|
|
61
|
-
console.warn("".concat(key, " job already running"));
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
43
|
+
// Store the running state
|
|
44
|
+
var wasRunning = this.jobs[key].running;
|
|
45
|
+
// Create a new job instance with the updated properties
|
|
46
|
+
var newJob = new cron_1.CronJob(tab || this.jobs[key].cronTime.source, task || this.jobs[key].fireOnTick, onComplete, wasRunning || start, timeZone, context, runOnInit);
|
|
47
|
+
// Replace the old job with the new one
|
|
48
|
+
this.jobs[key] = newJob;
|
|
49
|
+
// Start the job again if it was previously running or if start parameter is true
|
|
50
|
+
if (wasRunning || start) {
|
|
64
51
|
this.jobs[key].start();
|
|
65
52
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
CrontabManager.prototype.stop = function (key) {
|
|
72
|
-
try {
|
|
73
|
-
if (!this.jobs[key].running) {
|
|
74
|
-
console.warn("".concat(key, " job already stopped"));
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
53
|
+
};
|
|
54
|
+
CronJobManager.prototype.delete = function (key) {
|
|
55
|
+
try {
|
|
77
56
|
this.jobs[key].stop();
|
|
57
|
+
delete this.jobs[key];
|
|
78
58
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
CrontabManager.prototype.stopAll = function () {
|
|
85
|
-
// tslint:disable-next-line:forin
|
|
86
|
-
for (var jobKey in this.jobs) {
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error(new Date(), "error in trying to stop job: ".concat(key, ": ").concat(err));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
CronJobManager.prototype.start = function (key) {
|
|
87
64
|
try {
|
|
88
|
-
this.jobs[
|
|
65
|
+
if (this.jobs[key].running) {
|
|
66
|
+
console.warn("".concat(key, " job already running"));
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.jobs[key].start();
|
|
70
|
+
}
|
|
89
71
|
}
|
|
90
72
|
catch (err) {
|
|
73
|
+
console.error("couldn't start job: ".concat(key, ": ").concat(err));
|
|
91
74
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return manString;
|
|
102
|
-
};
|
|
103
|
-
CrontabManager.prototype.listCrons = function () {
|
|
104
|
-
var manString = '{\n';
|
|
105
|
-
// tslint:disable-next-line:forin
|
|
106
|
-
for (var jobKey in this.jobs) {
|
|
107
|
-
manString += "'".concat(jobKey, "': ").concat(this.jobs[jobKey].cronTime.source, " status: ").concat(this.jobs[jobKey].running ? 'Running' : 'Stopped', " \n");
|
|
108
|
-
}
|
|
109
|
-
manString += '\n}';
|
|
110
|
-
return manString;
|
|
111
|
-
};
|
|
112
|
-
CrontabManager.prototype.exists = function (tabKey) {
|
|
113
|
-
if (this.jobs[tabKey]) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
};
|
|
118
|
-
function combineOptions(tab, task, options) {
|
|
119
|
-
var newOpts = {};
|
|
120
|
-
newOpts['cronTime'] = tab;
|
|
121
|
-
newOpts['onTick'] = task;
|
|
122
|
-
if (options instanceof Object) {
|
|
123
|
-
// might overwrite... please be careful.
|
|
124
|
-
// tslint:disable-next-line:forin
|
|
125
|
-
for (var optionKey in options) {
|
|
126
|
-
newOpts[optionKey] = options[optionKey];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return newOpts;
|
|
130
|
-
}
|
|
131
|
-
function updateTab(key, cronstring) {
|
|
132
|
-
try {
|
|
133
|
-
var running = this.jobs[key].running;
|
|
134
|
-
this.jobs[key].stop();
|
|
135
|
-
if (typeof cronstring === 'string' || cronstring instanceof Date) {
|
|
136
|
-
this.jobs[key] = new CronJobPackage(cronstring, this.jobs[key]._callbacks[0], this.jobs[key].onComplete, running, this.jobs[key].zone);
|
|
75
|
+
};
|
|
76
|
+
CronJobManager.prototype.stop = function (key) {
|
|
77
|
+
try {
|
|
78
|
+
if (!this.jobs[key].running) {
|
|
79
|
+
console.warn("".concat(key, " job already stopped"));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.jobs[key].stop();
|
|
83
|
+
}
|
|
137
84
|
}
|
|
138
|
-
|
|
139
|
-
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error("couldn't stop job: ".concat(key, ": ").concat(err));
|
|
140
87
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
this.jobs[key].stop();
|
|
150
|
-
if (!(task instanceof Function)) {
|
|
151
|
-
console.error("can't update with something that is not a function: ".concat(typeof (task)));
|
|
152
|
-
return;
|
|
88
|
+
};
|
|
89
|
+
CronJobManager.prototype.stopAll = function () {
|
|
90
|
+
for (var jobKey in this.jobs) {
|
|
91
|
+
try {
|
|
92
|
+
this.jobs[jobKey].stop();
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
}
|
|
153
96
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
97
|
+
};
|
|
98
|
+
CronJobManager.prototype.exists = function (key) {
|
|
99
|
+
return !!this.jobs[key];
|
|
100
|
+
};
|
|
101
|
+
return CronJobManager;
|
|
102
|
+
}());
|
|
103
|
+
exports.CronJobManager = CronJobManager;
|
|
161
104
|
|
|
162
105
|
//# sourceMappingURL=cron.js.map
|
package/cron/cron.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cron/cron.ts"],"names":[],"mappings":"AAAA,IAAI,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;AAE7C,SAAS,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO;IAC9C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACf,IAAI,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE;QACvB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;KAClC;AAEF,CAAC;AAED,cAAc,CAAC,SAAS,CAAC,MAAM,GAAG,UAAS,GAAG;IAC7C,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG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AM,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,+BAAwB,GAAG,iBAAO,MAAM,CAAC,OAAO,CAAE,CAAC,CAAC;KAClE;AACF,CAAC;AAED,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC","file":"cron.js","sourcesContent":["let CronJobPackage = require('cron').CronJob;\n\nfunction CrontabManager(key, tab, task, options) {\n\tthis.jobs = {};\n\tif (key && tab && task) {\n\t\tthis.add(key, tab, task, options);\n\t}\n\n}\n\nCrontabManager.prototype.getJob = function(key) {\n\treturn this.jobs[key];\n};\n\nCrontabManager.prototype.getJobs = function() {\n\treturn Object.keys(this.jobs);\n};\n\nCrontabManager.prototype.add = function(key, tab, task, options) {\n\tif ((typeof tab === 'string' || tab instanceof Date) && typeof key === 'string' && task instanceof Function) {\n\t\toptions = combineOptions(tab, task, options);\n\t\ttry {\n\t\t\tif (this.jobs[key]) {\n\t\t\t\tthis.deleteJob(key);\n\t\t\t\tconsole.warn(`${key} already existed and was deleted from the manager...`);\n\t\t\t}\n\t\t\t\n\t\t\tthis.jobs[key] = new CronJobPackage(options);\n\t\t} \n\t\tcatch (fooBaredByUser) {\n\t\t\tconsole.error(`crontab: ${tab} possibly not valid, job ${key} not started...${fooBaredByUser.message}`);\n\t\t}\n\t}\n\telse {\n\t\tconsole.warn(`couldn't add: ${key} improper arguments`);\n\t}\n};\n\nCrontabManager.prototype.update = function() {\n\tif (arguments.length === 2) {\n\t\tif (typeof arguments[1] === 'string' || arguments[1] instanceof Date) {\n\t\t\tupdateTab.call(this, arguments[0], arguments[1]);\n\t\t}\n\t\telse if (arguments[1] instanceof Function) {\n\t\t\tupdateTask.call(this, arguments[0], arguments[1]);\n\t\t}\n\t} \n\telse if (arguments.length === 3) {\n\t\tupdateTab.call(this, arguments[0], arguments[1]);\n\t\tupdateTask.call(this, arguments[0], arguments[2]);\n\t}\n\telse {\n\t\tconsole.error(`incorrect number of arguents passed to update.. won't update.. ${arguments[0]}`);\n\t}\n};\n\nCrontabManager.prototype.deleteJob = function(key) {\n\ttry {\n\t\tthis.jobs[key].stop();\n\t\tdelete this.jobs[key];\n\t}\n\tcatch (err) { \n\t\tconsole.error(new Date(), `error in trying to stop job: ${key}: ${err}`);\n\t}\n};\n\nCrontabManager.prototype.start = function(key) {\n\ttry {\n\t\tif (this.jobs[key].running) {\n\t\t\tconsole.warn(`${key} job already running`);\n\t\t}\n\t\telse {\n\t\t\tthis.jobs[key].start();\n\t\t}\n\t}\n\tcatch (err) {\n\t\tconsole.error(`couldn't start job: ${key}: ${err}`);\n\t}\n};\n\nCrontabManager.prototype.stop = function(key) {\n\ttry {\n\t\tif (! this.jobs[key].running ) {\n\t\t\tconsole.warn(`${key} job already stopped`);\n\t\t}\n\t\telse {\n\t\t\tthis.jobs[key].stop();\n\t\t}\n\t}\n\tcatch (err) {\n\t\tconsole.error(`couldn't stop job: ${key}: ${err}`);\n\t}\n};\n\nCrontabManager.prototype.stopAll = function() {\n\t// tslint:disable-next-line:forin\n\tfor (let jobKey in this.jobs) {\n\t\ttry {\n\t\t\tthis.jobs[jobKey].stop();\n\t\t}\n\t\tcatch (err) {\n\n\t\t}\n\t}\n};\n\nCrontabManager.prototype.toString = function() {\n\tlet manString = '{\\n';\n\t// tslint:disable-next-line:forin\n\tfor (let jobKey in this.jobs) {\n\n\t\tmanString += `'${jobKey}': ${this.jobs[jobKey].cronTime.source}: ${this.jobs[jobKey]._callbacks[0]}: ${this.jobs[jobKey].running ? 'Running' : 'Stopped'}`;\n\t}\n\tmanString += '\\n}';\n\treturn manString;\n};\n\nCrontabManager.prototype.listCrons = function() {\n\tlet manString = '{\\n';\n\t// tslint:disable-next-line:forin\n\tfor (let jobKey in this.jobs) {\n\t\tmanString += `'${jobKey}': ${this.jobs[jobKey].cronTime.source} status: ${this.jobs[jobKey].running ? 'Running' : 'Stopped'} \\n`;\n\t}\n\tmanString += '\\n}';\n\treturn manString;\n};\n\nCrontabManager.prototype.exists = function(tabKey) {\n\tif (this.jobs[tabKey]) {\n\t\treturn true;\n\t}\n\n\treturn false;\n};\n\nfunction combineOptions(tab, task, options) {\n\tlet newOpts = {};\n\tnewOpts['cronTime'] = tab; \n\tnewOpts['onTick'] = task;\n\n\tif (options instanceof Object) {\n\t\t// might overwrite... please be careful.\n\t\t// tslint:disable-next-line:forin\n\t\tfor (let optionKey in options) {\n\t\t\tnewOpts[optionKey] = options[optionKey];\n\t\t}\n\t}\n\treturn newOpts;\n}\n\nfunction updateTab(key, cronstring) {\n\n\ttry {\n\t\tlet running = this.jobs[key].running;\n\t\tthis.jobs[key].stop();\n\n\t\tif (typeof cronstring === 'string' || cronstring instanceof Date) {\n\t\t\tthis.jobs[key] = new CronJobPackage(cronstring, this.jobs[key]._callbacks[0], this.jobs[key].onComplete, running, this.jobs[key].zone);\n\t\t}\n\t\telse {\n\t\t\tthrow new Error(`The cron definition passed was not a string or a Date object! ${key} was stopped and not updated`);\n\t\t}\n\t}\n\tcatch (tabErr) {\n\t\tconsole.error(`error updating tab: ${key} - ${tabErr.message}`);\n\t}\n}\n\nfunction updateTask(key, task) {\n\ttry {\n\t\tlet running = this.jobs[key].running;\n\t\tthis.jobs[key].stop();\n\n\t\tif (!(task instanceof Function)) {\n\t\t\tconsole.error(`can't update with something that is not a function: ${typeof(task)}`);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.jobs[key] = new CronJobPackage(this.jobs[key].cronTime.source, task, this.jobs[key].onComplete, running, this.jobs[key].zone);\n\n\n\t} \n\tcatch (tabErr) {\n\t\tconsole.error(`error updating task: ${key} - ${tabErr.message}`);\n\t}\n}\n\nmodule.exports = CrontabManager;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/cron/cron.ts"],"names":[],"mappings":";;;AAAA,6BAA4F;AAE5F;IAGI,wBAAY,GAAY,EAAE,GAAmB,EAAE,IAAgC,EAAE,UAAkC,EAAE,KAAe,EAAE,QAAiB,EAAE,OAAuB,EAAE,SAAmB;QACjM,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,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;IAED,8BAAK,GAAL,UAAM,GAAW;QAChB,IAAI;YACH,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE;gBAC3B,OAAO,CAAC,IAAI,CAAC,UAAG,GAAG,yBAAsB,CAAC,CAAC;aAC3C;iBACI;gBACJ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;aACvB;SACD;QACD,OAAO,GAAG,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,8BAAuB,GAAG,eAAK,GAAG,CAAE,CAAC,CAAC;SACpD;IACF,CAAC;IAED,6BAAI,GAAJ,UAAK,GAAW;QACf,IAAI;YACH,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAG;gBAC7B,OAAO,CAAC,IAAI,CAAC,UAAG,GAAG,yBAAsB,CAAC,CAAC;aAC3C;iBACI;gBACJ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;aACtB;SACD;QACD,OAAO,GAAG,EAAE;YACX,OAAO,CAAC,KAAK,CAAC,6BAAsB,GAAG,eAAK,GAAG,CAAE,CAAC,CAAC;SACnD;IACF,CAAC;IAED,gCAAO,GAAP;QACC,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC,IAAI,EAAE;YAC7B,IAAI;gBACH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;aACzB;YACD,OAAO,GAAG,EAAE;aAEX;SACD;IACF,CAAC;IAED,+BAAM,GAAN,UAAO,GAAW;QACjB,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACF,qBAAC;AAAD,CAxHA,AAwHC,IAAA;AAxHY,wCAAc","file":"cron.js","sourcesContent":["import { CronJob, CronCommand, CronTime, CronOnCompleteCommand, CronJobParams } from 'cron';\n\nexport class CronJobManager {\n\tprivate jobs: { [key: string]: CronJob };\n\n constructor(key?: string, tab?: string | Date, task?: CronCommand<any, boolean>, onComplete?: CronOnCompleteCommand, start?: boolean, timeZone?: string, context?: CronJobParams, runOnInit?: boolean) {\n this.jobs = {};\n if (key && tab && task) {\n this.add(key, tab, task, onComplete, start, timeZone, context, runOnInit);\n }\n }\n\n getJob(key: string): CronJob {\n return this.jobs[key];\n }\n\n getJobs(): string[] {\n return Object.keys(this.jobs);\n }\n\n add(key: string, tab: string | Date, task: CronCommand<any, boolean>, onComplete?: CronOnCompleteCommand, start?: boolean, timeZone?: string, context?: CronJobParams, runOnInit?: boolean): void {\n\t\tif ((typeof tab === 'string' || tab instanceof Date) && typeof key === 'string' && task instanceof Function) {\n\t\t\ttry {\n\t\t\t\tif (this.jobs[key]) {\n\t\t\t\t\tthis.delete(key);\n\t\t\t\t\tconsole.warn(`${key} already existed and was deleted from the manager...`);\n\t\t\t\t}\n\t\t\t\tthis.jobs[key] = new CronJob(tab, task, onComplete, start, timeZone, context, runOnInit);\n\t\t\t} catch (fooBaredByUser) {\n\t\t\t\tconsole.error(`crontab: ${tab} possibly not valid, job ${key} not started...${fooBaredByUser.message}`);\n\t\t\t}\n\t\t} else {\n\t\t\tconsole.warn(`couldn't add: ${key} improper arguments`);\n\t\t}\n\t}\n\n\tupdate(key: string, tab?: string | Date, task?: CronCommand<any, boolean>, onComplete?: () => void, start?: boolean, timeZone?: string, context?: any, runOnInit?: boolean): void {\n\t\t// Check if the job exists\n\t\tif (!this.jobs[key]) {\n\t\t\tconsole.warn(`Job with key ${key} does not exist.`);\n\t\t\treturn;\n\t\t}\n\t\n\t\t// Stop the existing job\n\t\tthis.jobs[key].stop();\n\t\n\t\t// Store the running state\n\t\tconst wasRunning = this.jobs[key].running;\n\t\n\t\t// Create a new job instance with the updated properties\n\t\tconst newJob = new CronJob(\n\t\t\ttab || this.jobs[key].cronTime.source,\n\t\t\ttask || this.jobs[key].fireOnTick,\n\t\t\tonComplete,\n\t\t\twasRunning || start,\n\t\t\ttimeZone,\n\t\t\tcontext,\n\t\t\trunOnInit\n\t\t);\n\t\n\t\t// Replace the old job with the new one\n\t\tthis.jobs[key] = newJob;\n\t\n\t\t// Start the job again if it was previously running or if start parameter is true\n\t\tif (wasRunning || start) {\n\t\t\tthis.jobs[key].start();\n\t\t}\n\t}\n\t\n\t\n\tdelete(key: string) {\n\t\ttry {\n\t\t\tthis.jobs[key].stop();\n\t\t\tdelete this.jobs[key];\n\t\t}\n\t\tcatch (err) { \n\t\t\tconsole.error(new Date(), `error in trying to stop job: ${key}: ${err}`);\n\t\t}\n\t}\n\n\tstart(key: string) {\n\t\ttry {\n\t\t\tif (this.jobs[key].running) {\n\t\t\t\tconsole.warn(`${key} job already running`);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.jobs[key].start();\n\t\t\t}\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(`couldn't start job: ${key}: ${err}`);\n\t\t}\n\t}\n\n\tstop(key: string) {\n\t\ttry {\n\t\t\tif (!this.jobs[key].running ) {\n\t\t\t\tconsole.warn(`${key} job already stopped`);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.jobs[key].stop();\n\t\t\t}\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(`couldn't stop job: ${key}: ${err}`);\n\t\t}\n\t}\n\n\tstopAll() {\n\t\tfor (let jobKey in this.jobs) {\n\t\t\ttry {\n\t\t\t\tthis.jobs[jobKey].stop();\n\t\t\t}\n\t\t\tcatch (err) {\n\t\n\t\t\t}\n\t\t}\n\t}\n\n\texists(key: string) {\n\t\treturn !!this.jobs[key];\n\t}\n}"]}
|
package/managers/cron.manager.js
CHANGED
|
@@ -38,12 +38,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.CronManager = void 0;
|
|
40
40
|
var cron_job_collection_1 = require("../collections/cron-job.collection");
|
|
41
|
-
var
|
|
41
|
+
var cron_1 = require("../cron/cron");
|
|
42
|
+
var moment = require("moment");
|
|
42
43
|
var CronManager = /** @class */ (function () {
|
|
43
44
|
function CronManager(mainServer) {
|
|
44
45
|
this._jobs = [];
|
|
45
46
|
this._mainServer = mainServer;
|
|
46
|
-
this._cronManager = new CronJobManager();
|
|
47
|
+
this._cronManager = new cron_1.CronJobManager();
|
|
47
48
|
this.watchCrons();
|
|
48
49
|
}
|
|
49
50
|
CronManager.prototype.watchCrons = function () {
|
|
@@ -128,23 +129,9 @@ var CronManager = /** @class */ (function () {
|
|
|
128
129
|
cron_job_collection_1.CronJobs.updateOne({ _id: cron._id }, { $set: { running: false } });
|
|
129
130
|
}
|
|
130
131
|
if (!this.doesCronJobExist(cron)) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var cronOptions = {
|
|
135
|
-
start: true,
|
|
136
|
-
// onComplete: () => {
|
|
137
|
-
// this.runCronJobCompleted(cron);
|
|
138
|
-
// },
|
|
139
|
-
// timeZone: cron.timezone
|
|
140
|
-
};
|
|
141
|
-
if (cron.timezone) {
|
|
142
|
-
cronOptions['timeZone'] = cron.timezone;
|
|
143
|
-
}
|
|
144
|
-
this._cronManager.add(cron.name, cron.time_to_run, function () {
|
|
145
|
-
_this.runCronJob(cron);
|
|
146
|
-
}, cronOptions);
|
|
147
|
-
}
|
|
132
|
+
this._cronManager.add(cron.name, cron.time_to_run, function () {
|
|
133
|
+
_this.runCronJob(cron);
|
|
134
|
+
}, null, true, cron.timezone, null, false);
|
|
148
135
|
}
|
|
149
136
|
};
|
|
150
137
|
CronManager.prototype.updateCronJob = function (cron) {
|
|
@@ -154,7 +141,7 @@ var CronManager = /** @class */ (function () {
|
|
|
154
141
|
};
|
|
155
142
|
CronManager.prototype.removeCronJob = function (cron_name) {
|
|
156
143
|
if (this.doesCronJobNameExist(cron_name)) {
|
|
157
|
-
this._cronManager.
|
|
144
|
+
this._cronManager.delete(cron_name);
|
|
158
145
|
}
|
|
159
146
|
};
|
|
160
147
|
CronManager.prototype.startCronJob = function (cron) {
|
|
@@ -164,7 +151,7 @@ var CronManager = /** @class */ (function () {
|
|
|
164
151
|
};
|
|
165
152
|
CronManager.prototype.stopCronJob = function (cron) {
|
|
166
153
|
if (this.doesCronJobExist(cron)) {
|
|
167
|
-
this._cronManager.
|
|
154
|
+
this._cronManager.stop(cron.name);
|
|
168
155
|
}
|
|
169
156
|
};
|
|
170
157
|
CronManager.prototype.stopAllCronJobs = function () {
|
|
@@ -222,7 +209,7 @@ var CronManager = /** @class */ (function () {
|
|
|
222
209
|
return [3 /*break*/, 11];
|
|
223
210
|
case 11:
|
|
224
211
|
if (res.repeat) {
|
|
225
|
-
nextDate = this._cronManager.getJob(res.name).
|
|
212
|
+
nextDate = moment(this._cronManager.getJob(res.name).nextDate()).second(0).millisecond(0).toDate();
|
|
226
213
|
cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } });
|
|
227
214
|
}
|
|
228
215
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAA8D;AAE9D,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAI7C;IAOC,qBAAY,UAAU;QAFd,UAAK,GAAmB,EAAE,CAAC;QAGlC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,EAAE,CAAC;QAEzC,IAAI,CAAC,UAAU,EAAE,CAAC;IACnB,CAAC;IAEY,gCAAU,GAAvB;;;;gBACC,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;oBACnD,8BAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,UAAA,GAAG;wBACvB,KAAI,CAAC,KAAK,GAAG,GAAG,CAAC;wBAEjB,KA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B,wBAAmB;iCAClB,GAAG,CAAC,oBAAoB,EAAxB,wBAAwB;4BAC3B,qBAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,oBAAoB,CAAC,EAAA;;4BAAvG,SAAuG,CAAC;;gCAGxG,qBAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,EAAA;;4BAA7E,SAA6E,CAAC;;;;;4BAKhF,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,KAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;;;4BAGrE,IAAI,GAAG,CAAC,MAAM,EAAE;gCACX,QAAQ,GAAmB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,SAAS,EAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;gCACjH,8BAAQ,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC,EAAE,EAAC,IAAI,EAAE,EAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAC,EAAC,CAAC,CAAC;6BACjF;iCACI;gCACJ,8BAAQ,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC,CAAC,CAAC;6BACnC;;;;;iBAEF,EAAE,cAAO,CAAC,CAAC,CAAC;SACb;IACF,CAAC;IACF,kBAAC;AAAD,CAxMA,AAwMC,IAAA;AAxMY,kCAAW","file":"cron.manager.js","sourcesContent":["import { CronJobModel } from '../models/cron-job.model';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport ResolveIOMainServer from '../server-app';\nlet CronJobManager = require('../cron/cron');\nimport * as moment from 'moment';\nimport { ChangeStream, ChangeStreamDocument } from 'mongodb';\n\nexport class CronManager {\n\n\tprivate _cronManager;\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _watchCrons$: ChangeStream;\n\tprivate _jobs: CronJobModel[] = [];\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._cronManager = new CronJobManager();\n\n\t\tthis.watchCrons();\n\t}\n\n\tpublic async watchCrons() {\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\n\t\t\tCronJobs.find().then(res => {\n\t\t\t\tthis._jobs = res;\n\n\t\t\t\tthis._jobs.forEach(job => {\n\t\t\t\t\tthis.addCronJob(job);\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup'});\n\n\t\t\tthis._watchCrons$.on('change', async (doc: ChangeStreamDocument<CronJobModel>) => {\n\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tif (!this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'replace' || doc.operationType === 'update') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tif (this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1, doc.fullDocument);\n\t\t\t\t\t\t\tthis.updateCronJob(doc.fullDocument);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tlet job = this._jobs.filter(a => a._id === <any>doc.documentKey['_id'])[0];\n\t\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\tif (this._jobs.some(a => a._id === (<any>doc).documentKey['_id'])) {\n\t\t\t\t\t\tlet job = this._jobs.filter(a => a._id === <any>doc.documentKey['_id'])[0];\n\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.on('error', (err) => {\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('end', () => {\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('close', () => {\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._watchCrons$.close();\n\t\t}\n\t}\n\n\tprivate doesCronJobExist(cron: CronJobModel) {\n\t\treturn this._cronManager.exists(cron.name);\n\t}\n\n\tprivate doesCronJobNameExist(cron_name: string) {\n\t\treturn this._cronManager.exists(cron_name);\n\t}\n\n\tprivate addCronJob(cron: CronJobModel) {\n\t\tif (cron.running) {\n\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {running: false}});\n\t\t}\n\t\t\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\tif (cron.timezone) {\n\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet cronOptions = {\n\t\t\t\t\tstart: true,\n\t\t\t\t\t// onComplete: () => {\n\t\t\t\t\t// \tthis.runCronJobCompleted(cron);\n\t\t\t\t\t// },\n\t\t\t\t\t// timeZone: cron.timezone\n\t\t\t\t};\n\n\t\t\t\tif (cron.timezone) {\n\t\t\t\t\tcronOptions['timeZone'] = cron.timezone;\n\t\t\t\t}\n\n\t\t\t\tthis._cronManager.add(\n\t\t\t\t\tcron.name,\n\t\t\t\t\tcron.time_to_run,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.runCronJob(cron);\n\t\t\t\t\t},\n\t\t\t\t\tcronOptions\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.update(cron.name, cron.time_to_run);\n\t\t}\n\t}\n\n\tprivate removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tthis._cronManager.deleteJob(cron_name);\n\t\t}\n\t}\n\n\tprivate startCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopAllCronJobs() {\n\t\tthis._cronManager.stopAll();\n\t}\n\n\tprivate runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tif (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {\n\n\t\t\tCronJobs.findOneAndUpdate({\n\t\t\t\t$and: [\n\t\t\t\t\t{_id: cron._id},\n\t\t\t\t\t{running: false},\n\t\t\t\t\t{\n\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Cron Error', JSON.stringify(err, null, 2));\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = (<moment.Moment>this._cronManager.getJob(res.name).nextDates()).second(0).millisecond(0).toDate();\n\t\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAA8D;AAE9D,qCAA8C;AAC9C,+BAAiC;AAGjC;IAMC,qBAAY,UAAU;QAFd,UAAK,GAAmB,EAAE,CAAC;QAGlC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY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job.model';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport ResolveIOMainServer from '../server-app';\nimport { CronJobManager } from '../cron/cron';\nimport * as moment from 'moment';\nimport { ChangeStream, ChangeStreamDocument } from 'mongodb';\n\nexport class CronManager {\n\tprivate _cronManager: CronJobManager;\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _watchCrons$: ChangeStream;\n\tprivate _jobs: CronJobModel[] = [];\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._cronManager = new CronJobManager();\n\n\t\tthis.watchCrons();\n\t}\n\n\tpublic async watchCrons() {\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\n\t\t\tCronJobs.find().then(res => {\n\t\t\t\tthis._jobs = res;\n\n\t\t\t\tthis._jobs.forEach(job => {\n\t\t\t\t\tthis.addCronJob(job);\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup'});\n\n\t\t\tthis._watchCrons$.on('change', async (doc: ChangeStreamDocument<CronJobModel>) => {\n\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tif (!this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'replace' || doc.operationType === 'update') {\n\t\t\t\t\tif (doc.fullDocument) {\n\t\t\t\t\t\tif (this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1, doc.fullDocument);\n\t\t\t\t\t\t\tthis.updateCronJob(doc.fullDocument);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._jobs.push(doc.fullDocument);\n\t\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tif (this._jobs.some(a => a._id === <any>doc.documentKey['_id'])) {\n\t\t\t\t\t\t\tlet job = this._jobs.filter(a => a._id === <any>doc.documentKey['_id'])[0];\n\t\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\tif (this._jobs.some(a => a._id === (<any>doc).documentKey['_id'])) {\n\t\t\t\t\t\tlet job = this._jobs.filter(a => a._id === <any>doc.documentKey['_id'])[0];\n\t\t\t\t\t\tthis.removeCronJob(job.name);\n\t\t\t\t\t\tthis._jobs.splice(this._jobs.map(a => a._id).indexOf(<any>doc.documentKey['_id']), 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\t.on('error', (err) => {\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('end', () => {\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('close', () => {\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._watchCrons$.close();\n\t\t}\n\t}\n\n\tprivate doesCronJobExist(cron: CronJobModel) {\n\t\treturn this._cronManager.exists(cron.name);\n\t}\n\n\tprivate doesCronJobNameExist(cron_name: string) {\n\t\treturn this._cronManager.exists(cron_name);\n\t}\n\n\tprivate addCronJob(cron: CronJobModel) {\n\t\tif (cron.running) {\n\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {running: false}});\n\t\t}\n\t\t\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.add(\n\t\t\t\tcron.name,\n\t\t\t\tcron.time_to_run,\n\t\t\t\t() => {\n\t\t\t\t\tthis.runCronJob(cron);\n\t\t\t\t},\n\t\t\t\tnull,\n\t\t\t\ttrue,\n\t\t\t\tcron.timezone,\n\t\t\t\tnull, \n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.update(cron.name, cron.time_to_run);\n\t\t}\n\t}\n\n\tprivate removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tthis._cronManager.delete(cron_name);\n\t\t}\n\t}\n\n\tprivate startCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.stop(cron.name);\n\t\t}\n\t}\n\n\tprivate stopAllCronJobs() {\n\t\tthis._cronManager.stopAll();\n\t}\n\n\tprivate runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tif (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {\n\n\t\t\tCronJobs.findOneAndUpdate({\n\t\t\t\t$and: [\n\t\t\t\t\t{_id: cron._id},\n\t\t\t\t\t{running: false},\n\t\t\t\t\t{\n\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Cron Error', JSON.stringify(err, null, 2));\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = moment(this._cronManager.getJob(res.name).nextDate()).second(0).millisecond(0).toDate();\n\t\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@resolveio/server-lib",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"package": "npm run build-prod && npm pack ./dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"axios": "1.5.1",
|
|
17
17
|
"body-parser": "1.20.2",
|
|
18
18
|
"clone": "2.1.2",
|
|
19
|
-
"cron": "1.
|
|
19
|
+
"cron": "3.1.4",
|
|
20
20
|
"crypto": "1.0.1",
|
|
21
21
|
"deep-diff": "1.0.2",
|
|
22
22
|
"deep-object-diff": "1.1.9",
|