Skip to content
Permalink
Browse files

Refactor JOB_PROCESS_WHERE_QUERY to get an optimized query plan (#869)

  • Loading branch information
mfred488 authored and simison committed Nov 24, 2019
1 parent c9988a4 commit 3e07e8ebe919d1f04518b640cc4b7a959e377354
Showing with 8 additions and 12 deletions.
  1. +8 −12 lib/agenda/find-and-lock-next-job.js
@@ -36,23 +36,19 @@ module.exports = function(jobName, definition, cb) {
} else {
// /**
// * Query used to find job to run
// * @type {{$or: [*]}}
// * @type {{$and: [*]}}
// */
const JOB_PROCESS_WHERE_QUERY = {
$or: [{
$and: [{
name: jobName,
lockedAt: null,
nextRunAt: {$lte: this._nextScanAt},
disabled: {$ne: true}
}, {
name: jobName,
lockedAt: {$exists: false},
nextRunAt: {$lte: this._nextScanAt},
disabled: {$ne: true}
}, {
name: jobName,
lockedAt: {$lte: lockDeadline},
disabled: {$ne: true}
$or: [{
lockedAt: {$eq: null},
nextRunAt: {$lte: this._nextScanAt}
}, {
lockedAt: {$lte: lockDeadline}
}]
}]
};

0 comments on commit 3e07e8e

Please sign in to comment.
You can’t perform that action at this time.