Skip to content

Commit

Permalink
Merge pull request #2 from wonderlic-stevend/feature/priority
Browse files Browse the repository at this point in the history
add priority to queue items
  • Loading branch information
wonderlic-stephene authored Dec 18, 2018
2 parents 7e8494f + 8a3d08f commit aea77e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/message-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function MessageQueue() {
if (options && options.nextReceivableTime) {
queueItem.nextReceivableTime = options.nextReceivableTime;
}

// The priority range is 1-10, 1 being the highest.
queueItem.priority = _.get(options, 'priority', 1);

return _enqueue(queueItem);
};

Expand Down Expand Up @@ -216,7 +220,7 @@ function MessageQueue() {
if (!self.databasePromise) { return Q.reject(new Error("No database configured")); }
return self.databasePromise()
.then(function(db) {
return db.collection(self.collectionName).findOneAndUpdate(query, update, {returnOriginal: false});
return db.collection(self.collectionName).findOneAndUpdate(query, update, {returnOriginal: false, sort: 'priority'});
})
.then(function(result) {
return result.value;
Expand Down

0 comments on commit aea77e9

Please sign in to comment.