@@ -43,10 +43,8 @@ Agenda.prototype.database = function(url, collection, options) {
4343 this . _db = mongo . db ( url , options ) . collection ( collection ) ;
4444
4545 var ignoreErrors = function ( ) { } ;
46- this . _db . ensureIndex ( "nextRunAt" , ignoreErrors )
47- . ensureIndex ( "lockedAt" , ignoreErrors )
48- . ensureIndex ( "name" , ignoreErrors )
49- . ensureIndex ( "priority" , ignoreErrors ) ;
46+ this . _db . ensureIndex ( { "name" : 1 , "priority" : - 1 , "lockedAt" : 1 , "nextRunAt" : 1 , "disabled" : 1 } , ignoreErrors )
47+ . ensureIndex ( { "name" : 1 , "lockedAt" : 1 , "priority" : - 1 , "nextRunAt" : 1 , "disabled" : 1 } , ignoreErrors ) ;
5048
5149 return this ;
5250} ;
@@ -259,14 +257,11 @@ Agenda.prototype._findAndLockNextJob = function(jobName, definition, cb) {
259257
260258 this . _db . findAndModify (
261259 {
262- nextRunAt : { $lte : this . _nextScanAt } ,
263- disabled : { $ne : true } ,
264260 $or : [
265- { lockedAt : null } ,
266- { lockedAt : { $exists : false } } ,
267- { lockedAt : { $lte : lockDeadline } }
268- ] ,
269- name : jobName
261+ { name : jobName , lockedAt : null , nextRunAt : { $lte : this . _nextScanAt } , disabled : { $ne : true } } ,
262+ { name : jobName , lockedAt : { $exists : false } , nextRunAt : { $lte : this . _nextScanAt } , disabled : { $ne : true } } ,
263+ { name : jobName , lockedAt : { $lte : lockDeadline } , nextRunAt : { $lte : this . _nextScanAt } , disabled : { $ne : true } }
264+ ]
270265 } ,
271266 { 'priority' : - 1 } ,
272267 { $set : { lockedAt : now } } ,
0 commit comments