@resolveio/server-lib 12.0.43 → 12.0.45
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/managers/cron.manager.d.ts +4 -2
- package/managers/cron.manager.js +82 -46
- package/managers/cron.manager.js.map +1 -1
- package/managers/mongo.manager.js +8 -0
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.js +1 -10
- package/managers/subscription.manager.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { ResumeToken } from 'mongodb';
|
|
1
2
|
export declare class CronManager {
|
|
2
3
|
private _cronManager;
|
|
3
4
|
private _mainServer;
|
|
5
|
+
private _watchCrons$;
|
|
6
|
+
private _jobs;
|
|
4
7
|
constructor(mainServer: any);
|
|
5
|
-
|
|
8
|
+
watchCrons(resumeToken?: ResumeToken): Promise<void>;
|
|
6
9
|
private doesCronJobExist;
|
|
7
10
|
private doesCronJobNameExist;
|
|
8
11
|
private addCronJob;
|
|
@@ -11,6 +14,5 @@ export declare class CronManager {
|
|
|
11
14
|
private startCronJob;
|
|
12
15
|
private stopCronJob;
|
|
13
16
|
private stopAllCronJobs;
|
|
14
|
-
checkCronJobsForUpdates(): Promise<void>;
|
|
15
17
|
private runCronJob;
|
|
16
18
|
}
|
package/managers/cron.manager.js
CHANGED
|
@@ -39,27 +39,97 @@ 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
41
|
var CronJobManager = require('../cron/cron');
|
|
42
|
-
var moment = require("moment");
|
|
43
42
|
var CronManager = /** @class */ (function () {
|
|
44
43
|
function CronManager(mainServer) {
|
|
44
|
+
this._jobs = [];
|
|
45
45
|
this._mainServer = mainServer;
|
|
46
46
|
this._cronManager = new CronJobManager();
|
|
47
|
-
this.
|
|
47
|
+
this.watchCrons();
|
|
48
48
|
}
|
|
49
|
-
CronManager.prototype.
|
|
49
|
+
CronManager.prototype.watchCrons = function (resumeToken) {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var
|
|
51
|
+
var lastResumeToken_1;
|
|
52
52
|
var _this = this;
|
|
53
53
|
return __generator(this, function (_a) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
jobs.forEach(function (job) {
|
|
54
|
+
if (!this._watchCrons$ || this._watchCrons$.closed) {
|
|
55
|
+
cron_job_collection_1.CronJobs.find().then(function (res) {
|
|
56
|
+
_this._jobs = res;
|
|
57
|
+
_this._jobs.forEach(function (job) {
|
|
59
58
|
_this.addCronJob(job);
|
|
60
59
|
});
|
|
61
|
-
|
|
60
|
+
});
|
|
61
|
+
if (resumeToken) {
|
|
62
|
+
lastResumeToken_1 = resumeToken;
|
|
63
|
+
try {
|
|
64
|
+
this._watchCrons$ = cron_job_collection_1.CronJobs.watchCollection([], { fullDocument: 'updateLookup', resumeAfter: resumeToken });
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
if (this._watchCrons$ && !this._watchCrons$.closed) {
|
|
68
|
+
this._watchCrons$.close();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this._watchCrons$ = cron_job_collection_1.CronJobs.watchCollection([], { fullDocument: 'updateLookup' });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
this._watchCrons$ = cron_job_collection_1.CronJobs.watchCollection([], { fullDocument: 'updateLookup' });
|
|
77
|
+
}
|
|
78
|
+
;
|
|
79
|
+
this._watchCrons$.on('change', function (doc) { return __awaiter(_this, void 0, void 0, function () {
|
|
80
|
+
var job, job;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
if (doc.operationType === 'insert') {
|
|
83
|
+
if (doc.fullDocument) {
|
|
84
|
+
this._jobs.push(doc.fullDocument);
|
|
85
|
+
this.addCronJob(doc.fullDocument);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (doc.operationType === 'replace' || doc.operationType === 'update') {
|
|
89
|
+
if (doc.fullDocument) {
|
|
90
|
+
if (this._jobs.some(function (a) { return a._id === doc.documentKey['_id']; })) {
|
|
91
|
+
this._jobs.splice(this._jobs.map(function (a) { return a._id; }).indexOf(doc.documentKey['_id']), 1, doc.fullDocument);
|
|
92
|
+
this.updateCronJob(doc.fullDocument);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this._jobs.push(doc.fullDocument);
|
|
96
|
+
this.addCronJob(doc.fullDocument);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (this._jobs.some(function (a) { return a._id === doc.documentKey['_id']; })) {
|
|
101
|
+
job = this._jobs.filter(function (a) { return a._id === doc.documentKey['_id']; })[0];
|
|
102
|
+
this.removeCronJob(job.name);
|
|
103
|
+
this._jobs.splice(this._jobs.map(function (a) { return a._id; }).indexOf(doc.documentKey['_id']), 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (this._jobs.some(function (a) { return a._id === doc.documentKey['_id']; })) {
|
|
109
|
+
job = this._jobs.filter(function (a) { return a._id === doc.documentKey['_id']; })[0];
|
|
110
|
+
this.removeCronJob(job.name);
|
|
111
|
+
this._jobs.splice(this._jobs.map(function (a) { return a._id; }).indexOf(doc.documentKey['_id']), 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
lastResumeToken_1 = doc._id;
|
|
115
|
+
return [2 /*return*/];
|
|
116
|
+
});
|
|
117
|
+
}); })
|
|
118
|
+
.on('error', function (err) {
|
|
119
|
+
_this._watchCrons$.close();
|
|
120
|
+
})
|
|
121
|
+
.on('end', function () {
|
|
122
|
+
_this._watchCrons$.close();
|
|
123
|
+
})
|
|
124
|
+
.on('close', function () {
|
|
125
|
+
_this._watchCrons$ = null;
|
|
126
|
+
_this.watchCrons(lastResumeToken_1);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this._watchCrons$.close();
|
|
62
131
|
}
|
|
132
|
+
return [2 /*return*/];
|
|
63
133
|
});
|
|
64
134
|
});
|
|
65
135
|
};
|
|
@@ -113,34 +183,6 @@ var CronManager = /** @class */ (function () {
|
|
|
113
183
|
CronManager.prototype.stopAllCronJobs = function () {
|
|
114
184
|
this._cronManager.stopAll();
|
|
115
185
|
};
|
|
116
|
-
CronManager.prototype.checkCronJobsForUpdates = function () {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
var jobs;
|
|
119
|
-
var _this = this;
|
|
120
|
-
return __generator(this, function (_a) {
|
|
121
|
-
switch (_a.label) {
|
|
122
|
-
case 0: return [4 /*yield*/, cron_job_collection_1.CronJobs.find({})];
|
|
123
|
-
case 1:
|
|
124
|
-
jobs = _a.sent();
|
|
125
|
-
// Remove deleted cron jobs
|
|
126
|
-
this._cronManager.getJobs().forEach(function (cronJob) {
|
|
127
|
-
if (jobs.map(function (a) { return a.name; }).indexOf(cronJob) === -1) {
|
|
128
|
-
_this.removeCronJob(cronJob);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
// Add new cron jobs
|
|
132
|
-
jobs.forEach(function (cronJob) {
|
|
133
|
-
_this.addCronJob(cronJob);
|
|
134
|
-
});
|
|
135
|
-
// Update cronjobs
|
|
136
|
-
jobs.forEach(function (cronJob) {
|
|
137
|
-
_this.updateCronJob(cronJob);
|
|
138
|
-
});
|
|
139
|
-
return [2 /*return*/];
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
186
|
CronManager.prototype.runCronJob = function (cron) {
|
|
145
187
|
var _this = this;
|
|
146
188
|
var now = new Date();
|
|
@@ -158,7 +200,7 @@ var CronManager = /** @class */ (function () {
|
|
|
158
200
|
}
|
|
159
201
|
]
|
|
160
202
|
}, { $set: { running: true } }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
161
|
-
var nextDate
|
|
203
|
+
var nextDate;
|
|
162
204
|
return __generator(this, function (_a) {
|
|
163
205
|
switch (_a.label) {
|
|
164
206
|
case 0:
|
|
@@ -186,13 +228,7 @@ var CronManager = /** @class */ (function () {
|
|
|
186
228
|
case 8:
|
|
187
229
|
if (res.repeat) {
|
|
188
230
|
nextDate = this._cronManager.getJob(res.name).nextDates().second(0).millisecond(0).toDate();
|
|
189
|
-
|
|
190
|
-
cron_job_collection_1.CronJobs.updateOne({
|
|
191
|
-
$and: [
|
|
192
|
-
{ _id: res._id },
|
|
193
|
-
{ running: true }
|
|
194
|
-
]
|
|
195
|
-
}, { $set: { running: false, next_run: nextDate || oneMin } });
|
|
231
|
+
cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } });
|
|
196
232
|
}
|
|
197
233
|
else {
|
|
198
234
|
cron_job_collection_1.CronJobs.deleteOne({ _id: res._id });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAA8D;AAE9D,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC7C,+BAAiC;AAEjC;IAKC,qBAAY,UAAU;QACrB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAEa,kCAAY,GAA1B;;;;;;4BACY,qBAAM,8BAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAA;;wBAA9B,IAAI,GAAG,SAAuB;wBAElC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;4BACf,KAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;wBACtB,CAAC,CAAC,CAAC;;;;;KACH;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BAAoB,CAAC,EAAA;;4BAAvG,SAAuG,CAAC;;gCAGxG,qBAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,EAAA;;4BAA7E,SAA6E,CAAC;;;4BAIhF,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;gCAE7G,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;gCAElE,8BAAQ,CAAC,SAAS,CAAC;oCAClB,IAAI,EAAE;wCACL,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC;wCACd,EAAC,OAAO,EAAE,IAAI,EAAC;qCACf;iCACD,EAAE,EAAC,IAAI,EAAE,EAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,IAAI,MAAM,EAAC,EAAC,CAAC,CAAC;6BAC3D;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,CArKA,AAqKC,IAAA;AArKY,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';\n\nexport class CronManager {\n\n\tprivate _cronManager;\n\tprivate _mainServer: ResolveIOMainServer;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tthis._cronManager = new CronJobManager();\n\t\tthis.loadCronJobs();\n\t}\n\n\tprivate async loadCronJobs() {\n\t\tlet jobs = await CronJobs.find({});\n\n\t\tjobs.forEach(job => {\n\t\t\tthis.addCronJob(job);\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\tpublic async checkCronJobsForUpdates() {\n\t\tlet jobs = await CronJobs.find({});\n\n\t\t// Remove deleted cron jobs\n\t\tthis._cronManager.getJobs().forEach(cronJob => {\n\t\t\tif (jobs.map(a => a.name).indexOf(cronJob) === -1) {\n\t\t\t\tthis.removeCronJob(cronJob);\n\t\t\t}\n\t\t});\n\n\t\t// Add new cron jobs\n\t\tjobs.forEach(cronJob => {\n\t\t\tthis.addCronJob(cronJob);\n\t\t});\n\n\t\t// Update cronjobs\n\t\tjobs.forEach(cronJob => {\n\t\t\tthis.updateCronJob(cronJob);\n\t\t});\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\tif (res.method_run_data) {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\tif (res.method_complete_data) {\n\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}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\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\n\t\t\t\t\t\tlet oneMin = moment().startOf('minute').add(1, 'minute').toDate();\n\n\t\t\t\t\t\tCronJobs.updateOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: res._id},\n\t\t\t\t\t\t\t\t{running: true}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}, {$set: {running: false, next_run: nextDate || oneMin}});\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,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,UAAwB,WAAyB;;;;;gBAChD,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;oBAGnD,8BAAQ,CAAC,IAAI,EAAE,CAAC,IA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;;;;;iBAEF,EAAE,cAAO,CAAC,CAAC,CAAC;SACb;IACF,CAAC;IACF,kBAAC;AAAD,CApNA,AAoNC,IAAA;AApNY,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, ResumeToken } 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(resumeToken?: ResumeToken) {\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\n\t\t\tlet lastResumeToken: ResumeToken;\n\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\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup', resumeAfter: resumeToken});\n\t\t\t\t}\n\t\t\t\tcatch(err) {\n\t\t\t\t\tif (this._watchCrons$ && !this._watchCrons$.closed) {\n\t\t\t\t\t\tthis._watchCrons$.close();\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup'});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._watchCrons$ = CronJobs.watchCollection([], {fullDocument: 'updateLookup'});\n\t\t\t};\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\tthis._jobs.push(doc.fullDocument);\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 {\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\n\t\t\t\tlastResumeToken = doc._id;\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(lastResumeToken);\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\tif (res.method_run_data) {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\tif (res.method_complete_data) {\n\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}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\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}"]}
|
|
@@ -1502,6 +1502,10 @@ var MongoManagerCollection = /** @class */ (function () {
|
|
|
1502
1502
|
return __generator(this, function (_a) {
|
|
1503
1503
|
switch (_a.label) {
|
|
1504
1504
|
case 0:
|
|
1505
|
+
if ((!update.$inc || update.$inc === {}) && (!update.$set || update.$set === {}) && (!update.$setOnInsert || update.$setOnInsert === {}) && (!update.$unset || update.$unset === {})) {
|
|
1506
|
+
resolve(1);
|
|
1507
|
+
return [2 /*return*/];
|
|
1508
|
+
}
|
|
1505
1509
|
if (this.timestamps) {
|
|
1506
1510
|
date = new Date();
|
|
1507
1511
|
if (!update.$set) {
|
|
@@ -1600,6 +1604,10 @@ var MongoManagerCollection = /** @class */ (function () {
|
|
|
1600
1604
|
return [2 /*return*/];
|
|
1601
1605
|
}
|
|
1602
1606
|
}
|
|
1607
|
+
if ((!update.$inc || update.$inc === {}) && (!update.$set || update.$set === {}) && (!update.$setOnInsert || update.$setOnInsert === {}) && (!update.$unset || update.$unset === {})) {
|
|
1608
|
+
resolve(1);
|
|
1609
|
+
return [2 /*return*/];
|
|
1610
|
+
}
|
|
1603
1611
|
date = new Date();
|
|
1604
1612
|
if (this.timestamps) {
|
|
1605
1613
|
if (!update.$set) {
|