@resolveio/server-lib 9.0.32 → 9.0.34
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/client-server-app.js +7 -48
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +8 -11
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +8 -11
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +8 -11
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +9 -12
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +8 -11
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +8 -11
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +9 -12
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +8 -11
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +8 -11
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +11 -14
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +13 -16
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +16 -19
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +9 -12
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +10 -13
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +10 -13
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +13 -16
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +13 -16
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +15 -18
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +12 -15
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +12 -15
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +8 -11
- package/collections/notification.collection.js.map +1 -1
- package/collections/queue-flag.collection.js +9 -12
- package/collections/queue-flag.collection.js.map +1 -1
- package/collections/queue-method.collection.js +9 -12
- package/collections/queue-method.collection.js.map +1 -1
- package/collections/queue-response.collection.js +9 -12
- package/collections/queue-response.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +10 -13
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +11 -14
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +11 -14
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +11 -14
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +8 -11
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +12 -15
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +25 -25
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +30 -80
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +9 -59
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +344 -460
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -5
- package/http/health.js.map +1 -1
- package/http/home.js +7 -11
- package/http/home.js.map +1 -1
- package/index.js +36 -98
- package/index.js.map +1 -1
- package/managers/cron.manager.js +78 -157
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +323 -303
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +14 -14
- package/managers/mongo.manager.js +794 -865
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +171 -254
- package/managers/monitor.manager.js.map +1 -1
- package/managers/queue-method.manager.js +69 -166
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +515 -708
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +111 -183
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +156 -262
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +100 -180
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +114 -530
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +29 -79
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +819 -884
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -5
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +258 -313
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +289 -348
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +341 -340
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +565 -657
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +67 -185
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/billing-logged-in-users.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/email-history.model.js +1 -2
- package/models/email-verified.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log-method-latency.model.js +1 -2
- package/models/log-subscription.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/monitor-cpu.model.js +1 -2
- package/models/monitor-https-inbound.model.js +1 -2
- package/models/monitor-https-outbound.model.js +1 -2
- package/models/monitor-memory.model.js +1 -2
- package/models/monitor-mongo.model.js +1 -2
- package/models/notification.model.js +1 -2
- package/models/pagination.model.js +2 -5
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/report-builder-dashboard-builder.model.js +1 -2
- package/models/report-builder-library.model.js +1 -2
- package/models/report-builder-report.model.js +1 -2
- package/models/report-builder.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user-group.model.js +1 -2
- package/models/user-guide.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +1 -1
- package/public_api.js +70 -82
- package/public_api.js.map +1 -1
- package/publications/app-status.js +4 -8
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +4 -8
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +9 -13
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +11 -15
- package/publications/files.js.map +1 -1
- package/publications/flags.js +7 -11
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +31 -35
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +4 -8
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +4 -8
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +4 -8
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +8 -12
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +16 -66
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +17 -21
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +3 -7
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +4 -8
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +4 -8
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +393 -534
- package/server-app.js.map +1 -1
- package/util/common.js +55 -92
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +76 -134
- package/util/schema-report-builder.js.map +1 -1
package/managers/cron.manager.js
CHANGED
|
@@ -1,147 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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) {
|
|
1
|
+
import { CronJobs } from '../collections/cron-job.collection';
|
|
2
|
+
let CronJobManager = require('../cron/cron');
|
|
3
|
+
export class CronManager {
|
|
4
|
+
constructor(mainServer) {
|
|
44
5
|
this._mainServer = mainServer;
|
|
45
6
|
this._cronManager = new CronJobManager();
|
|
46
7
|
this.loadCronJobs();
|
|
47
8
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
});
|
|
9
|
+
async loadCronJobs() {
|
|
10
|
+
let jobs = await CronJobs.find({});
|
|
11
|
+
jobs.forEach(job => {
|
|
12
|
+
this.addCronJob(job);
|
|
63
13
|
});
|
|
64
|
-
}
|
|
65
|
-
|
|
14
|
+
}
|
|
15
|
+
doesCronJobExist(cron) {
|
|
66
16
|
return this._cronManager.exists(cron.name);
|
|
67
|
-
}
|
|
68
|
-
|
|
17
|
+
}
|
|
18
|
+
doesCronJobNameExist(cron_name) {
|
|
69
19
|
return this._cronManager.exists(cron_name);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
var _this = this;
|
|
20
|
+
}
|
|
21
|
+
addCronJob(cron) {
|
|
73
22
|
if (!this.doesCronJobExist(cron)) {
|
|
74
23
|
if (cron.timezone) {
|
|
75
24
|
}
|
|
76
25
|
else {
|
|
77
|
-
|
|
26
|
+
let cronOptions = {
|
|
78
27
|
start: true,
|
|
79
28
|
};
|
|
80
29
|
if (cron.timezone) {
|
|
81
30
|
cronOptions['timeZone'] = cron.timezone;
|
|
82
31
|
}
|
|
83
|
-
this._cronManager.add(cron.name, cron.time_to_run,
|
|
84
|
-
|
|
32
|
+
this._cronManager.add(cron.name, cron.time_to_run, () => {
|
|
33
|
+
this.runCronJob(cron);
|
|
85
34
|
}, cronOptions);
|
|
86
35
|
}
|
|
87
36
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
37
|
+
}
|
|
38
|
+
updateCronJob(cron) {
|
|
90
39
|
if (this.doesCronJobExist(cron)) {
|
|
91
40
|
this._cronManager.update(cron.name, cron.time_to_run);
|
|
92
41
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
42
|
+
}
|
|
43
|
+
removeCronJob(cron_name) {
|
|
95
44
|
if (this.doesCronJobNameExist(cron_name)) {
|
|
96
45
|
this._cronManager.deleteJob(cron_name);
|
|
97
46
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
47
|
+
}
|
|
48
|
+
startCronJob(cron) {
|
|
100
49
|
if (this.doesCronJobExist(cron)) {
|
|
101
50
|
this._cronManager.start(cron.name);
|
|
102
51
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
52
|
+
}
|
|
53
|
+
stopCronJob(cron) {
|
|
105
54
|
if (this.doesCronJobExist(cron)) {
|
|
106
55
|
this._cronManager.start(cron.name);
|
|
107
56
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
57
|
+
}
|
|
58
|
+
stopAllCronJobs() {
|
|
110
59
|
this._cronManager.stopAll();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
});
|
|
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);
|
|
138
72
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
73
|
+
// Update cronjobs
|
|
74
|
+
jobs.forEach(cronJob => {
|
|
75
|
+
this.updateCronJob(cronJob);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
runCronJob(cron) {
|
|
79
|
+
let now = new Date();
|
|
143
80
|
if (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {
|
|
144
|
-
|
|
81
|
+
CronJobs.findOneAndUpdate({
|
|
145
82
|
$and: [
|
|
146
83
|
{ _id: cron._id },
|
|
147
84
|
{ running: false },
|
|
@@ -153,54 +90,38 @@ var CronManager = /** @class */ (function () {
|
|
|
153
90
|
]
|
|
154
91
|
}
|
|
155
92
|
]
|
|
156
|
-
}, { $set: { running: true } }).then(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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*/];
|
|
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);
|
|
197
100
|
}
|
|
198
|
-
|
|
199
|
-
|
|
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
|
+
}, () => { });
|
|
200
123
|
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
}());
|
|
204
|
-
exports.CronManager = CronManager;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
205
126
|
|
|
206
127
|
//# sourceMappingURL=cron.manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/cron.manager.ts"],"names":[],"mappings":"
|
|
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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Ac,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,oBAAoB,CAAC,CAAC;yBACxG;6BACI;4BACJ,MAAM,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;yBAC9E;qBACD;oBAED,IAAI,GAAG,CAAC,MAAM,EAAE;wBACf,IAAI,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;wBAEjH,QAAQ,CAAC,SAAS,CAAC;4BAClB,IAAI,EAAE;gCACL,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC;gCACd,EAAC,OAAO,EAAE,IAAI,EAAC;6BACf;yBACD,EAAE,EAAC,IAAI,EAAE,EAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAC,EAAC,CAAC,CAAC;qBACjD;yBACI;wBACJ,QAAQ,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAC,CAAC,CAAC;qBACnC;iBACD;YACF,CAAC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;SACb;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}"]}
|