Skip to content

Commit

Permalink
add priority to queue items
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderlic-stevend committed Dec 12, 2018
1 parent 7e8494f commit 8a3d08f
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 8a3d08f

Please sign in to comment.