@pulsecron/pulse
Advanced tools
Comparing version 1.6.6 to 1.6.7
@@ -6,3 +6,2 @@ "use strict"; | ||
const debug_1 = tslib_1.__importDefault(require("debug")); | ||
const job_1 = require("../job"); | ||
const debug = (0, debug_1.default)('pulse:resumeOnRestart'); | ||
@@ -16,40 +15,13 @@ const resumeOnRestart = function (resume = true) { | ||
.updateMany({ | ||
$and: [ | ||
{ repeatInterval: { $exists: false } }, | ||
{ repeatAt: { $exists: false } }, | ||
$or: [ | ||
{ | ||
$or: [ | ||
{ | ||
lockedAt: { $exists: true }, | ||
$and: [ | ||
{ | ||
$or: [ | ||
{ nextRunAt: { $lte: now, $ne: null } }, | ||
{ nextRunAt: { $exists: false } }, | ||
{ nextRunAt: null }, | ||
], | ||
}, | ||
{ | ||
$or: [ | ||
{ $expr: { $eq: ['$runCount', '$finishedCount'] } }, | ||
{ $or: [{ lastFinishedAt: { $exists: false } }, { lastFinishedAt: null }] }, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
lockedAt: { $exists: false }, | ||
$and: [ | ||
{ | ||
$or: [ | ||
{ nextRunAt: { $lte: now, $ne: null } }, | ||
{ nextRunAt: { $exists: false } }, | ||
{ nextRunAt: null }, | ||
], | ||
}, | ||
{ $or: [{ lastFinishedAt: { $exists: false } }, { lastFinishedAt: null }] }, | ||
], | ||
}, | ||
], | ||
lockedAt: { $exists: true }, | ||
nextRunAt: { $ne: null }, | ||
$or: [{ $expr: { $eq: ['$runCount', '$finishedCount'] } }, { lastFinishedAt: { $exists: false } }], | ||
}, | ||
{ | ||
lockedAt: { $exists: false }, | ||
lastFinishedAt: { $exists: false }, | ||
nextRunAt: { $lte: now, $ne: null }, | ||
}, | ||
], | ||
@@ -62,53 +34,5 @@ }, { | ||
if (result.modifiedCount > 0) { | ||
debug('Resumed %d unfinished standard jobs (%s)', result.modifiedCount, now.toISOString()); | ||
debug('resuming unfinished %d jobs(%s)', result.modifiedCount, now.toISOString()); | ||
} | ||
}); | ||
this._collection | ||
.find({ | ||
$and: [ | ||
{ $or: [{ repeatInterval: { $exists: true } }, { repeatAt: { $exists: true } }] }, | ||
{ | ||
$or: [ | ||
{ nextRunAt: { $lte: now } }, | ||
{ nextRunAt: { $exists: false } }, | ||
{ nextRunAt: null }, | ||
], | ||
}, | ||
{ | ||
$or: [ | ||
{ lastFinishedAt: { $exists: false } }, | ||
{ lastFinishedAt: { $lte: now } }, | ||
{ lastFinishedAt: null }, | ||
], | ||
}, | ||
], | ||
}) | ||
.toArray() | ||
.then((jobs) => { | ||
const updates = jobs.map((jobData) => { | ||
const job = new job_1.Job({ | ||
pulse: this, | ||
name: jobData.name || '', | ||
data: jobData.data || {}, | ||
type: jobData.type || 'normal', | ||
priority: jobData.priority || 'normal', | ||
shouldSaveResult: jobData.shouldSaveResult || false, | ||
attempts: jobData.attempts || 0, | ||
backoff: jobData.backoff, | ||
...jobData, | ||
}); | ||
job.computeNextRunAt(); | ||
return this._collection.updateOne({ _id: job.attrs._id }, { | ||
$set: { nextRunAt: job.attrs.nextRunAt }, | ||
$unset: { lockedAt: undefined, lastModifiedBy: undefined, lastRunAt: undefined }, | ||
}); | ||
}); | ||
return Promise.all(updates); | ||
}) | ||
.then((results) => { | ||
const modifiedCount = results.filter((res) => res.modifiedCount > 0).length; | ||
if (modifiedCount > 0) { | ||
debug('Resumed %d recurring jobs (%s)', modifiedCount, now.toISOString()); | ||
} | ||
}); | ||
} | ||
@@ -115,0 +39,0 @@ return this; |
{ | ||
"name": "@pulsecron/pulse", | ||
"version": "1.6.6", | ||
"version": "1.6.7", | ||
"description": "The modern MongoDB-powered job scheduler library for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
187277
2220