Comparing version 0.0.9 to 0.0.10
@@ -163,5 +163,5 @@ "use strict"; | ||
this._models.Dronos.findOne( { | ||
owner: schedule.owner || '', | ||
name: schedule.name || '' | ||
}, function( err, schedule ) { | ||
owner: schedule.owner || '', | ||
name: schedule.name || '' | ||
}, function( err, schedule ) { | ||
if ( err ) { | ||
@@ -194,5 +194,5 @@ done( err ); | ||
this._models.Dronos.remove( { | ||
owner: schedule.owner || '', | ||
name: schedule.name || '' | ||
}, function( err, count ) { | ||
owner: schedule.owner || '', | ||
name: schedule.name || '' | ||
}, function( err, count ) { | ||
if ( err ) { | ||
@@ -344,90 +344,90 @@ done( err ); | ||
self._models.Dronos.find( { | ||
_nextRun: { $lt: moment().toISOString() } | ||
}, | ||
function( err, schedules ) { | ||
_nextRun: { $lt: moment().toISOString() } | ||
}, | ||
function( err, schedules ) { | ||
if ( self._running === false ) { | ||
done(); | ||
return; | ||
} | ||
if ( self._running === false ) { | ||
done(); | ||
return; | ||
} | ||
if ( !Array.isArray( schedules ) || schedules.length < 1 ) { | ||
done(); | ||
return; | ||
} | ||
if ( !Array.isArray( schedules ) || schedules.length < 1 ) { | ||
done(); | ||
return; | ||
} | ||
// if we got some schedules to run, and we are not shutting down, | ||
// run each in parallel according to batch size. | ||
async.eachLimit( schedules, self._params.batchSize, function( schedule, done ) { | ||
// if we got some schedules to run, and we are not shutting down, | ||
// run each in parallel according to batch size. | ||
async.eachLimit( schedules, self._params.batchSize, function( schedule, done ) { | ||
// before attempting to run each schedule, see if we are shutting down | ||
if ( self._running === false ) { | ||
done( true ); | ||
return; | ||
} | ||
// before attempting to run each schedule, see if we are shutting down | ||
if ( self._running === false ) { | ||
done( true ); | ||
return; | ||
} | ||
var nextRun = getNextRun( schedule ); | ||
var nextRun = getNextRun( schedule ); | ||
if ( !nextRun ) { | ||
nextRun = moment().add( 1000, 'years' ).toISOString(); | ||
} | ||
if ( !nextRun ) { | ||
nextRun = moment().add( 1000, 'years' ); | ||
} | ||
// mark the schedule as running if it is still due | ||
self._models | ||
.Dronos | ||
.findOneAndUpdate( { | ||
_id: schedule._id, | ||
_nextRun: { $lt: moment().toISOString() } | ||
}, | ||
{ | ||
$set: { | ||
_lastRun: moment().toISOString(), | ||
_nextRun: nextRun | ||
} | ||
}, | ||
{ upsert: false }, | ||
function( err, schedule ) { | ||
// mark the schedule as running if it is still due | ||
self._models | ||
.Dronos | ||
.findOneAndUpdate( { | ||
_id: schedule._id, | ||
_nextRun: { $lt: moment().toISOString() } | ||
}, | ||
{ | ||
$set: { | ||
_lastRun: moment().toISOString(), | ||
_nextRun: nextRun.toISOString() | ||
} | ||
}, | ||
{ upsert: false }, | ||
function( err, schedule ) { | ||
console.error( 'next run', err, schedule ); | ||
// another instance may have reached this schedule first | ||
if ( schedule ) { | ||
// another instance may have reached this schedule first | ||
if ( schedule ) { | ||
self._runSchedule( schedule, function( foundHandler ) { | ||
self._runSchedule( schedule, function( foundHandler ) { | ||
// the handler may have been removed since last run, | ||
if ( foundHandler ) { | ||
done(); | ||
} else { | ||
// the handler may have been removed since last run, | ||
if ( foundHandler ) { | ||
done(); | ||
} else { | ||
// handler was removed, reset the entry | ||
self._models | ||
.Dronos | ||
.findOneAndUpdate( { | ||
_id: schedule._id | ||
}, | ||
{ | ||
$set: { | ||
_lastRun: schedule._lastRun, | ||
_nextRun: schedule._nextRun | ||
} | ||
}, | ||
{ upsert: false }, | ||
function() { | ||
done(); | ||
} ); | ||
// handler was removed, reset the entry | ||
self._models | ||
.Dronos | ||
.findOneAndUpdate( { | ||
_id: schedule._id | ||
}, | ||
{ | ||
$set: { | ||
_lastRun: schedule._lastRun, | ||
_nextRun: schedule._nextRun | ||
} | ||
}, | ||
{ upsert: false }, | ||
function() { | ||
done(); | ||
} ); | ||
} | ||
} | ||
} ); | ||
} else { | ||
done(); | ||
} | ||
} ); | ||
} else { | ||
done(); | ||
} | ||
} ); | ||
} ); | ||
}, function() { | ||
done(); | ||
} ); | ||
}, function() { | ||
done(); | ||
} ); | ||
} ); | ||
} ); | ||
}; | ||
@@ -467,5 +467,5 @@ | ||
return JSON.stringify( { | ||
owner: schedule.owner || null, | ||
name: schedule.name || null | ||
} ); | ||
owner: schedule.owner || null, | ||
name: schedule.name || null | ||
} ); | ||
} | ||
@@ -472,0 +472,0 @@ |
{ | ||
"name": "dronos", | ||
"description": "Dronos is a distributed scheduling system (with patterns similar to Linux's cron system), using MongoDB to coordinate running tasks (drons) across multiple nodes.", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"author": "Anthony Hildoer <anthony@bluerival.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
1661
50684