@resolveio/server-lib 22.2.30 → 22.2.32

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.
@@ -47,6 +47,10 @@ var schema = {
47
47
  blackbox: true,
48
48
  optional: true
49
49
  },
50
+ save_history: {
51
+ type: Boolean,
52
+ optional: true
53
+ },
50
54
  running: {
51
55
  type: Boolean
52
56
  },
@@ -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;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE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B,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"]}
@@ -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*/, 24];
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.date_next = nextDate;
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 = 3;
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*/, 7];
430
- case 5: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_run)];
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
- if (!res.method_complete) return [3 /*break*/, 11];
436
- if (!res.method_complete_data) return [3 /*break*/, 9];
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*/, 11];
441
- case 9: return [4 /*yield*/, resolveio_server_app_1.ResolveIOServer.getMainServer().getMethodManager().callMethodCron(res.method_complete)];
442
- case 10:
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 = 11;
445
- case 11: return [3 /*break*/, 18];
446
- case 12:
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
- cronHistory_1.error = this.safeStringify(err_1);
450
- cronHistory_1.passed = false;
451
- if (!res.repeat) return [3 /*break*/, 14];
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.date_next = nextDate;
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 13:
467
+ case 14:
456
468
  _a.sent();
457
- return [3 /*break*/, 16];
458
- case 14: return [4 /*yield*/, cron_job_collection_1.CronJobs.deleteOne({ _id: res._id })];
459
- case 15:
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 = 16;
462
- case 16: return [3 /*break*/, 18];
463
- case 17:
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 18:
468
- if (!res.repeat) return [3 /*break*/, 20];
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.date_next = nextDate;
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 19:
486
+ case 20:
473
487
  _a.sent();
474
- return [3 /*break*/, 22];
475
- case 20: return [4 /*yield*/, cron_job_collection_1.CronJobs.deleteOne({ _id: res._id })];
476
- case 21:
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 = 22;
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 = 24;
489
- case 24: return [2 /*return*/];
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,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,EAAE,IAAI,CAAC,EAAzB,CAAyB,CAAC,EAAA;;wBADvD,gDAAgD;wBAChD,SAAuD,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O,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,CApTA,AAoTC,IAAA;AApTY,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;;;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AC;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"]}
@@ -10013,6 +10013,9 @@ function applyAssistantDatedReportWindow(value, toolResult) {
10013
10013
  if (!startDate || !endDate) {
10014
10014
  return content || value || '';
10015
10015
  }
10016
+ var dateDisplayFormat = resolveAssistantDisplayDateFormatPreference();
10017
+ var startDateDisplay = formatAssistantDateValue(startDate, dateDisplayFormat);
10018
+ var endDateDisplay = formatAssistantDateValue(endDate, dateDisplayFormat);
10016
10019
  var mode = normalizeOptionalString(window === null || window === void 0 ? void 0 : window.mode).toLowerCase();
10017
10020
  var months = normalizeOptionalNumber(window === null || window === void 0 ? void 0 : window.months);
10018
10021
  var monthsText = '';
@@ -10025,9 +10028,11 @@ function applyAssistantDatedReportWindow(value, toolResult) {
10025
10028
  monthsText = "; rolling last ".concat(count, " month").concat(count === 1 ? '' : 's');
10026
10029
  }
10027
10030
  }
10028
- var line = "Report date range (UTC): ".concat(startDate, " to ").concat(endDate).concat(monthsText, ".");
10031
+ var line = "Report date range (UTC): ".concat(startDateDisplay, " to ").concat(endDateDisplay).concat(monthsText, ".");
10029
10032
  var normalizedLower = String(content || '').toLowerCase();
10030
- if (normalizedLower.includes(startDate.toLowerCase()) && normalizedLower.includes(endDate.toLowerCase())) {
10033
+ var hasRawDates = normalizedLower.includes(startDate.toLowerCase()) && normalizedLower.includes(endDate.toLowerCase());
10034
+ var hasDisplayDates = normalizedLower.includes(startDateDisplay.toLowerCase()) && normalizedLower.includes(endDateDisplay.toLowerCase());
10035
+ if (hasRawDates || hasDisplayDates) {
10031
10036
  return content || value || '';
10032
10037
  }
10033
10038
  if (!content) {
@@ -12200,28 +12205,38 @@ function isAssistantLikelyDateValue(value) {
12200
12205
  }
12201
12206
  return false;
12202
12207
  }
12203
- function formatAssistantDateValue(value) {
12208
+ function resolveAssistantDisplayDateFormatPreference() {
12209
+ var profile = resolveAssistantAppHeuristicProfile();
12210
+ return profile.displayDateFormat || 'mdy';
12211
+ }
12212
+ function formatAssistantDateValue(value, dateDisplayFormat) {
12213
+ if (dateDisplayFormat === void 0) { dateDisplayFormat = 'iso'; }
12204
12214
  var dateValue = value instanceof Date ? value : new Date(value);
12205
12215
  if (Number.isNaN(dateValue.getTime())) {
12206
12216
  return String(value);
12207
12217
  }
12208
- var iso = dateValue.toISOString();
12209
- var _a = __read(iso.split('T'), 2), datePart = _a[0], timePart = _a[1];
12210
- if (!timePart) {
12211
- return datePart || iso;
12212
- }
12213
- var trimmed = timePart.replace('Z', '');
12214
- if (trimmed.startsWith('00:00:00')) {
12218
+ var year = dateValue.getUTCFullYear();
12219
+ var month = "".concat(dateValue.getUTCMonth() + 1).padStart(2, '0');
12220
+ var day = "".concat(dateValue.getUTCDate()).padStart(2, '0');
12221
+ var datePart = dateDisplayFormat === 'mdy'
12222
+ ? "".concat(month, "/").concat(day, "/").concat(year)
12223
+ : "".concat(year, "-").concat(month, "-").concat(day);
12224
+ var hours = "".concat(dateValue.getUTCHours()).padStart(2, '0');
12225
+ var minutes = "".concat(dateValue.getUTCMinutes()).padStart(2, '0');
12226
+ var seconds = "".concat(dateValue.getUTCSeconds()).padStart(2, '0');
12227
+ var millis = dateValue.getUTCMilliseconds();
12228
+ if (hours === '00' && minutes === '00' && seconds === '00' && millis === 0) {
12215
12229
  return datePart;
12216
12230
  }
12217
- return "".concat(datePart, " ").concat(trimmed.slice(0, 5));
12231
+ return "".concat(datePart, " ").concat(hours, ":").concat(minutes);
12218
12232
  }
12219
- function formatAssistantDisplayCell(value, column) {
12233
+ function formatAssistantDisplayCell(value, column, dateDisplayFormat) {
12234
+ if (dateDisplayFormat === void 0) { dateDisplayFormat = 'iso'; }
12220
12235
  if (value === null || value === undefined || value === '') {
12221
12236
  return '';
12222
12237
  }
12223
12238
  if (Array.isArray(value)) {
12224
- return value.map(function (item) { return formatAssistantDisplayCell(item, column); }).filter(Boolean).join(', ');
12239
+ return value.map(function (item) { return formatAssistantDisplayCell(item, column, dateDisplayFormat); }).filter(Boolean).join(', ');
12225
12240
  }
12226
12241
  if (typeof value === 'string') {
12227
12242
  var normalizedCurrency = normalizeAssistantCurrencyText(value);
@@ -12237,7 +12252,7 @@ function formatAssistantDisplayCell(value, column) {
12237
12252
  }
12238
12253
  }
12239
12254
  if (isAssistantDateColumn(columnKey) && isAssistantLikelyDateValue(value)) {
12240
- return formatAssistantDateValue(value);
12255
+ return formatAssistantDateValue(value, dateDisplayFormat);
12241
12256
  }
12242
12257
  var numericValue = resolveAssistantNumericValue(value);
12243
12258
  if (numericValue !== null) {
@@ -12266,7 +12281,7 @@ function formatAssistantDisplayCell(value, column) {
12266
12281
  }
12267
12282
  }
12268
12283
  if (isAssistantLikelyDateValue(value) && isAssistantDateColumn(columnKey)) {
12269
- return formatAssistantDateValue(value);
12284
+ return formatAssistantDateValue(value, dateDisplayFormat);
12270
12285
  }
12271
12286
  return String(value);
12272
12287
  }
@@ -12281,12 +12296,13 @@ function formatDisplayTableMarkdown(display) {
12281
12296
  if (!display || !Array.isArray(display.columns) || !display.columns.length) {
12282
12297
  return '';
12283
12298
  }
12299
+ var dateDisplayFormat = resolveAssistantDisplayDateFormatPreference();
12284
12300
  var header = "| ".concat(display.columns.join(' | '), " |");
12285
12301
  var separator = "| ".concat(display.columns.map(function () { return '---'; }).join(' | '), " |");
12286
12302
  var rows = (display.rows || []).map(function (row) {
12287
12303
  var cells = display.columns.map(function (column) {
12288
12304
  var rawValue = row === null || row === void 0 ? void 0 : row[column];
12289
- var formatted = formatAssistantDisplayCell(rawValue, column);
12305
+ var formatted = formatAssistantDisplayCell(rawValue, column, dateDisplayFormat);
12290
12306
  return escapeMarkdownCell(formatted);
12291
12307
  });
12292
12308
  return "| ".concat(cells.join(' | '), " |");
@@ -17421,7 +17437,8 @@ function cloneAssistantHeuristicProfile(profile) {
17421
17437
  }); })
17422
17438
  : [],
17423
17439
  enabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.enabledDeterministicHeuristics) || [])),
17424
- disabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.disabledDeterministicHeuristics) || []))
17440
+ disabledDeterministicHeuristics: new Set(Array.from((profile === null || profile === void 0 ? void 0 : profile.disabledDeterministicHeuristics) || [])),
17441
+ displayDateFormat: profile === null || profile === void 0 ? void 0 : profile.displayDateFormat
17425
17442
  };
17426
17443
  }
17427
17444
  function mergeAssistantHeuristicProfiles(base, override) {
@@ -17448,8 +17465,28 @@ function mergeAssistantHeuristicProfiles(base, override) {
17448
17465
  merged.collectionTermHints = __spreadArray(__spreadArray([], __read(merged.collectionTermHints), false), __read((Array.isArray(override.collectionTermHints) ? override.collectionTermHints : [])), false);
17449
17466
  Array.from(override.enabledDeterministicHeuristics || []).forEach(function (value) { return merged.enabledDeterministicHeuristics.add(value); });
17450
17467
  Array.from(override.disabledDeterministicHeuristics || []).forEach(function (value) { return merged.disabledDeterministicHeuristics.add(value); });
17468
+ if (override.displayDateFormat) {
17469
+ merged.displayDateFormat = override.displayDateFormat;
17470
+ }
17451
17471
  return merged;
17452
17472
  }
17473
+ function normalizeAssistantDisplayDateFormat(value) {
17474
+ var normalized = normalizeOptionalString(value).toLowerCase();
17475
+ if (!normalized) {
17476
+ return undefined;
17477
+ }
17478
+ var compact = normalized.replace(/[^a-z0-9]/g, '');
17479
+ if (!compact) {
17480
+ return undefined;
17481
+ }
17482
+ if (compact === 'iso' || compact === 'isodate' || compact === 'yearfirst' || compact === 'yyyymmdd') {
17483
+ return 'iso';
17484
+ }
17485
+ if (compact === 'mdy' || compact === 'short' || compact === 'shortdate' || compact === 'mmddyyyy' || compact === 'datepipeshort') {
17486
+ return 'mdy';
17487
+ }
17488
+ return undefined;
17489
+ }
17453
17490
  function normalizeAssistantHeuristicStringList(value) {
17454
17491
  if (Array.isArray(value)) {
17455
17492
  return mergeAssistantHintValues(value.map(function (entry) { return normalizeOptionalString(entry).toLowerCase(); }));
@@ -17530,6 +17567,12 @@ function normalizeAssistantAppHeuristicProfile(value) {
17530
17567
  || value.collectionTermHints
17531
17568
  || value.term_hints
17532
17569
  || value.termHints);
17570
+ profile.displayDateFormat = normalizeAssistantDisplayDateFormat(value.display_date_format
17571
+ || value.displayDateFormat
17572
+ || value.date_display_format
17573
+ || value.dateDisplayFormat
17574
+ || value.table_date_format
17575
+ || value.tableDateFormat);
17533
17576
  var enabled = normalizeAssistantHeuristicStringList(value.enabled_deterministic_heuristics
17534
17577
  || value.enabledDeterministicHeuristics
17535
17578
  || value.enabled_heuristics