mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛 Fixed post scheduling (#8976)
closes #8975
- recursive logic was broken
- caused via bf47397ac2
This commit is contained in:
parent
69657a1ac6
commit
d460cf1291
2 changed files with 36 additions and 18 deletions
|
@ -54,7 +54,8 @@ SchedulingDefault.prototype.unschedule = function (object) {
|
|||
*/
|
||||
SchedulingDefault.prototype.run = function () {
|
||||
var self = this,
|
||||
timeout = null;
|
||||
timeout = null,
|
||||
recursiveRun;
|
||||
|
||||
if (this.isRunning) {
|
||||
return;
|
||||
|
@ -62,27 +63,30 @@ SchedulingDefault.prototype.run = function () {
|
|||
|
||||
this.isRunning = true;
|
||||
|
||||
timeout = setTimeout(function () {
|
||||
var times = Object.keys(self.allJobs),
|
||||
nextJobs = {};
|
||||
recursiveRun = function recursiveRun() {
|
||||
timeout = setTimeout(function () {
|
||||
var times = Object.keys(self.allJobs),
|
||||
nextJobs = {};
|
||||
|
||||
times.every(function (time) {
|
||||
if (moment(Number(time)).diff(moment(), 'minutes') <= self.offsetInMinutes) {
|
||||
nextJobs[time] = self.allJobs[time];
|
||||
delete self.allJobs[time];
|
||||
return true;
|
||||
}
|
||||
times.every(function (time) {
|
||||
if (moment(Number(time)).diff(moment(), 'minutes') <= self.offsetInMinutes) {
|
||||
nextJobs[time] = self.allJobs[time];
|
||||
delete self.allJobs[time];
|
||||
return true;
|
||||
}
|
||||
|
||||
// break!
|
||||
return false;
|
||||
});
|
||||
// break!
|
||||
return false;
|
||||
});
|
||||
|
||||
clearTimeout(timeout);
|
||||
self._execute(nextJobs);
|
||||
clearTimeout(timeout);
|
||||
self._execute(nextJobs);
|
||||
|
||||
// recursive!
|
||||
self.run();
|
||||
}, self.runTimeoutInMs);
|
||||
recursiveRun();
|
||||
}, self.runTimeoutInMs);
|
||||
};
|
||||
|
||||
recursiveRun();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,6 +84,20 @@ describe('Scheduling Default Adapter', function () {
|
|||
scope.adapter.run();
|
||||
});
|
||||
|
||||
it('ensure recursive run works', function (done) {
|
||||
sandbox.spy(scope.adapter, '_execute');
|
||||
|
||||
scope.adapter.allJobs = {};
|
||||
scope.adapter.runTimeoutInMs = 500;
|
||||
scope.adapter.offsetInMinutes = 2;
|
||||
scope.adapter.run();
|
||||
|
||||
setTimeout(function () {
|
||||
scope.adapter._execute.callCount.should.be.greaterThan(1);
|
||||
done();
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
it('execute', function (done) {
|
||||
var pinged = 0,
|
||||
jobs = 3,
|
||||
|
|
Loading…
Add table
Reference in a new issue