@resolveio/server-lib 12.8.4 → 20.0.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/fixtures/cron-jobs.js +1 -1
- package/fixtures/cron-jobs.js.map +1 -1
- package/managers/cron.manager.js +49 -21
- package/managers/cron.manager.js.map +1 -1
- package/methods/logs.js +18 -18
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +36 -36
- package/methods/monitor.js.map +1 -1
- package/methods/report-builder.js +25 -25
- package/methods/report-builder.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +1 -0
- package/server-app.js +13 -4
- package/server-app.js.map +1 -1
package/fixtures/cron-jobs.js
CHANGED
|
@@ -58,7 +58,7 @@ function loadServerCronJobs() {
|
|
|
58
58
|
method_run_data: null,
|
|
59
59
|
next_run: new Date(),
|
|
60
60
|
running: false,
|
|
61
|
-
timezone: 'America/Chicago'
|
|
61
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
if (cronJobs.some(function (a) { return a.running; })) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fixtures/cron-jobs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0EAA8D;AAC9D,2DAA8D;AAE9D,SAAsB,kBAAkB;;;;;wBAExB,qBAAM,8BAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAA;;oBAAlC,QAAQ,GAAG,SAAuB;oBAEtC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,KAAK,2BAA2B,EAAtC,CAAsC,CAAC,EAAE;wBAChE,8BAAQ,CAAC,MAAM,CAAC;4BACf,GAAG,EAAE,IAAA,iCAAiB,GAAE;4BACxB,GAAG,EAAE,CAAC;4BACN,IAAI,EAAG,2BAA2B;4BAClC,MA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.js","sourcesContent":["import { CronJobs } from '../collections/cron-job.collection';\nimport { objectIdHexString } from '../managers/mongo.manager';\n\nexport async function loadServerCronJobs() {\n\n\tlet cronJobs = await CronJobs.find({});\n\n\tif (!cronJobs.some(a => a.name === 'Email Merged Docs Cleanup')) {\n\t\tCronJobs.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tname : 'Email Merged Docs Cleanup', \n\t\t\trepeat : true, \n\t\t\ttime_to_run : '0 0 * * *', \n\t\t\tmethod_run : 'cronEmailMergedDocsCleanUp', \n\t\t\tmethod_run_data : null, \n\t\t\tnext_run : new Date(), \n\t\t\trunning : false,\n\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t});\n\t}\n\n\tif (cronJobs.some(a => a.running)) {\n\t\tCronJobs.updateMany({running: true}, {$set: {running: false}});\n\t}\n}"]}
|
package/managers/cron.manager.js
CHANGED
|
@@ -153,10 +153,18 @@ var CronManager = /** @class */ (function () {
|
|
|
153
153
|
CronManager.prototype.addCronJob = function (cron) {
|
|
154
154
|
var _this = this;
|
|
155
155
|
if (!this.doesCronJobExist(cron)) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
try {
|
|
157
|
+
this._cronManager.add(cron.name, cron.time_to_run, function () { return _this.runCronJob(cron); }, null, true, cron.timezone, null, false);
|
|
158
|
+
var nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);
|
|
159
|
+
if (cron.running || (nextDate && !cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {
|
|
160
|
+
cron_job_collection_1.CronJobs.updateOne({ _id: cron._id }, { $set: { running: false, next_run: nextDate || null } });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
console.log('Cron error', e);
|
|
165
|
+
if (cron.time_to_run instanceof Date) {
|
|
166
|
+
this.runCronJob(cron);
|
|
167
|
+
}
|
|
160
168
|
}
|
|
161
169
|
}
|
|
162
170
|
};
|
|
@@ -204,12 +212,13 @@ var CronManager = /** @class */ (function () {
|
|
|
204
212
|
}
|
|
205
213
|
]
|
|
206
214
|
}, { $set: { running: true } }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
207
|
-
var
|
|
215
|
+
var cronHistory_1, timeoutHandle, err_1, nextDate, nextDate;
|
|
216
|
+
var _this = this;
|
|
208
217
|
return __generator(this, function (_a) {
|
|
209
218
|
switch (_a.label) {
|
|
210
219
|
case 0:
|
|
211
|
-
if (!res) return [3 /*break*/,
|
|
212
|
-
|
|
220
|
+
if (!res) return [3 /*break*/, 14];
|
|
221
|
+
cronHistory_1 = {
|
|
213
222
|
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
214
223
|
name: res.name,
|
|
215
224
|
reoccuring: res.repeat,
|
|
@@ -224,12 +233,27 @@ var CronManager = /** @class */ (function () {
|
|
|
224
233
|
date_end: null,
|
|
225
234
|
date_next: null
|
|
226
235
|
};
|
|
227
|
-
return [4 /*yield*/, cron_job_history_collection_1.CronJobHistories.create(
|
|
236
|
+
return [4 /*yield*/, cron_job_history_collection_1.CronJobHistories.create(cronHistory_1)];
|
|
228
237
|
case 1:
|
|
229
238
|
_a.sent();
|
|
239
|
+
timeoutHandle = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
240
|
+
var nextDate;
|
|
241
|
+
return __generator(this, function (_a) {
|
|
242
|
+
console.log(new Date(), 'Cron Timeout', JSON.stringify(cron, null, 2));
|
|
243
|
+
if (res.repeat) {
|
|
244
|
+
nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);
|
|
245
|
+
cronHistory_1.date_next = nextDate;
|
|
246
|
+
cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } });
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
cron_job_collection_1.CronJobs.deleteOne({ _id: res._id });
|
|
250
|
+
}
|
|
251
|
+
return [2 /*return*/];
|
|
252
|
+
});
|
|
253
|
+
}); }, 5 * 60 * 1000);
|
|
230
254
|
_a.label = 2;
|
|
231
255
|
case 2:
|
|
232
|
-
_a.trys.push([2, 11, ,
|
|
256
|
+
_a.trys.push([2, 11, 12, 13]);
|
|
233
257
|
if (!res.method_run_data) return [3 /*break*/, 4];
|
|
234
258
|
return [4 /*yield*/, this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data)];
|
|
235
259
|
case 3:
|
|
@@ -250,39 +274,43 @@ var CronManager = /** @class */ (function () {
|
|
|
250
274
|
case 9:
|
|
251
275
|
_a.sent();
|
|
252
276
|
_a.label = 10;
|
|
253
|
-
case 10: return [3 /*break*/,
|
|
277
|
+
case 10: return [3 /*break*/, 13];
|
|
254
278
|
case 11:
|
|
255
279
|
err_1 = _a.sent();
|
|
256
280
|
console.log(new Date(), 'Cron Error', JSON.stringify(err_1, null, 2));
|
|
257
|
-
|
|
258
|
-
|
|
281
|
+
cronHistory_1.error = JSON.stringify(err_1, null, 2);
|
|
282
|
+
cronHistory_1.passed = false;
|
|
259
283
|
if (res.repeat) {
|
|
260
284
|
nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);
|
|
261
|
-
|
|
285
|
+
cronHistory_1.date_next = nextDate;
|
|
262
286
|
cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } });
|
|
263
287
|
}
|
|
264
288
|
else {
|
|
265
289
|
cron_job_collection_1.CronJobs.deleteOne({ _id: res._id });
|
|
266
290
|
}
|
|
267
|
-
return [3 /*break*/,
|
|
291
|
+
return [3 /*break*/, 13];
|
|
268
292
|
case 12:
|
|
293
|
+
// Clear the timeout if the job completes or fails before the timeout
|
|
294
|
+
clearTimeout(timeoutHandle);
|
|
295
|
+
return [7 /*endfinally*/];
|
|
296
|
+
case 13:
|
|
269
297
|
if (res.repeat) {
|
|
270
298
|
nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);
|
|
271
|
-
|
|
299
|
+
cronHistory_1.date_next = nextDate;
|
|
272
300
|
cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } });
|
|
273
301
|
}
|
|
274
302
|
else {
|
|
275
303
|
cron_job_collection_1.CronJobs.deleteOne({ _id: res._id });
|
|
276
304
|
}
|
|
277
|
-
cron_job_history_collection_1.CronJobHistories.updateOne({ _id:
|
|
305
|
+
cron_job_history_collection_1.CronJobHistories.updateOne({ _id: cronHistory_1._id }, { $set: {
|
|
278
306
|
server_restart: false,
|
|
279
|
-
passed:
|
|
280
|
-
error:
|
|
307
|
+
passed: cronHistory_1.passed,
|
|
308
|
+
error: cronHistory_1.error,
|
|
281
309
|
date_end: new Date(),
|
|
282
|
-
date_next:
|
|
310
|
+
date_next: cronHistory_1.date_next
|
|
283
311
|
} });
|
|
284
|
-
_a.label =
|
|
285
|
-
case
|
|
312
|
+
_a.label = 14;
|
|
313
|
+
case 14: return [2 /*return*/];
|
|
286
314
|
}
|
|
287
315
|
});
|
|
288
316
|
}); }, function () { });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAA8D;AAE9D,qCAA8C;AAG9C,0FAA8E;AAC9E,2DAA8D;AAG9D;IAMC,qBAAY,UAAU;QAFd,UAAK,GAAmB,EAAE,CAAC;QAGlC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAc,EAAE,CAAC;QAEzC,IAAI,CAAC,UAAU,EAAE,CAAC;IACnB,CAAC;IAEY,gCAAU,GAAvB;;;;;;wBACC,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;4BACnD,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,CAAC;4BACvC,IAAI,CAAC,YAAY,CAAC,KAAK,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AAS,GAAG,QAAQ,CAAC;4BACjC,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;yBACjF;6BACI;4BACJ,8BAAQ,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC,CAAC,CAAC;yBACnC;wBAED,8CAAgB,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,WAAW,CAAC,GAAG,EAAC,EAAE,EAAC,IAAI,EAAE;gCACzD,cAAc,EAAE,KAAK;gCACrB,MAAM,EAAE,WAAW,CAAC,MAAM;gCAC1B,KAAK,EAAE,WAAW,CAAC,KAAK;gCACxB,QAAQ,EAAE,IAAI,IAAI,EAAE;gCACpB,SAAS,EAAE,WAAW,CAAC,SAAS;6BAChC,EAAC,CAAC,CAAC;;;;;aAEL,EAAE,cAAO,CAAC,CAAC,CAAC;IACd,CAAC;IACF,kBAAC;AAAD,CA7PA,AA6PC,IAAA;AA7PY,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';\nimport { CronJobManager } from '../cron/cron';\nimport * as moment from 'moment-timezone';\nimport { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { objectIdHexString } from '../managers/mongo.manager';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\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\tthis._watchCrons$.removeAllListeners();\n\t\t\tthis._watchCrons$.close();\n\t\t\tthis._watchCrons$ = null;\n\t\t}\n\t\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\t\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\t\t\t\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\tif (job.running) {\n\t\t\t\t\t\tCronJobs.updateOne({_id: job._id}, {$set: {running: false}});\n\t\t\t\t\t}\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\tlet oldDoc = this._jobs.filter(a => a._id === <any>doc.documentKey['_id'])[0];\n\t\t\t\t\t\tif (oldDoc) {\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\n\t\t\t\t\t\t\tif (oldDoc.name !== doc.fullDocument.name) {\n\t\t\t\t\t\t\t\tthis.removeCronJob(oldDoc.name);\n\t\t\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (oldDoc.time_to_run !== doc.fullDocument.time_to_run || \n\t\t\t\t\t\t\t\toldDoc.timezone !== doc.fullDocument.timezone\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthis.updateCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\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$.removeAllListeners();\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t})\n\t\t\t.on('end', () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t})\n\t\t\t.on('close', () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t});\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 (!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() => this.runCronJob(cron),\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\n\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\tif (cron.running || (nextDate && !cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {running: false, next_run: nextDate || null}});\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, () => this.runCronJob(cron), null, true, cron.timezone);\n\n\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\tif (nextDate && (!cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {next_run: nextDate}});\n\t\t\t}\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\tCronJobs.findOneAndUpdate({\n\t\t\t$and: [\n\t\t\t\t{_id: cron._id},\n\t\t\t\t{running: false},\n\t\t\t\t{\n\t\t\t\t\t$or: [\n\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\tif (res) {\n\t\t\t\tlet cronHistory: CronJobHistoryModel = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tname: res.name,\n\t\t\t\t\treoccuring: res.repeat,\n\t\t\t\t\ttime_to_run: res.time_to_run,\n\t\t\t\t\tmethod_name: res.method_run,\n\t\t\t\t\tid_cronjob: res._id,\n\t\t\t\t\tserver_restart: true,\n\t\t\t\t\tpassed: true,\n\t\t\t\t\terror: '',\n\t\t\t\t\tdate_scheduled: res.next_run,\n\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\tdate_end: null,\n\t\t\t\t\tdate_next: null\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tawait CronJobHistories.create(cronHistory);\n\n\t\t\t\ttry {\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\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\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\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tconsole.log(new Date(), 'Cron Error', JSON.stringify(err, null, 2));\n\t\t\t\t\tcronHistory.error = JSON.stringify(err, null, 2);\n\t\t\t\t\tcronHistory.passed = false;\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\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\n\t\t\t\tif (res.repeat) {\n\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t} \n\t\t\t\telse {\n\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\n\t\t\t\tCronJobHistories.updateOne({_id: cronHistory._id}, {$set: {\n\t\t\t\t\tserver_restart: false,\n\t\t\t\t\tpassed: cronHistory.passed,\n\t\t\t\t\terror: cronHistory.error,\n\t\t\t\t\tdate_end: new Date(),\n\t\t\t\t\tdate_next: cronHistory.date_next\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,q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CAAC,CAAC;;;wBAG7B,IAAI,GAAG,CAAC,MAAM,EAAE;4BACX,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;4BAC7E,aAAW,CAAC,SAAS,GAAG,QAAQ,CAAC;4BACjC,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;yBACjF;6BACI;4BACJ,8BAAQ,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC,CAAC,CAAC;yBACnC;wBAED,8CAAgB,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,aAAW,CAAC,GAAG,EAAC,EAAE,EAAC,IAAI,EAAE;gCACzD,cAAc,EAAE,KAAK;gCACrB,MAAM,EAAE,aAAW,CAAC,MAAM;gCAC1B,KAAK,EAAE,aAAW,CAAC,KAAK;gCACxB,QAAQ,EAAE,IAAI,IAAI,EAAE;gCACpB,SAAS,EAAE,aAAW,CAAC,SAAS;6BAChC,EAAC,CAAC,CAAC;;;;;aAEL,EAAE,cAAO,CAAC,CAAC,CAAC;IACd,CAAC;IACF,kBAAC;AAAD,CAvRA,AAuRC,IAAA;AAvRY,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';\nimport { CronJobManager } from '../cron/cron';\nimport * as moment from 'moment-timezone';\nimport { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { objectIdHexString } from '../managers/mongo.manager';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\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\tthis._watchCrons$.removeAllListeners();\n\t\t\tthis._watchCrons$.close();\n\t\t\tthis._watchCrons$ = null;\n\t\t}\n\t\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\t\n\t\tif (!this._watchCrons$ || this._watchCrons$.closed) {\t\t\t\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\tif (job.running) {\n\t\t\t\t\t\tCronJobs.updateOne({_id: job._id}, {$set: {running: false}});\n\t\t\t\t\t}\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\tlet oldDoc = this._jobs.filter(a => a._id === <any>doc.documentKey['_id'])[0];\n\t\t\t\t\t\tif (oldDoc) {\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\n\t\t\t\t\t\t\tif (oldDoc.name !== doc.fullDocument.name) {\n\t\t\t\t\t\t\t\tthis.removeCronJob(oldDoc.name);\n\t\t\t\t\t\t\t\tthis.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (oldDoc.time_to_run !== doc.fullDocument.time_to_run || \n\t\t\t\t\t\t\t\toldDoc.timezone !== doc.fullDocument.timezone\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthis.updateCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\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$.removeAllListeners();\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t})\n\t\t\t.on('end', () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$.close();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t})\n\t\t\t.on('close', () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tthis.watchCrons();\n\t\t\t});\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 (!this.doesCronJobExist(cron)) {\n\t\t\ttry {\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() => this.runCronJob(cron),\n\t\t\t\t\tnull,\n\t\t\t\t\ttrue,\n\t\t\t\t\tcron.timezone,\n\t\t\t\t\tnull, \n\t\t\t\t\tfalse\n\t\t\t\t);\n\n\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\t\tif (cron.running || (nextDate && !cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {running: false, next_run: nextDate || null}});\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch(e) {\n\t\t\t\tconsole.log('Cron error', e);\n\n\t\t\t\tif (cron.time_to_run instanceof Date) {\n\t\t\t\t\tthis.runCronJob(cron);\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, () => this.runCronJob(cron), null, true, cron.timezone);\n\n\t\t\tlet nextDate = new Date(this._cronManager.getJob(cron.name).nextDate()['ts']);\n\n\t\t\tif (nextDate && (!cron.next_run || nextDate.getTime() !== cron.next_run.getTime())) {\n\t\t\t\tCronJobs.updateOne({_id: cron._id}, {$set: {next_run: nextDate}});\n\t\t\t}\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\tCronJobs.findOneAndUpdate({\n\t\t\t$and: [\n\t\t\t\t{_id: cron._id},\n\t\t\t\t{running: false},\n\t\t\t\t{\n\t\t\t\t\t$or: [\n\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\tif (res) {\n\t\t\t\tlet cronHistory: CronJobHistoryModel = {\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tname: res.name,\n\t\t\t\t\treoccuring: res.repeat,\n\t\t\t\t\ttime_to_run: res.time_to_run,\n\t\t\t\t\tmethod_name: res.method_run,\n\t\t\t\t\tid_cronjob: res._id,\n\t\t\t\t\tserver_restart: true,\n\t\t\t\t\tpassed: true,\n\t\t\t\t\terror: '',\n\t\t\t\t\tdate_scheduled: res.next_run,\n\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\tdate_end: null,\n\t\t\t\t\tdate_next: null\n\t\t\t\t};\n\t\t\t\t\n\t\t\t\tawait CronJobHistories.create(cronHistory);\n\n\t\t\t\tlet timeoutHandle = setTimeout(async () => {\n\t\t\t\t\tconsole.log(new Date(), 'Cron Timeout', JSON.stringify(cron, null, 2));\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\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}, 5 * 60 * 1000); // 5 minutes in milliseconds\n\n\t\t\t\ttry {\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\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\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\t\t\t\t}\n\t\t\t\tcatch (err) {\n\t\t\t\t\tconsole.log(new Date(), 'Cron Error', JSON.stringify(err, null, 2));\n\t\t\t\t\tcronHistory.error = JSON.stringify(err, null, 2);\n\t\t\t\t\tcronHistory.passed = false;\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\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\tfinally {\n\t\t\t\t\t// Clear the timeout if the job completes or fails before the timeout\n\t\t\t\t\tclearTimeout(timeoutHandle);\n\t\t\t\t}\n\n\t\t\t\tif (res.repeat) {\n\t\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\tCronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t} \n\t\t\t\telse {\n\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\n\t\t\t\tCronJobHistories.updateOne({_id: cronHistory._id}, {$set: {\n\t\t\t\t\tserver_restart: false,\n\t\t\t\t\tpassed: cronHistory.passed,\n\t\t\t\t\terror: cronHistory.error,\n\t\t\t\t\tdate_end: new Date(),\n\t\t\t\t\tdate_next: cronHistory.date_next\n\t\t\t\t}});\n\t\t\t}\n\t\t}, () => {});\n\t}\n}"]}
|
package/methods/logs.js
CHANGED
|
@@ -152,37 +152,37 @@ function loadLogMethods(methodManager) {
|
|
|
152
152
|
second: {
|
|
153
153
|
$second: {
|
|
154
154
|
date: '$createdAt',
|
|
155
|
-
timezone: 'America/Chicago'
|
|
155
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
158
|
minute: {
|
|
159
159
|
$minute: {
|
|
160
160
|
date: '$createdAt',
|
|
161
|
-
timezone: 'America/Chicago'
|
|
161
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
162
162
|
}
|
|
163
163
|
},
|
|
164
164
|
hour: {
|
|
165
165
|
$hour: {
|
|
166
166
|
date: '$createdAt',
|
|
167
|
-
timezone: 'America/Chicago'
|
|
167
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
170
|
day: {
|
|
171
171
|
$dayOfMonth: {
|
|
172
172
|
date: '$createdAt',
|
|
173
|
-
timezone: 'America/Chicago'
|
|
173
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
174
174
|
}
|
|
175
175
|
},
|
|
176
176
|
month: {
|
|
177
177
|
$month: {
|
|
178
178
|
date: '$createdAt',
|
|
179
|
-
timezone: 'America/Chicago'
|
|
179
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
182
|
year: {
|
|
183
183
|
$year: {
|
|
184
184
|
date: '$createdAt',
|
|
185
|
-
timezone: 'America/Chicago'
|
|
185
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
};
|
|
@@ -200,31 +200,31 @@ function loadLogMethods(methodManager) {
|
|
|
200
200
|
minute: {
|
|
201
201
|
$minute: {
|
|
202
202
|
date: '$createdAt',
|
|
203
|
-
timezone: 'America/Chicago'
|
|
203
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
204
204
|
}
|
|
205
205
|
},
|
|
206
206
|
hour: {
|
|
207
207
|
$hour: {
|
|
208
208
|
date: '$createdAt',
|
|
209
|
-
timezone: 'America/Chicago'
|
|
209
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
210
210
|
}
|
|
211
211
|
},
|
|
212
212
|
day: {
|
|
213
213
|
$dayOfMonth: {
|
|
214
214
|
date: '$createdAt',
|
|
215
|
-
timezone: 'America/Chicago'
|
|
215
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
216
216
|
}
|
|
217
217
|
},
|
|
218
218
|
month: {
|
|
219
219
|
$month: {
|
|
220
220
|
date: '$createdAt',
|
|
221
|
-
timezone: 'America/Chicago'
|
|
221
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
222
222
|
}
|
|
223
223
|
},
|
|
224
224
|
year: {
|
|
225
225
|
$year: {
|
|
226
226
|
date: '$createdAt',
|
|
227
|
-
timezone: 'America/Chicago'
|
|
227
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
};
|
|
@@ -241,25 +241,25 @@ function loadLogMethods(methodManager) {
|
|
|
241
241
|
hour: {
|
|
242
242
|
$hour: {
|
|
243
243
|
date: '$createdAt',
|
|
244
|
-
timezone: 'America/Chicago'
|
|
244
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
245
245
|
}
|
|
246
246
|
},
|
|
247
247
|
day: {
|
|
248
248
|
$dayOfMonth: {
|
|
249
249
|
date: '$createdAt',
|
|
250
|
-
timezone: 'America/Chicago'
|
|
250
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
251
251
|
}
|
|
252
252
|
},
|
|
253
253
|
month: {
|
|
254
254
|
$month: {
|
|
255
255
|
date: '$createdAt',
|
|
256
|
-
timezone: 'America/Chicago'
|
|
256
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
257
257
|
}
|
|
258
258
|
},
|
|
259
259
|
year: {
|
|
260
260
|
$year: {
|
|
261
261
|
date: '$createdAt',
|
|
262
|
-
timezone: 'America/Chicago'
|
|
262
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
};
|
|
@@ -275,19 +275,19 @@ function loadLogMethods(methodManager) {
|
|
|
275
275
|
day: {
|
|
276
276
|
$dayOfMonth: {
|
|
277
277
|
date: '$createdAt',
|
|
278
|
-
timezone: 'America/Chicago'
|
|
278
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
279
279
|
}
|
|
280
280
|
},
|
|
281
281
|
month: {
|
|
282
282
|
$month: {
|
|
283
283
|
date: '$createdAt',
|
|
284
|
-
timezone: 'America/Chicago'
|
|
284
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
285
285
|
}
|
|
286
286
|
},
|
|
287
287
|
year: {
|
|
288
288
|
$year: {
|
|
289
289
|
date: '$createdAt',
|
|
290
|
-
timezone: 'America/Chicago'
|
|
290
|
+
timezone: process.env.TZ_CLIENT || 'America/Chicago'
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
};
|
package/methods/logs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/methods/logs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAAqD;AACrD,0FAA8E;AAC9E,kCAA2C;AAC3C,8FAAkF;AAClF,2DAA8D;AAE9D,SAAgB,cAAc,CAAC,aAA4B;IAC1D,aAAa,CAAC,OAAO,CAAC;QACrB,cAAc,EAAE;YACf,QAAQ,EAAE,UAAS,OAAO,EAAE,IAAI;gBAC/B,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,uBAAe,CAAC,aAAa,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;gBAE9J,OAAO,qBAAI,CAAC,SAAS,CAAC;oBACrB,GAAG,EAAE,IAAA,iCAAiB,GAAE;oBACxB,IAAI,EAAE,OAAO;oBACb,UAAU,EAAE,EAAE;oBACd,WAAW,EAAE,EAAE;oBACf,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;oBACtC,MAAM,EAAE,EAAE;oBACV,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;oBAC3B,IAAI,EAAE,IAAI,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,UAAU,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAC,EAAE,IAAI,CAAC,EAAA;;gCAxB/H,YAAY,GAAG,SAwBgH;gCAEnI,OAAO,CAAC;oCACP,OAAO,EAAE,SAAS;oCAClB,aAAa,EAAE,aAAa;oCAC5B,eAAe,EAAE,eAAe;oCAChC,YAAY,EAAE,YAAY;iCAC1B,CAAC,CAAC;;;;qBACH,CAAC,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,IAAI;SACpB;KACD,CAAC,CAAC;AACJ,CAAC;AA/TD,wCA+TC","file":"logs.js","sourcesContent":["import { MethodManager } from '../managers/method.manager';\nimport { Logs } from '../collections/log.collection';\nimport { LogSubscriptions } from '../collections/log-subscription.collection';\nimport { ResolveIOServer } from '../index';\nimport { LogMethodLatencies } from '../collections/log-method-latency.collection';\nimport { objectIdHexString } from '../managers/mongo.manager';\n\nexport function loadLogMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tinsertErrorLog: {\n\t\t\tfunction: function(message, data) {\n\t\t\t\tthis.sendEmail('dev@resolveio.com', 'Error Detected - ' + ResolveIOServer.getClientName(), this.user + '\\n' + message + '\\n' + JSON.stringify(data, null, 2));\n\n\t\t\t\treturn Logs.insertOne({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\ttype: 'error',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tid_document: '',\n\t\t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\tmethod: '',\n\t\t\t\t\tid_user: this.id_user || '',\n\t\t\t\t\tuser: this.user || '',\n\t\t\t\t\tmessageId: 0,\n\t\t\t\t\troute: ''\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t},\n\t\tinsertSubscriptionLog: {\n\t\t\tfunction: function(type, subscription, collection_name, subData) {\n\t\t\t\treturn LogSubscriptions.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\ttype: type,\n\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\tcollection_name: collection_name,\n\t\t\t\t\tsubData: subData\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t},\n\t\tinsertMethodLatencyLog: {\n\t\t\tfunction: function(method) {\n\t\t\t\treturn LogMethodLatencies.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\tdate_end: null,\n\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\tmethod: method\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t},\n\t\tsuperadminAPM: {\n\t\t\tfunction: function(date_start: Date, date_end: Date, graphInterval) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet latencies = await LogMethodLatencies.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: '$method',\n\t\t\t\t\t\t\t\tmethod: {$first: '$method'},\n\t\t\t\t\t\t\t\tcount: {$sum: 1},\n\t\t\t\t\t\t\t\tlatency_min: {$min: '$latency_ms'},\n\t\t\t\t\t\t\t\tlatency_avg: {$avg: '$latency_ms'},\n\t\t\t\t\t\t\t\tlatency_max: {$max: '$latency_ms'}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tlet subscriptions = await LogSubscriptions.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: '$subscription',\n\t\t\t\t\t\t\t\tsubscription: {$first: '$subscription'},\n\t\t\t\t\t\t\t\tcount: {$sum: 1}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tlet groupId = {};\n\t\t\t\t\tlet groupSort = {};\n\n\t\t\t\t\tif (graphInterval === 'seconds') {\n\t\t\t\t\t\tgroupId = {\n\t\t\t\t\t\t\tsecond: {\n\t\t\t\t\t\t\t\t$second: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t\t'_id.minute': 1,\n\t\t\t\t\t\t\t'_id.second': 1\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse if (graphInterval === 'minutes') {\n\t\t\t\t\t\tgroupId = {\n\t\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t\t'_id.minute': 1\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse if (graphInterval === 'hours') {\n\t\t\t\t\t\tgroupId = {\n\t\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t\t'_id.hour': 1\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\tgroupId = {\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tlet methodGraphData = await LogMethodLatencies.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tlet subGraphData = await LogSubscriptions.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tmethods: latencies,\n\t\t\t\t\t\tsubscriptions: subscriptions,\n\t\t\t\t\t\tmethodGraphData: methodGraphData,\n\t\t\t\t\t\tsubGraphData: subGraphData\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t}\n\t});\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/methods/logs.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,gEAAqD;AACrD,0FAA8E;AAC9E,kCAA2C;AAC3C,8FAAkF;AAClF,2DAA8D;AAE9D,SAAgB,cAAc,CAAC,aAA4B;IAC1D,aAAa,CAAC,OAAO,CAAC;QACrB,cAAc,EAAE;YACf,QAAQ,EAAE,UAAS,OAAO,EAAE,IAAI;gBAC/B,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,uBAAe,CAAC,aAAa,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;gBAE9J,OAAO,qBAAI,CAAC,SAAS,CAAC;oBACrB,GAAG,EAAE,IAAA,iCAAiB,GAAE;oBACxB,IAAI,EAAE,OAAO;oBACb,UAAU,EAAE,EAAE;oBACd,WAAW,EAAE,EAAE;oBACf,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;oBACtC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DACP;6CACD;yCACD;wCACD;4CACC,KAAK,EAAE,SAAS;yCAChB;qCACD,EAAE,EAAC,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAC,EAAE,IAAI,CAAC,EAAA;;gCAxB/H,eAAe,GAAG,SAwB6G;gCAEhH,qBAAM,8CAAgB,CAAC,SAAS,CAAC;wCACnD;4CACC,MAAM,EAAE;gDACP,IAAI,EAAE;oDACL;wDACC,SAAS,EAAE,EAAC,IAAI,EAAE,UAAU,EAAC;qDAC7B;oDACD;wDACC,SAAS,EAAE,EAAC,IAAI,EAAE,QAAQ,EAAC;qDAC3B;iDACD;6CACD;yCACD;wCACD;4CACC,MAAM,EAAE;gDACP,GAAG,EAAE,OAAO;gDACZ,KAAK,EAAE;oDACN,IAAI,EAAE,CAAC;iDACP;6CACD;yCACD;wCACD;4CACC,KAAK,EAAE,SAAS;yCAChB;qCACD,EAAE,EAAC,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EAAC,EAAE,IAAI,CAAC,EAAA;;gCAxB/H,YAAY,GAAG,SAwBgH;gCAEnI,OAAO,CAAC;oCACP,OAAO,EAAE,SAAS;oCAClB,aAAa,EAAE,aAAa;oCAC5B,eAAe,EAAE,eAAe;oCAChC,YAAY,EAAE,YAAY;iCAC1B,CAAC,CAAC;;;;qBACH,CAAC,CAAC;YACJ,CAAC;YACD,cAAc,EAAE,IAAI;SACpB;KACD,CAAC,CAAC;AACJ,CAAC;AA/TD,wCA+TC","file":"logs.js","sourcesContent":["import { MethodManager } from '../managers/method.manager';\nimport { Logs } from '../collections/log.collection';\nimport { LogSubscriptions } from '../collections/log-subscription.collection';\nimport { ResolveIOServer } from '../index';\nimport { LogMethodLatencies } from '../collections/log-method-latency.collection';\nimport { objectIdHexString } from '../managers/mongo.manager';\n\nexport function loadLogMethods(methodManager: MethodManager) {\n\tmethodManager.methods({\n\t\tinsertErrorLog: {\n\t\t\tfunction: function(message, data) {\n\t\t\t\tthis.sendEmail('dev@resolveio.com', 'Error Detected - ' + ResolveIOServer.getClientName(), this.user + '\\n' + message + '\\n' + JSON.stringify(data, null, 2));\n\n\t\t\t\treturn Logs.insertOne({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\ttype: 'error',\n\t\t\t\t\tcollection: '',\n\t\t\t\t\tid_document: '',\n\t\t\t\t\tpayload: JSON.stringify(data, null, 2),\n\t\t\t\t\tmethod: '',\n\t\t\t\t\tid_user: this.id_user || '',\n\t\t\t\t\tuser: this.user || '',\n\t\t\t\t\tmessageId: 0,\n\t\t\t\t\troute: ''\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t},\n\t\tinsertSubscriptionLog: {\n\t\t\tfunction: function(type, subscription, collection_name, subData) {\n\t\t\t\treturn LogSubscriptions.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\ttype: type,\n\t\t\t\t\tsubscription: subscription,\n\t\t\t\t\tcollection_name: collection_name,\n\t\t\t\t\tsubData: subData\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t},\n\t\tinsertMethodLatencyLog: {\n\t\t\tfunction: function(method) {\n\t\t\t\treturn LogMethodLatencies.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t__v: 0,\n\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\tdate_end: null,\n\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\tmethod: method\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t},\n\t\tsuperadminAPM: {\n\t\t\tfunction: function(date_start: Date, date_end: Date, graphInterval) {\n\t\t\t\treturn new Promise(async (resolve, reject) => {\n\t\t\t\t\tlet latencies = await LogMethodLatencies.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: '$method',\n\t\t\t\t\t\t\t\tmethod: {$first: '$method'},\n\t\t\t\t\t\t\t\tcount: {$sum: 1},\n\t\t\t\t\t\t\t\tlatency_min: {$min: '$latency_ms'},\n\t\t\t\t\t\t\t\tlatency_avg: {$avg: '$latency_ms'},\n\t\t\t\t\t\t\t\tlatency_max: {$max: '$latency_ms'}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tlet subscriptions = await LogSubscriptions.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: '$subscription',\n\t\t\t\t\t\t\t\tsubscription: {$first: '$subscription'},\n\t\t\t\t\t\t\t\tcount: {$sum: 1}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tlet groupId = {};\n\t\t\t\t\tlet groupSort = {};\n\n\t\t\t\t\tif (graphInterval === 'seconds') {\n\t\t\t\t\t\tgroupId = {\n\t\t\t\t\t\t\tsecond: {\n\t\t\t\t\t\t\t\t$second: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t\t'_id.minute': 1,\n\t\t\t\t\t\t\t'_id.second': 1\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse if (graphInterval === 'minutes') {\n\t\t\t\t\t\tgroupId = {\n\t\t\t\t\t\t\tminute: {\n\t\t\t\t\t\t\t\t$minute: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t\t'_id.hour': 1,\n\t\t\t\t\t\t\t'_id.minute': 1\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\telse if (graphInterval === 'hours') {\n\t\t\t\t\t\tgroupId = {\n\t\t\t\t\t\t\thour: {\n\t\t\t\t\t\t\t\t$hour: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1,\n\t\t\t\t\t\t\t'_id.hour': 1\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\tgroupId = {\n\t\t\t\t\t\t\tday: {\n\t\t\t\t\t\t\t\t$dayOfMonth: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tmonth: {\n\t\t\t\t\t\t\t\t$month: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tyear: {\n\t\t\t\t\t\t\t\t$year: {\n\t\t\t\t\t\t\t\t\tdate: '$createdAt',\n\t\t\t\t\t\t\t\t\ttimezone: process.env.TZ_CLIENT || 'America/Chicago'\n\t\t\t\t\t\t\t\t} \n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tgroupSort = {\n\t\t\t\t\t\t\t'_id.year': 1,\n\t\t\t\t\t\t\t'_id.month': 1,\n\t\t\t\t\t\t\t'_id.day': 1\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tlet methodGraphData = await LogMethodLatencies.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tlet subGraphData = await LogSubscriptions.aggregate([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$gte: date_start}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tcreatedAt: {$lte: date_end}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t\t_id: groupId,\n\t\t\t\t\t\t\t\tcount: {\n\t\t\t\t\t\t\t\t\t$sum: 1\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$sort: groupSort\n\t\t\t\t\t\t}\n\t\t\t\t\t], {allowDiskUse: true, readPreference: this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary'}, true);\n\n\t\t\t\t\tresolve({\n\t\t\t\t\t\tmethods: latencies,\n\t\t\t\t\t\tsubscriptions: subscriptions,\n\t\t\t\t\t\tmethodGraphData: methodGraphData,\n\t\t\t\t\t\tsubGraphData: subGraphData\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\tskipValidation: true\n\t\t}\n\t});\n}"]}
|