@resolveio/server-lib 12.0.44 → 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.
@@ -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
- private loadCronJobs;
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
  }
@@ -41,24 +41,95 @@ var cron_job_collection_1 = require("../collections/cron-job.collection");
41
41
  var CronJobManager = require('../cron/cron');
42
42
  var CronManager = /** @class */ (function () {
43
43
  function CronManager(mainServer) {
44
+ this._jobs = [];
44
45
  this._mainServer = mainServer;
45
46
  this._cronManager = new CronJobManager();
46
- this.loadCronJobs();
47
+ this.watchCrons();
47
48
  }
48
- CronManager.prototype.loadCronJobs = function () {
49
+ CronManager.prototype.watchCrons = function (resumeToken) {
49
50
  return __awaiter(this, void 0, void 0, function () {
50
- var jobs;
51
+ var lastResumeToken_1;
51
52
  var _this = this;
52
53
  return __generator(this, function (_a) {
53
- switch (_a.label) {
54
- case 0: return [4 /*yield*/, cron_job_collection_1.CronJobs.find({})];
55
- case 1:
56
- jobs = _a.sent();
57
- 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) {
58
58
  _this.addCronJob(job);
59
59
  });
60
- return [2 /*return*/];
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
+ });
61
128
  }
129
+ else {
130
+ this._watchCrons$.close();
131
+ }
132
+ return [2 /*return*/];
62
133
  });
63
134
  });
64
135
  };
@@ -112,34 +183,6 @@ var CronManager = /** @class */ (function () {
112
183
  CronManager.prototype.stopAllCronJobs = function () {
113
184
  this._cronManager.stopAll();
114
185
  };
115
- CronManager.prototype.checkCronJobsForUpdates = function () {
116
- return __awaiter(this, void 0, void 0, function () {
117
- var jobs;
118
- var _this = this;
119
- return __generator(this, function (_a) {
120
- switch (_a.label) {
121
- case 0: return [4 /*yield*/, cron_job_collection_1.CronJobs.find({})];
122
- case 1:
123
- jobs = _a.sent();
124
- // Remove deleted cron jobs
125
- this._cronManager.getJobs().forEach(function (cronJob) {
126
- if (jobs.map(function (a) { return a.name; }).indexOf(cronJob) === -1) {
127
- _this.removeCronJob(cronJob);
128
- }
129
- });
130
- // Add new cron jobs
131
- jobs.forEach(function (cronJob) {
132
- _this.addCronJob(cronJob);
133
- });
134
- // Update cronjobs
135
- jobs.forEach(function (cronJob) {
136
- _this.updateCronJob(cronJob);
137
- });
138
- return [2 /*return*/];
139
- }
140
- });
141
- });
142
- };
143
186
  CronManager.prototype.runCronJob = function (cron) {
144
187
  var _this = this;
145
188
  var now = new Date();
@@ -157,7 +200,7 @@ var CronManager = /** @class */ (function () {
157
200
  }
158
201
  ]
159
202
  }, { $set: { running: true } }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
160
- var nextDate, nextDate2;
203
+ var nextDate;
161
204
  return __generator(this, function (_a) {
162
205
  switch (_a.label) {
163
206
  case 0:
@@ -185,16 +228,7 @@ var CronManager = /** @class */ (function () {
185
228
  case 8:
186
229
  if (res.repeat) {
187
230
  nextDate = this._cronManager.getJob(res.name).nextDates().second(0).millisecond(0).toDate();
188
- nextDate2 = this._cronManager.getJob(res.name).nextDate().second(0).millisecond(0).toDate();
189
- if (res.name === 'QB Pull Data') {
190
- console.log(new Date(), 'QB Pull Data, Next Run', nextDate, nextDate2);
191
- }
192
- cron_job_collection_1.CronJobs.updateOne({
193
- $and: [
194
- { _id: res._id },
195
- { running: true }
196
- ]
197
- }, { $set: { running: false, next_run: nextDate || nextDate2 } });
231
+ cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } });
198
232
  }
199
233
  else {
200
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;AAG7C;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;IAEO,sCAAgB,GAAxB,UAAyB,IAAkB;QAC1C,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAEO,0CAAoB,GAA5B,UAA6B,SAAiB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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;gCAC7G,SAAS,GAAmB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;gCAEjH,IAAI,GAAG,CAAC,IAAI,KAAK,cAAc,EAAE;oCAChC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,wBAAwB,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;iCACvE;gCAED,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,SAAS,EAAC,EAAC,CAAC,CAAC;6BAC9D;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,CAxKA,AAwKC,IAAA;AAxKY,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\t\t\t\t\t\tlet nextDate2 = (<moment.Moment>this._cronManager.getJob(res.name).nextDate()).second(0).millisecond(0).toDate();\n\n\t\t\t\t\t\tif (res.name === 'QB Pull Data') {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'QB Pull Data, Next Run', nextDate, nextDate2);\n\t\t\t\t\t\t}\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 || nextDate2}});\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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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,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}"]}
@@ -1608,9 +1608,6 @@ var MongoManagerCollection = /** @class */ (function () {
1608
1608
  resolve(1);
1609
1609
  return [2 /*return*/];
1610
1610
  }
1611
- if (this.collectionName === 'cron-jobs') {
1612
- console.log(new Date(), 'Update Cron Job', filter, update, options, bypassLogs, bypassCheckSchema);
1613
- }
1614
1611
  date = new Date();
1615
1612
  if (this.timestamps) {
1616
1613
  if (!update.$set) {