@resolveio/server-lib 22.2.31 → 22.2.33
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/collections/cron-job.collection.js +4 -0
- package/collections/cron-job.collection.js.map +1 -1
- package/managers/cron.manager.js +66 -50
- package/managers/cron.manager.js.map +1 -1
- package/methods/ai-terminal.d.ts +6 -0
- package/methods/ai-terminal.js +405 -181
- package/methods/ai-terminal.js.map +1 -1
- package/models/cron-job.model.d.ts +1 -0
- package/models/cron-job.model.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/cron-job.collection.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,2DAAsF;AAEtF,gEAA0D;AAE1D,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,MAAM;KACZ;IACD,MAAM,EAAE;QACP,IAAI,EAAE,OAAO;KACb;IACD,WAAW,EAAE;QACZ,IAAI,EAAE,sBAAY,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC;KACtC;IACD,UAAU,EAAE;QACX,IAAI,EAAE,MAAM;KACZ;IACD,eAAe,EAAE;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KACd;IACD,eAAe,EAAE;QAChB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,oBAAoB,EAAE;QACrB,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KACd;IACD,OAAO,EAAE;QACR,IAAI,EAAE,OAAO;KACb;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;KACZ;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;CACD,CAAC;AAES,QAAA,QAAQ,GAAyC,IAAI,CAAC;AAEjE,oBAAoB,EAAE,CAAC;AAEvB,SAAS,oBAAoB;IAC5B,IAAI,sCAAe,IAAI,sCAAe,CAAC,SAAS,EAAE,IAAI,iCAAiB,EAAE,CAAC;QACzE,IAAM,KAAK,GAAG,iCAAiB,CAAC,MAAM,CAAe;YACpD,cAAc,EAAE,WAAW;YAC3B,MAAM,EAAE,MAAM;YACd,oBAAoB,EAAE,KAAK;YAC3B,gBAAgB,EAAE,KAAK;YACvB,yBAAyB,EAAE,EAAE;YAC7B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,KAAK;YACjB,WAAW,EAAE,IAAI;YACjB,iBAAiB,EAAE,IAAI;YACvB,SAAS,EAAE,IAAI;YACf,aAAa,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,gBAAQ,GAAG,KAAK,CAAC,eAAe,CAAC;QACjC,gBAAQ,CAAC,WAAW,CAAC,EAAC,OAAO,EAAE,CAAC,EAAC,CAAC,CAAC;IACpC,CAAC;SACI,CAAC;QACL,YAAY,CAAC;YACZ,oBAAoB,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","file":"cron-job.collection.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { CronJobModel } from '../models/cron-job.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tname: {\n\t\ttype: String\n\t},\n\trepeat: {\n\t\ttype: Boolean\n\t},\n\ttime_to_run: {\n\t\ttype: SimpleSchema.oneOf(String, Date)\n\t},\n\tmethod_run: {\n\t\ttype: String\n\t},\n\tmethod_run_data: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t},\n\tmethod_complete: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tmethod_complete_data: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t},\n\trunning: {\n\t\ttype: Boolean\n\t},\n\ttimezone: {\n\t\ttype: String\n\t},\n\tnext_run: {\n\t\ttype: Date,\n\t\toptional: true\n\t}\n};\n\nexport let CronJobs: MongoManagerCollection<CronJobModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB() && MongoManagerModel) {\n\t\tconst model = MongoManagerModel.create<CronJobModel>({\n\t\t\tcollectionName: 'cron-jobs',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: false,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null,\n\t\t\tskipCache: true,\n\t\t\tbypassSession: true\n\t\t});\n\t\tCronJobs = model.collection_main;\n\t\tCronJobs.createIndex({running: 1});\n\t}\n\telse {\n\t\tsetImmediate(() => {\n\t\t\tinitializeCollection();\n\t\t});\n\t}\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/cron-job.collection.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AACxC,2DAAsF;AAEtF,gEAA0D;AAE1D,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IAC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,gBAAgB,EAAE,KAAK;YACvB,yBAAyB,EAAE,EAAE;YAC7B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,KAAK;YACjB,WAAW,EAAE,IAAI;YACjB,iBAAiB,EAAE,IAAI;YACvB,SAAS,EAAE,IAAI;YACf,aAAa,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,gBAAQ,GAAG,KAAK,CAAC,eAAe,CAAC;QACjC,gBAAQ,CAAC,WAAW,CAAC,EAAC,OAAO,EAAE,CAAC,EAAC,CAAC,CAAC;IACpC,CAAC;SACI,CAAC;QACL,YAAY,CAAC;YACZ,oBAAoB,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","file":"cron-job.collection.js","sourcesContent":["import SimpleSchema from 'simpl-schema';\nimport { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { CronJobModel } from '../models/cron-job.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tname: {\n\t\ttype: String\n\t},\n\trepeat: {\n\t\ttype: Boolean\n\t},\n\ttime_to_run: {\n\t\ttype: SimpleSchema.oneOf(String, Date)\n\t},\n\tmethod_run: {\n\t\ttype: String\n\t},\n\tmethod_run_data: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t},\n\tmethod_complete: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tmethod_complete_data: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t},\n\tsave_history: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\trunning: {\n\t\ttype: Boolean\n\t},\n\ttimezone: {\n\t\ttype: String\n\t},\n\tnext_run: {\n\t\ttype: Date,\n\t\toptional: true\n\t}\n};\n\nexport let CronJobs: MongoManagerCollection<CronJobModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB() && MongoManagerModel) {\n\t\tconst model = MongoManagerModel.create<CronJobModel>({\n\t\t\tcollectionName: 'cron-jobs',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: false,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null,\n\t\t\tskipCache: true,\n\t\t\tbypassSession: true\n\t\t});\n\t\tCronJobs = model.collection_main;\n\t\tCronJobs.createIndex({running: 1});\n\t}\n\telse {\n\t\tsetImmediate(() => {\n\t\t\tinitializeCollection();\n\t\t});\n\t}\n}\n"]}
|
package/managers/cron.manager.js
CHANGED
|
@@ -358,7 +358,7 @@ var CronManager = /** @class */ (function () {
|
|
|
358
358
|
};
|
|
359
359
|
CronManager.prototype.runCronJob = function (cron) {
|
|
360
360
|
return __awaiter(this, void 0, void 0, function () {
|
|
361
|
-
var now, res, cronHistory_1, timeoutHandle, err_1, nextDate, nextDate;
|
|
361
|
+
var now, res, saveHistoryOverride, saveHistory, cronHistory_1, timeoutHandle, err_1, nextDate, nextDate;
|
|
362
362
|
var _this = this;
|
|
363
363
|
return __generator(this, function (_a) {
|
|
364
364
|
switch (_a.label) {
|
|
@@ -379,7 +379,11 @@ var CronManager = /** @class */ (function () {
|
|
|
379
379
|
}, { $set: { running: true } })];
|
|
380
380
|
case 1:
|
|
381
381
|
res = _a.sent();
|
|
382
|
-
if (!res) return [3 /*break*/,
|
|
382
|
+
if (!res) return [3 /*break*/, 25];
|
|
383
|
+
saveHistoryOverride = !!(res.method_run_data && res.method_run_data._cron_save_history === false);
|
|
384
|
+
saveHistory = !saveHistoryOverride && res.save_history !== false;
|
|
385
|
+
cronHistory_1 = null;
|
|
386
|
+
if (!saveHistory) return [3 /*break*/, 3];
|
|
383
387
|
cronHistory_1 = {
|
|
384
388
|
_id: (0, common_1.objectIdHexString)(),
|
|
385
389
|
name: res.name,
|
|
@@ -398,6 +402,8 @@ var CronManager = /** @class */ (function () {
|
|
|
398
402
|
return [4 /*yield*/, cron_job_history_collection_1.CronJobHistories.create(cronHistory_1)];
|
|
399
403
|
case 2:
|
|
400
404
|
_a.sent();
|
|
405
|
+
_a.label = 3;
|
|
406
|
+
case 3:
|
|
401
407
|
timeoutHandle = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
402
408
|
var nextDate;
|
|
403
409
|
return __generator(this, function (_a) {
|
|
@@ -406,7 +412,9 @@ var CronManager = /** @class */ (function () {
|
|
|
406
412
|
console.log(new Date(), 'Cron Timeout', this.safeStringify(cron));
|
|
407
413
|
if (!res.repeat) return [3 /*break*/, 2];
|
|
408
414
|
nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);
|
|
409
|
-
cronHistory_1
|
|
415
|
+
if (cronHistory_1) {
|
|
416
|
+
cronHistory_1.date_next = nextDate;
|
|
417
|
+
}
|
|
410
418
|
return [4 /*yield*/, cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } })];
|
|
411
419
|
case 1:
|
|
412
420
|
_a.sent();
|
|
@@ -419,74 +427,82 @@ var CronManager = /** @class */ (function () {
|
|
|
419
427
|
}
|
|
420
428
|
});
|
|
421
429
|
}); }, 5 * 60 * 1000);
|
|
422
|
-
_a.label =
|
|
423
|
-
case 3:
|
|
424
|
-
_a.trys.push([3, 12, 17, 18]);
|
|
425
|
-
if (!res.method_run_data) return [3 /*break*/, 5];
|
|
426
|
-
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run, res.method_run_data)];
|
|
430
|
+
_a.label = 4;
|
|
427
431
|
case 4:
|
|
432
|
+
_a.trys.push([4, 13, 18, 19]);
|
|
433
|
+
if (!res.method_run_data) return [3 /*break*/, 6];
|
|
434
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run, res.method_run_data)];
|
|
435
|
+
case 5:
|
|
428
436
|
_a.sent();
|
|
429
|
-
return [3 /*break*/,
|
|
430
|
-
case
|
|
431
|
-
case 6:
|
|
432
|
-
_a.sent();
|
|
433
|
-
_a.label = 7;
|
|
437
|
+
return [3 /*break*/, 8];
|
|
438
|
+
case 6: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run)];
|
|
434
439
|
case 7:
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete, res.method_complete_data)];
|
|
440
|
+
_a.sent();
|
|
441
|
+
_a.label = 8;
|
|
438
442
|
case 8:
|
|
443
|
+
if (!res.method_complete) return [3 /*break*/, 12];
|
|
444
|
+
if (!res.method_complete_data) return [3 /*break*/, 10];
|
|
445
|
+
return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete, res.method_complete_data)];
|
|
446
|
+
case 9:
|
|
439
447
|
_a.sent();
|
|
440
|
-
return [3 /*break*/,
|
|
441
|
-
case
|
|
442
|
-
case
|
|
448
|
+
return [3 /*break*/, 12];
|
|
449
|
+
case 10: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete)];
|
|
450
|
+
case 11:
|
|
443
451
|
_a.sent();
|
|
444
|
-
_a.label =
|
|
445
|
-
case
|
|
446
|
-
case
|
|
452
|
+
_a.label = 12;
|
|
453
|
+
case 12: return [3 /*break*/, 19];
|
|
454
|
+
case 13:
|
|
447
455
|
err_1 = _a.sent();
|
|
448
456
|
console.log(new Date(), 'Cron Error', this.safeStringify(err_1));
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
457
|
+
if (cronHistory_1) {
|
|
458
|
+
cronHistory_1.error = this.safeStringify(err_1);
|
|
459
|
+
cronHistory_1.passed = false;
|
|
460
|
+
}
|
|
461
|
+
if (!res.repeat) return [3 /*break*/, 15];
|
|
452
462
|
nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);
|
|
453
|
-
cronHistory_1
|
|
463
|
+
if (cronHistory_1) {
|
|
464
|
+
cronHistory_1.date_next = nextDate;
|
|
465
|
+
}
|
|
454
466
|
return [4 /*yield*/, cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } })];
|
|
455
|
-
case
|
|
467
|
+
case 14:
|
|
456
468
|
_a.sent();
|
|
457
|
-
return [3 /*break*/,
|
|
458
|
-
case
|
|
459
|
-
case
|
|
469
|
+
return [3 /*break*/, 17];
|
|
470
|
+
case 15: return [4 /*yield*/, cron_job_collection_1.CronJobs.deleteOne({ _id: res._id })];
|
|
471
|
+
case 16:
|
|
460
472
|
_a.sent();
|
|
461
|
-
_a.label =
|
|
462
|
-
case
|
|
463
|
-
case
|
|
473
|
+
_a.label = 17;
|
|
474
|
+
case 17: return [3 /*break*/, 19];
|
|
475
|
+
case 18:
|
|
464
476
|
// Clear the timeout if the job completes or fails before the timeout
|
|
465
477
|
clearTimeout(timeoutHandle);
|
|
466
478
|
return [7 /*endfinally*/];
|
|
467
|
-
case
|
|
468
|
-
if (!res.repeat) return [3 /*break*/,
|
|
479
|
+
case 19:
|
|
480
|
+
if (!res.repeat) return [3 /*break*/, 21];
|
|
469
481
|
nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);
|
|
470
|
-
cronHistory_1
|
|
482
|
+
if (cronHistory_1) {
|
|
483
|
+
cronHistory_1.date_next = nextDate;
|
|
484
|
+
}
|
|
471
485
|
return [4 /*yield*/, cron_job_collection_1.CronJobs.updateOne({ _id: res._id }, { $set: { running: false, next_run: nextDate } })];
|
|
472
|
-
case
|
|
486
|
+
case 20:
|
|
473
487
|
_a.sent();
|
|
474
|
-
return [3 /*break*/,
|
|
475
|
-
case
|
|
476
|
-
case
|
|
488
|
+
return [3 /*break*/, 23];
|
|
489
|
+
case 21: return [4 /*yield*/, cron_job_collection_1.CronJobs.deleteOne({ _id: res._id })];
|
|
490
|
+
case 22:
|
|
477
491
|
_a.sent();
|
|
478
|
-
_a.label =
|
|
479
|
-
case 22: return [4 /*yield*/, cron_job_history_collection_1.CronJobHistories.updateOne({ _id: cronHistory_1._id }, { $set: {
|
|
480
|
-
server_restart: false,
|
|
481
|
-
passed: cronHistory_1.passed,
|
|
482
|
-
error: cronHistory_1.error,
|
|
483
|
-
date_end: new Date(),
|
|
484
|
-
date_next: cronHistory_1.date_next
|
|
485
|
-
} })];
|
|
492
|
+
_a.label = 23;
|
|
486
493
|
case 23:
|
|
494
|
+
if (!cronHistory_1) return [3 /*break*/, 25];
|
|
495
|
+
return [4 /*yield*/, cron_job_history_collection_1.CronJobHistories.updateOne({ _id: cronHistory_1._id }, { $set: {
|
|
496
|
+
server_restart: false,
|
|
497
|
+
passed: cronHistory_1.passed,
|
|
498
|
+
error: cronHistory_1.error,
|
|
499
|
+
date_end: new Date(),
|
|
500
|
+
date_next: cronHistory_1.date_next
|
|
501
|
+
} })];
|
|
502
|
+
case 24:
|
|
487
503
|
_a.sent();
|
|
488
|
-
_a.label =
|
|
489
|
-
case
|
|
504
|
+
_a.label = 25;
|
|
505
|
+
case 25: return [2 /*return*/];
|
|
490
506
|
}
|
|
491
507
|
});
|
|
492
508
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0FAA8E;AAC9E,0EAA8D;AAC9D,qCAA8C;AAG9C,gEAA0D;AAC1D,yCAAmD;AAEnD;IAKC;QAFQ,UAAK,GAAmB,EAAE,CAAC;IAEpB,CAA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TY,kCAAW","file":"cron.manager.js","sourcesContent":["import { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport { CronJobManager } from '../cron/cron';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\nimport { CronJobModel } from '../models/cron-job.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\n\nexport class CronManager {\n\tprivate _cronManager: CronJobManager;\n\tprivate _watchCrons$: ChangeStream;\n\tprivate _jobs: CronJobModel[] = [];\n\n\tconstructor() {}\n\n\tstatic create() {\n\t\tconst cronManager = new CronManager();\n\t\tsetImmediate(async () => await cronManager.initialize());\n\t\treturn cronManager;\n\t}\n\n\tprivate async initialize() {\n\t\tthis._cronManager = new CronJobManager();\n\t\tawait this.watchCrons();\n\t}\n\n\tprivate async watchCrons() {\n\t\tif (this._watchCrons$ && !this._watchCrons$.closed) {\n\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\tawait this._watchCrons$.close();\n\t\t\tthis._watchCrons$ = null;\n\t\t}\n\t\n\t\t// eslint-disable-next-line no-restricted-syntax\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\tlet res = await CronJobs.find();\n\t\t\tthis._jobs = res;\n\n\t\t\tfor (let job of this._jobs) {\n\t\t\t\tawait this.addCronJob(job);\n\t\t\t\tif (job.running) {\n\t\t\t\t\tawait CronJobs.updateOne({_id: job._id}, {$set: {running: false}});\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\tawait this.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.find(a => a._id === <any>doc.documentKey['_id']);\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\tawait this.removeCronJob(oldDoc.name);\n\t\t\t\t\t\t\t\tawait this.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (typeof oldDoc.time_to_run !== typeof doc.fullDocument.time_to_run || (typeof oldDoc.time_to_run === 'string' && oldDoc.time_to_run !== doc.fullDocument.time_to_run) ||\n\t\t\t\t\t\t\t\t(oldDoc.time_to_run instanceof Date && oldDoc.time_to_run.getTime() !== (<Date>doc.fullDocument.time_to_run).getTime()) || \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\tawait this.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\tawait this.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.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\t\tawait this.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.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\tawait this.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', async () => {\n\t\t\t\tawait this._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('end', async () => {\n\t\t\t\tawait this._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('close', async () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tawait this.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 async addCronJob(cron: CronJobModel) {\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\ttry {\n\t\t\t\tawait this._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\tawait CronJobs.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\tawait this.runCronJob(cron);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tawait this._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\tawait CronJobs.updateOne({_id: cron._id}, {$set: {next_run: nextDate}});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tawait this._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 async stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tawait this._cronManager.stop(cron.name);\n\t\t}\n\t}\n\n\tprivate async stopAllCronJobs() {\n\t\tawait this._cronManager.stopAll();\n\t}\n\n\tprivate async runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tlet res = await CronJobs.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}});\n\t\t\t\n\t\tif (res) {\n\t\t\tlet cronHistory: CronJobHistoryModel = {\n\t\t\t\t_id: objectIdHexString(),\n\t\t\t\tname: res.name,\n\t\t\t\treoccuring: res.repeat,\n\t\t\t\ttime_to_run: res.time_to_run,\n\t\t\t\tmethod_name: res.method_run,\n\t\t\t\tid_cronjob: res._id,\n\t\t\t\tserver_restart: true,\n\t\t\t\tpassed: true,\n\t\t\t\terror: '',\n\t\t\t\tdate_scheduled: res.next_run,\n\t\t\t\tdate_start: new Date(),\n\t\t\t\tdate_end: null,\n\t\t\t\tdate_next: null\n\t\t\t};\n\t\t\t\n\t\t\tawait CronJobHistories.create(cronHistory);\n\n\t\t\tlet timeoutHandle = setTimeout(async () => {\n\t\t\t\tconsole.log(new Date(), 'Cron Timeout', this.safeStringify(cron));\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\tawait CronJobs.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\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\t\t\t}, 5 * 60 * 1000); // 5 minutes in milliseconds\n\n\t\t\ttry {\n\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t}\n\n\t\t\t\tif (res.method_complete) {\n\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tconsole.log(new Date(), 'Cron Error', this.safeStringify(err));\n\t\t\t\tcronHistory.error = this.safeStringify(err);\n\t\t\t\tcronHistory.passed = false;\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\tawait CronJobs.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\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\t// Clear the timeout if the job completes or fails before the timeout\n\t\t\t\tclearTimeout(timeoutHandle);\n\t\t\t}\n\n\t\t\tif (res.repeat) {\n\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\tawait CronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t} \n\t\t\telse {\n\t\t\t\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t}\n\n\t\t\tawait CronJobHistories.updateOne({_id: cronHistory._id}, {$set: {\n\t\t\t\tserver_restart: false,\n\t\t\t\tpassed: cronHistory.passed,\n\t\t\t\terror: cronHistory.error,\n\t\t\t\tdate_end: new Date(),\n\t\t\t\tdate_next: cronHistory.date_next\n\t\t\t}});\n\t\t}\n\t}\n\n\tprivate safeStringify(obj: unknown)\n\t{\n\t\ttry\n\t\t{\n\t\t\treturn JSON.stringify(obj, this.getCircularReplacer(), 2);\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treturn `Error stringifying object: ${e.message}`;\n\t\t}\n\t}\n\n\tprivate getCircularReplacer()\n\t{\n\t\tconst seen = new WeakSet();\n\t\treturn (key, value) =>\n\t\t{\n\t\t\tif (typeof value === 'object' && value !== null)\n\t\t\t{\n\t\t\t\tif (seen.has(value))\n\t\t\t\t{\n\t\t\t\t\treturn '[Circular]';\n\t\t\t\t}\n\t\t\t\tseen.add(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0FAA8E;AAC9E,0EAA8D;AAC9D,qCAA8C;AAG9C,gEAA0D;AAC1D,yCAAmD;AAEnD;IAKC;QAFQ,UAAK,GAAmB,EAAE,CAAC;IAEpB,CAAC;IAET,kBAAM,GAAb;QAAA,iBAIC;QAHA,IAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;QACtC,YAAY,CAAC;;wBAAY,qBAAM,WAAW,CAAC,UAAU,EAAE,EAAA;wBAA9B,sBAAA,SAA8B,EAAA;;iBAAA,CAAC,CAAC;QACzD,OAAO,WAAW,CAAC;IACpB,CAAC;IAEa,gCAAU,GAAxB;;;;;wBACC,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAc,EAAE,CAAC;wBACzC,qBAAM,IAAI,CAAC,UAAU,EAAE,EAAA;;wBAAvB,SAAuB,CAAC;;;;;KACxB;IAEa,gCAAU,GAAxB;;;;;;;;6BACK,CAAA,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAA,EAA9C,wBAA8C;wBACjD,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,CAAC;wBACvC,qBAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,EAAA;;wBAA/B,SAA+B,CAAC;wBAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;;;oBAG1B,gDAAgD;oBAChD,qBAAM,IAAI,OAAO,CAAC,UAAA,OAAO,IAAI,OAAA,UAAU,CAAC,OAAO,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,KAAK;oCACrB,MAAM,EAAE,aAAW,CAAC,MAAM;oCAC1B,KAAK,EAAE,aAAW,CAAC,KAAK;oCACxB,QAAQ,EAAE,IAAI,IAAI,EAAE;oCACpB,SAAS,EAAE,aAAW,CAAC,SAAS;iCAChC,EAAC,CAAC,EAAA;;wBANH,SAMG,CAAC;;;;;;KAGN;IAEO,mCAAa,GAArB,UAAsB,GAAY;QAEjC,IACA,CAAC;YACA,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,CAAC,EACR,CAAC;YACA,OAAO,qCAA8B,CAAC,CAAC,OAAO,CAAE,CAAC;QAClD,CAAC;IACF,CAAC;IAEO,yCAAmB,GAA3B;QAEC,IAAM,IAAI,GAAG,IAAI,OAAO,EAAE,CAAC;QAC3B,OAAO,UAAC,GAAG,EAAE,KAAK;YAEjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAC/C,CAAC;gBACA,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EACnB,CAAC;oBACA,OAAO,YAAY,CAAC;gBACrB,CAAC;gBACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YACD,OAAO,KAAK,CAAC;QACd,CAAC,CAAC;IACH,CAAC;IACF,kBAAC;AAAD,CAnUA,AAmUC,IAAA;AAnUY,kCAAW","file":"cron.manager.js","sourcesContent":["import { ChangeStream, ChangeStreamDocument } from 'mongodb';\nimport { CronJobHistories } from '../collections/cron-job-history.collection';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport { CronJobManager } from '../cron/cron';\nimport { CronJobHistoryModel } from '../models/cron-job-history.model';\nimport { CronJobModel } from '../models/cron-job.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\n\nexport class CronManager {\n\tprivate _cronManager: CronJobManager;\n\tprivate _watchCrons$: ChangeStream;\n\tprivate _jobs: CronJobModel[] = [];\n\n\tconstructor() {}\n\n\tstatic create() {\n\t\tconst cronManager = new CronManager();\n\t\tsetImmediate(async () => await cronManager.initialize());\n\t\treturn cronManager;\n\t}\n\n\tprivate async initialize() {\n\t\tthis._cronManager = new CronJobManager();\n\t\tawait this.watchCrons();\n\t}\n\n\tprivate async watchCrons() {\n\t\tif (this._watchCrons$ && !this._watchCrons$.closed) {\n\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\tawait this._watchCrons$.close();\n\t\t\tthis._watchCrons$ = null;\n\t\t}\n\t\n\t\t// eslint-disable-next-line no-restricted-syntax\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\tlet res = await CronJobs.find();\n\t\t\tthis._jobs = res;\n\n\t\t\tfor (let job of this._jobs) {\n\t\t\t\tawait this.addCronJob(job);\n\t\t\t\tif (job.running) {\n\t\t\t\t\tawait CronJobs.updateOne({_id: job._id}, {$set: {running: false}});\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\tawait this.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.find(a => a._id === <any>doc.documentKey['_id']);\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\tawait this.removeCronJob(oldDoc.name);\n\t\t\t\t\t\t\t\tawait this.addCronJob(doc.fullDocument);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (typeof oldDoc.time_to_run !== typeof doc.fullDocument.time_to_run || (typeof oldDoc.time_to_run === 'string' && oldDoc.time_to_run !== doc.fullDocument.time_to_run) ||\n\t\t\t\t\t\t\t\t(oldDoc.time_to_run instanceof Date && oldDoc.time_to_run.getTime() !== (<Date>doc.fullDocument.time_to_run).getTime()) || \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\tawait this.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\tawait this.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.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\t\tawait this.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.find(a => a._id === <any>doc.documentKey['_id']);\n\t\t\t\t\t\tawait this.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', async () => {\n\t\t\t\tawait this._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('end', async () => {\n\t\t\t\tawait this._watchCrons$.close();\n\t\t\t})\n\t\t\t.on('close', async () => {\n\t\t\t\tthis._watchCrons$.removeAllListeners();\n\t\t\t\tthis._watchCrons$ = null;\n\t\t\t\tawait this.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 async addCronJob(cron: CronJobModel) {\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\ttry {\n\t\t\t\tawait this._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\tawait CronJobs.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\tawait this.runCronJob(cron);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tawait this._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\tawait CronJobs.updateOne({_id: cron._id}, {$set: {next_run: nextDate}});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tawait this._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 async stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tawait this._cronManager.stop(cron.name);\n\t\t}\n\t}\n\n\tprivate async stopAllCronJobs() {\n\t\tawait this._cronManager.stopAll();\n\t}\n\n\tprivate async runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tlet res = await CronJobs.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}});\n\t\t\t\n\t\tif (res) {\n\t\t\tconst saveHistoryOverride = !!(res.method_run_data && (<any>res.method_run_data)._cron_save_history === false);\n\t\t\tconst saveHistory = !saveHistoryOverride && res.save_history !== false;\n\t\t\tlet cronHistory: CronJobHistoryModel = null;\n\t\t\tif (saveHistory) {\n\t\t\t\tcronHistory = {\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\t\t\t}\n\n\t\t\tlet timeoutHandle = setTimeout(async () => {\n\t\t\t\tconsole.log(new Date(), 'Cron Timeout', this.safeStringify(cron));\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\tif (cronHistory) {\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\t}\n\t\t\t\t\tawait CronJobs.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\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\t\t\t}, 5 * 60 * 1000); // 5 minutes in milliseconds\n\n\t\t\ttry {\n\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t}\n\n\t\t\t\tif (res.method_complete) {\n\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tconsole.log(new Date(), 'Cron Error', this.safeStringify(err));\n\t\t\t\tif (cronHistory) {\n\t\t\t\t\tcronHistory.error = this.safeStringify(err);\n\t\t\t\t\tcronHistory.passed = false;\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\tif (cronHistory) {\n\t\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t\t}\n\t\t\t\t\tawait CronJobs.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\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\t// Clear the timeout if the job completes or fails before the timeout\n\t\t\t\tclearTimeout(timeoutHandle);\n\t\t\t}\n\n\t\t\tif (res.repeat) {\n\t\t\t\tlet nextDate = new Date(this._cronManager.getJob(res.name).nextDate()['ts']);\n\t\t\t\tif (cronHistory) {\n\t\t\t\t\tcronHistory.date_next = nextDate;\n\t\t\t\t}\n\t\t\t\tawait CronJobs.updateOne({_id: res._id}, {$set: {running: false, next_run: nextDate}});\n\t\t\t} \n\t\t\telse {\n\t\t\t\tawait CronJobs.deleteOne({_id: res._id});\n\t\t\t}\n\n\t\t\tif (cronHistory) {\n\t\t\t\tawait CronJobHistories.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\n\tprivate safeStringify(obj: unknown)\n\t{\n\t\ttry\n\t\t{\n\t\t\treturn JSON.stringify(obj, this.getCircularReplacer(), 2);\n\t\t}\n\t\tcatch (e)\n\t\t{\n\t\t\treturn `Error stringifying object: ${e.message}`;\n\t\t}\n\t}\n\n\tprivate getCircularReplacer()\n\t{\n\t\tconst seen = new WeakSet();\n\t\treturn (key, value) =>\n\t\t{\n\t\t\tif (typeof value === 'object' && value !== null)\n\t\t\t{\n\t\t\t\tif (seen.has(value))\n\t\t\t\t{\n\t\t\t\t\treturn '[Circular]';\n\t\t\t\t}\n\t\t\t\tseen.add(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t};\n\t}\n}\n"]}
|
package/methods/ai-terminal.d.ts
CHANGED
|
@@ -194,6 +194,12 @@ export declare function repairAssistantFieldPathReferenceInPipeline(pipeline: Ar
|
|
|
194
194
|
export declare function rewriteMatchExpressionsToExpr(match: any): any;
|
|
195
195
|
export declare function normalizeAssistantMonthlyCalendarWindowPipeline(pipeline: Array<Record<string, any>>): Array<Record<string, any>>;
|
|
196
196
|
export declare function normalizeAssistantAggregatePipeline(pipeline?: Array<Record<string, any>>, collection?: string, originalMessage?: string): Array<Record<string, any>>;
|
|
197
|
+
export declare function resolveReadMultiTermJobRegexFallbackForTesting(query: Record<string, any>, probeDocs?: any[], schemaFields?: string[]): {
|
|
198
|
+
query: Record<string, any>;
|
|
199
|
+
fields: string[];
|
|
200
|
+
sourceFields: string[];
|
|
201
|
+
terms: string[];
|
|
202
|
+
} | null;
|
|
197
203
|
export declare function stripQueryFieldPathsDeep(query: any, fieldsToStrip: string[]): any;
|
|
198
204
|
export declare function stripScopedFieldsFromPipeline(pipeline: any[], fieldsToStrip: string[]): any[];
|
|
199
205
|
export declare function rewriteEmbeddedMatchObjects(query: any): any;
|