@resolveio/server-lib 3.2.2 → 3.2.3
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/managers/cron.manager.js +11 -8
- package/package.json +1 -1
package/managers/cron.manager.js
CHANGED
|
@@ -138,18 +138,20 @@ var CronManager = /** @class */ (function () {
|
|
|
138
138
|
CronManager.prototype.runCronJob = function (cron) {
|
|
139
139
|
var _this = this;
|
|
140
140
|
var now = new Date();
|
|
141
|
-
|
|
142
|
-
if (cron.next_run) {
|
|
143
|
-
cronRunTime = cron.next_run;
|
|
144
|
-
cronRunTime.setSeconds(0, 0);
|
|
145
|
-
}
|
|
146
|
-
if (!cron.next_run || now.getTime() >= cronRunTime.getTime()) {
|
|
141
|
+
if (!cron.next_run || now.getTime() >= cron.next_run.getTime()) {
|
|
147
142
|
cron_job_collection_1.CronJobs.findOneAndUpdate({
|
|
148
143
|
$and: [
|
|
149
144
|
{ _id: cron._id },
|
|
150
|
-
{ running: false }
|
|
145
|
+
{ running: false },
|
|
146
|
+
{
|
|
147
|
+
$or: [
|
|
148
|
+
{ next_run: { $exists: false } },
|
|
149
|
+
{ next_run: { $lte: now } }
|
|
150
|
+
]
|
|
151
|
+
}
|
|
151
152
|
]
|
|
152
153
|
}, { $set: { running: true } }).exec(function (err, res) { return __awaiter(_this, void 0, void 0, function () {
|
|
154
|
+
var nextDate;
|
|
153
155
|
return __generator(this, function (_a) {
|
|
154
156
|
switch (_a.label) {
|
|
155
157
|
case 0:
|
|
@@ -176,12 +178,13 @@ var CronManager = /** @class */ (function () {
|
|
|
176
178
|
_a.label = 8;
|
|
177
179
|
case 8:
|
|
178
180
|
if (cron.repeat) {
|
|
181
|
+
nextDate = (this._cronManager.getJob(cron.name).nextDates().toDate()).setSeconds(0, 0);
|
|
179
182
|
cron_job_collection_1.CronJobs.updateOne({
|
|
180
183
|
$and: [
|
|
181
184
|
{ _id: cron._id },
|
|
182
185
|
{ running: true }
|
|
183
186
|
]
|
|
184
|
-
}, { $set: { running: false, next_run:
|
|
187
|
+
}, { $set: { running: false, next_run: nextDate } }).exec();
|
|
185
188
|
}
|
|
186
189
|
else {
|
|
187
190
|
cron_job_collection_1.CronJobs.deleteOne({ _id: cron._id }).exec();
|