@resolveio/server-lib 9.0.34 → 9.0.35

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.
Files changed (192) hide show
  1. package/client-server-app.js +48 -7
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +11 -8
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +11 -8
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +11 -8
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +12 -9
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +11 -8
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +11 -8
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +12 -9
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +11 -8
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +11 -8
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +14 -11
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +16 -13
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +19 -16
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +12 -9
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +13 -10
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +13 -10
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +16 -13
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +16 -13
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +18 -15
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +15 -12
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +15 -12
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +11 -8
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +12 -9
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +12 -9
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +12 -9
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +13 -10
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +14 -11
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +14 -11
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +14 -11
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +11 -8
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +15 -12
  62. package/collections/user.collection.js.map +1 -1
  63. package/cron/cron.js +25 -25
  64. package/cron/cron.js.map +1 -1
  65. package/fixtures/cron-jobs.js +80 -30
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +59 -9
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +460 -344
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +5 -1
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +11 -7
  74. package/http/home.js.map +1 -1
  75. package/index.js +98 -36
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +157 -78
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +302 -314
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.js +1001 -739
  82. package/managers/mongo.manager.js.map +1 -1
  83. package/managers/monitor.manager.js +254 -171
  84. package/managers/monitor.manager.js.map +1 -1
  85. package/managers/queue-method.manager.js +166 -69
  86. package/managers/queue-method.manager.js.map +1 -1
  87. package/managers/subscription.manager.js +714 -515
  88. package/managers/subscription.manager.js.map +1 -1
  89. package/methods/accounts.js +183 -111
  90. package/methods/accounts.js.map +1 -1
  91. package/methods/aws.js +262 -156
  92. package/methods/aws.js.map +1 -1
  93. package/methods/cloudconvert.js +180 -100
  94. package/methods/cloudconvert.js.map +1 -1
  95. package/methods/collections.js +110 -103
  96. package/methods/collections.js.map +1 -1
  97. package/methods/counters.js +79 -29
  98. package/methods/counters.js.map +1 -1
  99. package/methods/cron-jobs.js +884 -819
  100. package/methods/cron-jobs.js.map +1 -1
  101. package/methods/flags.js +5 -1
  102. package/methods/flags.js.map +1 -1
  103. package/methods/logs.js +313 -258
  104. package/methods/logs.js.map +1 -1
  105. package/methods/monitor.js +348 -289
  106. package/methods/monitor.js.map +1 -1
  107. package/methods/pdf.js +340 -341
  108. package/methods/pdf.js.map +1 -1
  109. package/methods/report-builder.js +657 -565
  110. package/methods/report-builder.js.map +1 -1
  111. package/methods/support.js +185 -67
  112. package/methods/support.js.map +1 -1
  113. package/models/app-status.model.js +2 -1
  114. package/models/app-version.model.js +2 -1
  115. package/models/billing-logged-in-users.model.js +2 -1
  116. package/models/collection-document.model.js +2 -1
  117. package/models/counter.model.js +2 -1
  118. package/models/cron-job-history.model.js +2 -1
  119. package/models/cron-job.model.js +2 -1
  120. package/models/dialog.model.js +2 -1
  121. package/models/email-history.model.js +2 -1
  122. package/models/email-verified.model.js +2 -1
  123. package/models/file.model.js +2 -1
  124. package/models/flag.model.js +2 -1
  125. package/models/log-method-latency.model.js +2 -1
  126. package/models/log-subscription.model.js +2 -1
  127. package/models/log.model.js +2 -1
  128. package/models/logged-in-users.model.js +2 -1
  129. package/models/method-call.model.js +2 -1
  130. package/models/method-response.model.js +2 -1
  131. package/models/method.model.js +2 -1
  132. package/models/monitor-cpu.model.js +2 -1
  133. package/models/monitor-https-inbound.model.js +2 -1
  134. package/models/monitor-https-outbound.model.js +2 -1
  135. package/models/monitor-memory.model.js +2 -1
  136. package/models/monitor-mongo.model.js +2 -1
  137. package/models/notification.model.js +2 -1
  138. package/models/pagination.model.js +5 -2
  139. package/models/pagination.model.js.map +1 -1
  140. package/models/permission.model.js +2 -1
  141. package/models/queue-method.model.js +2 -1
  142. package/models/queue-response.model.js +2 -1
  143. package/models/report-builder-dashboard-builder.model.js +2 -1
  144. package/models/report-builder-library.model.js +2 -1
  145. package/models/report-builder-report.model.js +2 -1
  146. package/models/report-builder.model.js +2 -1
  147. package/models/select-data-label.model.js +2 -1
  148. package/models/server-response.model.js +2 -1
  149. package/models/subscription.model.js +2 -1
  150. package/models/support-ticket.model.js +2 -1
  151. package/models/user-group.model.js +2 -1
  152. package/models/user-guide.model.js +2 -1
  153. package/models/user.model.js +2 -1
  154. package/package.json +1 -1
  155. package/public_api.js +82 -70
  156. package/public_api.js.map +1 -1
  157. package/publications/app-status.js +8 -4
  158. package/publications/app-status.js.map +1 -1
  159. package/publications/app-version.js +8 -4
  160. package/publications/app-version.js.map +1 -1
  161. package/publications/cron-jobs.js +13 -9
  162. package/publications/cron-jobs.js.map +1 -1
  163. package/publications/files.js +15 -11
  164. package/publications/files.js.map +1 -1
  165. package/publications/flags.js +11 -7
  166. package/publications/flags.js.map +1 -1
  167. package/publications/logs.js +35 -31
  168. package/publications/logs.js.map +1 -1
  169. package/publications/method-calls.js +8 -4
  170. package/publications/method-calls.js.map +1 -1
  171. package/publications/method-responses.js +8 -4
  172. package/publications/method-responses.js.map +1 -1
  173. package/publications/notifications.js +8 -4
  174. package/publications/notifications.js.map +1 -1
  175. package/publications/report-builder-dashboard-builders.js +12 -8
  176. package/publications/report-builder-dashboard-builders.js.map +1 -1
  177. package/publications/report-builder-libraries.js +66 -16
  178. package/publications/report-builder-libraries.js.map +1 -1
  179. package/publications/report-builder-reports.js +21 -17
  180. package/publications/report-builder-reports.js.map +1 -1
  181. package/publications/super-admin.js +7 -3
  182. package/publications/super-admin.js.map +1 -1
  183. package/publications/user-groups.js +8 -4
  184. package/publications/user-groups.js.map +1 -1
  185. package/publications/user-guides.js +8 -4
  186. package/publications/user-guides.js.map +1 -1
  187. package/server-app.js +534 -393
  188. package/server-app.js.map +1 -1
  189. package/util/common.js +92 -55
  190. package/util/common.js.map +1 -1
  191. package/util/schema-report-builder.js +134 -76
  192. package/util/schema-report-builder.js.map +1 -1
@@ -1,84 +1,147 @@
1
- import { CronJobs } from '../collections/cron-job.collection';
2
- let CronJobManager = require('../cron/cron');
3
- export class CronManager {
4
- constructor(mainServer) {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.CronManager = void 0;
40
+ var cron_job_collection_1 = require("../collections/cron-job.collection");
41
+ var CronJobManager = require('../cron/cron');
42
+ var CronManager = /** @class */ (function () {
43
+ function CronManager(mainServer) {
5
44
  this._mainServer = mainServer;
6
45
  this._cronManager = new CronJobManager();
7
46
  this.loadCronJobs();
8
47
  }
9
- async loadCronJobs() {
10
- let jobs = await CronJobs.find({});
11
- jobs.forEach(job => {
12
- this.addCronJob(job);
48
+ CronManager.prototype.loadCronJobs = function () {
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var jobs;
51
+ var _this = this;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0: return [4 /*yield*/, cron_job_collection_1.CronJobs.find({})];
55
+ case 1:
56
+ jobs = _a.sent();
57
+ jobs.forEach(function (job) {
58
+ _this.addCronJob(job);
59
+ });
60
+ return [2 /*return*/];
61
+ }
62
+ });
13
63
  });
14
- }
15
- doesCronJobExist(cron) {
64
+ };
65
+ CronManager.prototype.doesCronJobExist = function (cron) {
16
66
  return this._cronManager.exists(cron.name);
17
- }
18
- doesCronJobNameExist(cron_name) {
67
+ };
68
+ CronManager.prototype.doesCronJobNameExist = function (cron_name) {
19
69
  return this._cronManager.exists(cron_name);
20
- }
21
- addCronJob(cron) {
70
+ };
71
+ CronManager.prototype.addCronJob = function (cron) {
72
+ var _this = this;
22
73
  if (!this.doesCronJobExist(cron)) {
23
74
  if (cron.timezone) {
24
75
  }
25
76
  else {
26
- let cronOptions = {
77
+ var cronOptions = {
27
78
  start: true,
28
79
  };
29
80
  if (cron.timezone) {
30
81
  cronOptions['timeZone'] = cron.timezone;
31
82
  }
32
- this._cronManager.add(cron.name, cron.time_to_run, () => {
33
- this.runCronJob(cron);
83
+ this._cronManager.add(cron.name, cron.time_to_run, function () {
84
+ _this.runCronJob(cron);
34
85
  }, cronOptions);
35
86
  }
36
87
  }
37
- }
38
- updateCronJob(cron) {
88
+ };
89
+ CronManager.prototype.updateCronJob = function (cron) {
39
90
  if (this.doesCronJobExist(cron)) {
40
91
  this._cronManager.update(cron.name, cron.time_to_run);
41
92
  }
42
- }
43
- removeCronJob(cron_name) {
93
+ };
94
+ CronManager.prototype.removeCronJob = function (cron_name) {
44
95
  if (this.doesCronJobNameExist(cron_name)) {
45
96
  this._cronManager.deleteJob(cron_name);
46
97
  }
47
- }
48
- startCronJob(cron) {
98
+ };
99
+ CronManager.prototype.startCronJob = function (cron) {
49
100
  if (this.doesCronJobExist(cron)) {
50
101
  this._cronManager.start(cron.name);
51
102
  }
52
- }
53
- stopCronJob(cron) {
103
+ };
104
+ CronManager.prototype.stopCronJob = function (cron) {
54
105
  if (this.doesCronJobExist(cron)) {
55
106
  this._cronManager.start(cron.name);
56
107
  }
57
- }
58
- stopAllCronJobs() {
108
+ };
109
+ CronManager.prototype.stopAllCronJobs = function () {
59
110
  this._cronManager.stopAll();
60
- }
61
- async checkCronJobsForUpdates() {
62
- let jobs = await CronJobs.find({});
63
- // Remove deleted cron jobs
64
- this._cronManager.getJobs().forEach(cronJob => {
65
- if (jobs.map(a => a.name).indexOf(cronJob) === -1) {
66
- this.removeCronJob(cronJob);
67
- }
68
- });
69
- // Add new cron jobs
70
- jobs.forEach(cronJob => {
71
- this.addCronJob(cronJob);
72
- });
73
- // Update cronjobs
74
- jobs.forEach(cronJob => {
75
- this.updateCronJob(cronJob);
111
+ };
112
+ CronManager.prototype.checkCronJobsForUpdates = function () {
113
+ return __awaiter(this, void 0, void 0, function () {
114
+ var jobs;
115
+ var _this = this;
116
+ return __generator(this, function (_a) {
117
+ switch (_a.label) {
118
+ case 0: return [4 /*yield*/, cron_job_collection_1.CronJobs.find({})];
119
+ case 1:
120
+ jobs = _a.sent();
121
+ // Remove deleted cron jobs
122
+ this._cronManager.getJobs().forEach(function (cronJob) {
123
+ if (jobs.map(function (a) { return a.name; }).indexOf(cronJob) === -1) {
124
+ _this.removeCronJob(cronJob);
125
+ }
126
+ });
127
+ // Add new cron jobs
128
+ jobs.forEach(function (cronJob) {
129
+ _this.addCronJob(cronJob);
130
+ });
131
+ // Update cronjobs
132
+ jobs.forEach(function (cronJob) {
133
+ _this.updateCronJob(cronJob);
134
+ });
135
+ return [2 /*return*/];
136
+ }
137
+ });
76
138
  });
77
- }
78
- runCronJob(cron) {
79
- let now = new Date();
139
+ };
140
+ CronManager.prototype.runCronJob = function (cron) {
141
+ var _this = this;
142
+ var now = new Date();
80
143
  if (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {
81
- CronJobs.findOneAndUpdate({
144
+ cron_job_collection_1.CronJobs.findOneAndUpdate({
82
145
  $and: [
83
146
  { _id: cron._id },
84
147
  { running: false },
@@ -90,38 +153,54 @@ export class CronManager {
90
153
  ]
91
154
  }
92
155
  ]
93
- }, { $set: { running: true } }).then(async (res) => {
94
- if (res) {
95
- if (res.method_run_data) {
96
- await this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);
97
- }
98
- else {
99
- await this._mainServer.getMethodManager().callMethodCron(res.method_run);
156
+ }, { $set: { running: true } }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
157
+ var nextDate;
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0:
161
+ if (!res) return [3 /*break*/, 9];
162
+ if (!res.method_run_data) return [3 /*break*/, 2];
163
+ return [4 /*yield*/, this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data)];
164
+ case 1:
165
+ _a.sent();
166
+ return [3 /*break*/, 4];
167
+ case 2: return [4 /*yield*/, this._mainServer.getMethodManager().callMethodCron(res.method_run)];
168
+ case 3:
169
+ _a.sent();
170
+ _a.label = 4;
171
+ case 4:
172
+ if (!res.method_complete) return [3 /*break*/, 8];
173
+ if (!res.method_complete_data) return [3 /*break*/, 6];
174
+ return [4 /*yield*/, this._mainServer.getMethodManager().callMethodCron(res.method_complete, res.method_complete_data)];
175
+ case 5:
176
+ _a.sent();
177
+ return [3 /*break*/, 8];
178
+ case 6: return [4 /*yield*/, this._mainServer.getMethodManager().callMethodCron(res.method_complete)];
179
+ case 7:
180
+ _a.sent();
181
+ _a.label = 8;
182
+ case 8:
183
+ if (res.repeat) {
184
+ nextDate = this._cronManager.getJob(res.name).nextDates().second(0).millisecond(0).toDate();
185
+ cron_job_collection_1.CronJobs.updateOne({
186
+ $and: [
187
+ { _id: res._id },
188
+ { running: true }
189
+ ]
190
+ }, { $set: { running: false, next_run: nextDate } });
191
+ }
192
+ else {
193
+ cron_job_collection_1.CronJobs.deleteOne({ _id: res._id });
194
+ }
195
+ _a.label = 9;
196
+ case 9: return [2 /*return*/];
100
197
  }
101
- if (res.method_complete) {
102
- if (res.method_complete_data) {
103
- await this._mainServer.getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);
104
- }
105
- else {
106
- await this._mainServer.getMethodManager().callMethodCron(res.method_complete);
107
- }
108
- }
109
- if (res.repeat) {
110
- let nextDate = this._cronManager.getJob(res.name).nextDates().second(0).millisecond(0).toDate();
111
- CronJobs.updateOne({
112
- $and: [
113
- { _id: res._id },
114
- { running: true }
115
- ]
116
- }, { $set: { running: false, next_run: nextDate } });
117
- }
118
- else {
119
- CronJobs.deleteOne({ _id: res._id });
120
- }
121
- }
122
- }, () => { });
198
+ });
199
+ }); }, function () { });
123
200
  }
124
- }
125
- }
201
+ };
202
+ return CronManager;
203
+ }());
204
+ exports.CronManager = CronManager;
126
205
 
127
206
  //# sourceMappingURL=cron.manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAG7C,MAAM,OAAO,WAAW;IAKvB,YAAY,UAAU;QACrB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,YAAY;QACzB,IAAI,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAClB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,gBAAgB,CAAC,IAAkB;QAC1C,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAEO,oBAAoB,CAAC,SAAiB;QAC7C,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAEO,UAAU,CAAC,IAAkB;QACpC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE;YACjC,IAAI,IAAI,CAAC,QAAQ,EAAE;aAElB;iBACI;gBACJ,IAAI,WAAW,GAAG;oBACjB,KAAK,EAAE,IAAI;iBAKX,CAAC;gBAEF,IAAI,IAAI,CA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b;IACF,CAAC;CACD","file":"cron.manager.js","sourcesContent":["import { CronJobModel } from '../models/cron-job.model';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport ResolveIOMainServer from '../server-app';\nlet CronJobManager = require('../cron/cron');\nimport * as moment from 'moment';\n\nexport class CronManager {\n\n\tprivate _cronManager;\n\tprivate _mainServer: ResolveIOMainServer;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tthis._cronManager = new CronJobManager();\n\t\tthis.loadCronJobs();\n\t}\n\n\tprivate async loadCronJobs() {\n\t\tlet jobs = await CronJobs.find({});\n\n\t\tjobs.forEach(job => {\n\t\t\tthis.addCronJob(job);\n\t\t});\n\t}\n\n\tprivate doesCronJobExist(cron: CronJobModel) {\n\t\treturn this._cronManager.exists(cron.name);\n\t}\n\n\tprivate doesCronJobNameExist(cron_name: string) {\n\t\treturn this._cronManager.exists(cron_name);\n\t}\n\n\tprivate addCronJob(cron: CronJobModel) {\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\tif (cron.timezone) {\n\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet cronOptions = {\n\t\t\t\t\tstart: true,\n\t\t\t\t\t// onComplete: () => {\n\t\t\t\t\t// \tthis.runCronJobCompleted(cron);\n\t\t\t\t\t// },\n\t\t\t\t\t// timeZone: cron.timezone\n\t\t\t\t};\n\n\t\t\t\tif (cron.timezone) {\n\t\t\t\t\tcronOptions['timeZone'] = cron.timezone;\n\t\t\t\t}\n\n\t\t\t\tthis._cronManager.add(\n\t\t\t\t\tcron.name,\n\t\t\t\t\tcron.time_to_run,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.runCronJob(cron);\n\t\t\t\t\t},\n\t\t\t\t\tcronOptions\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.update(cron.name, cron.time_to_run);\n\t\t}\n\t}\n\n\tprivate removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tthis._cronManager.deleteJob(cron_name);\n\t\t}\n\t}\n\n\tprivate startCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopAllCronJobs() {\n\t\tthis._cronManager.stopAll();\n\t}\n\n\tpublic async checkCronJobsForUpdates() {\n\t\tlet jobs = await CronJobs.find({});\n\n\t\t// Remove deleted cron jobs\n\t\tthis._cronManager.getJobs().forEach(cronJob => {\n\t\t\tif (jobs.map(a => a.name).indexOf(cronJob) === -1) {\n\t\t\t\tthis.removeCronJob(cronJob);\n\t\t\t}\n\t\t});\n\n\t\t// Add new cron jobs\n\t\tjobs.forEach(cronJob => {\n\t\t\tthis.addCronJob(cronJob);\n\t\t});\n\n\t\t// Update cronjobs\n\t\tjobs.forEach(cronJob => {\n\t\t\tthis.updateCronJob(cronJob);\n\t\t});\n\t}\n\n\tprivate runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tif (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {\n\n\t\t\tCronJobs.findOneAndUpdate({\n\t\t\t\t$and: [\n\t\t\t\t\t{_id: cron._id},\n\t\t\t\t\t{running: false},\n\t\t\t\t\t{\n\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = (<moment.Moment>this._cronManager.getJob(res.name).nextDates()).second(0).millisecond(0).toDate();\n\n\t\t\t\t\t\tCronJobs.updateOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: res._id},\n\t\t\t\t\t\t\t\t{running: true}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0EAA8D;AAE9D,IAAI,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAG7C;IAKC,qBAAY,UAAU;QACrB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,EAAE,CAAC;QACzC,IAAI,CAAC,YAAY,EAAE,CAAC;IACrB,CAAC;IAEa,kCAAY,GAA1B;;;;;;4BACY,qBAAM,8BAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAA;;wBAA9B,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;gCAGxG,qBAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,EAAA;;4BAA7E,SAA6E,CAAC;;;4BAIhF,IAAI,GAAG,CAAC,MAAM,EAAE;gCACX,QAAQ,GAAmB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,SAAS,EAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;gCAEjH,8BAAQ,CAAC,SAAS,CAAC;oCAClB,IAAI,EAAE;wCACL,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC;wCACd,EAAC,OAAO,EAAE,IAAI,EAAC;qCACf;iCACD,EAAE,EAAC,IAAI,EAAE,EAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAC,EAAC,CAAC,CAAC;6BACjD;iCACI;gCACJ,8BAAQ,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC,CAAC,CAAC;6BACnC;;;;;iBAEF,EAAE,cAAO,CAAC,CAAC,CAAC;SACb;IACF,CAAC;IACF,kBAAC;AAAD,CA/JA,AA+JC,IAAA;AA/JY,kCAAW","file":"cron.manager.js","sourcesContent":["import { CronJobModel } from '../models/cron-job.model';\nimport { CronJobs } from '../collections/cron-job.collection';\nimport ResolveIOMainServer from '../server-app';\nlet CronJobManager = require('../cron/cron');\nimport * as moment from 'moment';\n\nexport class CronManager {\n\n\tprivate _cronManager;\n\tprivate _mainServer: ResolveIOMainServer;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tthis._cronManager = new CronJobManager();\n\t\tthis.loadCronJobs();\n\t}\n\n\tprivate async loadCronJobs() {\n\t\tlet jobs = await CronJobs.find({});\n\n\t\tjobs.forEach(job => {\n\t\t\tthis.addCronJob(job);\n\t\t});\n\t}\n\n\tprivate doesCronJobExist(cron: CronJobModel) {\n\t\treturn this._cronManager.exists(cron.name);\n\t}\n\n\tprivate doesCronJobNameExist(cron_name: string) {\n\t\treturn this._cronManager.exists(cron_name);\n\t}\n\n\tprivate addCronJob(cron: CronJobModel) {\n\t\tif (!this.doesCronJobExist(cron)) {\n\t\t\tif (cron.timezone) {\n\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlet cronOptions = {\n\t\t\t\t\tstart: true,\n\t\t\t\t\t// onComplete: () => {\n\t\t\t\t\t// \tthis.runCronJobCompleted(cron);\n\t\t\t\t\t// },\n\t\t\t\t\t// timeZone: cron.timezone\n\t\t\t\t};\n\n\t\t\t\tif (cron.timezone) {\n\t\t\t\t\tcronOptions['timeZone'] = cron.timezone;\n\t\t\t\t}\n\n\t\t\t\tthis._cronManager.add(\n\t\t\t\t\tcron.name,\n\t\t\t\t\tcron.time_to_run,\n\t\t\t\t\t() => {\n\t\t\t\t\t\tthis.runCronJob(cron);\n\t\t\t\t\t},\n\t\t\t\t\tcronOptions\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.update(cron.name, cron.time_to_run);\n\t\t}\n\t}\n\n\tprivate removeCronJob(cron_name: string) {\n\t\tif (this.doesCronJobNameExist(cron_name)) {\n\t\t\tthis._cronManager.deleteJob(cron_name);\n\t\t}\n\t}\n\n\tprivate startCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopCronJob(cron: CronJobModel) {\n\t\tif (this.doesCronJobExist(cron)) {\n\t\t\tthis._cronManager.start(cron.name);\n\t\t}\n\t}\n\n\tprivate stopAllCronJobs() {\n\t\tthis._cronManager.stopAll();\n\t}\n\n\tpublic async checkCronJobsForUpdates() {\n\t\tlet jobs = await CronJobs.find({});\n\n\t\t// Remove deleted cron jobs\n\t\tthis._cronManager.getJobs().forEach(cronJob => {\n\t\t\tif (jobs.map(a => a.name).indexOf(cronJob) === -1) {\n\t\t\t\tthis.removeCronJob(cronJob);\n\t\t\t}\n\t\t});\n\n\t\t// Add new cron jobs\n\t\tjobs.forEach(cronJob => {\n\t\t\tthis.addCronJob(cronJob);\n\t\t});\n\n\t\t// Update cronjobs\n\t\tjobs.forEach(cronJob => {\n\t\t\tthis.updateCronJob(cronJob);\n\t\t});\n\t}\n\n\tprivate runCronJob(cron: CronJobModel) {\n\t\tlet now = new Date();\n\n\t\tif (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {\n\n\t\t\tCronJobs.findOneAndUpdate({\n\t\t\t\t$and: [\n\t\t\t\t\t{_id: cron._id},\n\t\t\t\t\t{running: false},\n\t\t\t\t\t{\n\t\t\t\t\t\t$or: [\n\t\t\t\t\t\t\t{next_run: {$exists: false}},\n\t\t\t\t\t\t\t{next_run: null},\n\t\t\t\t\t\t\t{next_run: {$lte: now}}\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}, {$set: {running: true}}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\tif (res.method_run_data) {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run, res.method_run_data);\t\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_run);\n\t\t\t\t\t}\n\t\n\t\t\t\t\tif (res.method_complete) {\n\t\t\t\t\t\tif (res.method_complete_data) {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete, res.method_complete_data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodCron(res.method_complete);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (res.repeat) {\n\t\t\t\t\t\tlet nextDate = (<moment.Moment>this._cronManager.getJob(res.name).nextDates()).second(0).millisecond(0).toDate();\n\n\t\t\t\t\t\tCronJobs.updateOne({\n\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t{_id: res._id},\n\t\t\t\t\t\t\t\t{running: true}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}, {$set: {running: false, next_run: nextDate}});\n\t\t\t\t\t} \n\t\t\t\t\telse {\n\t\t\t\t\t\tCronJobs.deleteOne({_id: res._id});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n}"]}