agenda
agenda copied to clipboard
Solved: Job which are queued with high priority were not given priority
//registering jobs
const regJobToProcess = (job) => {
let job = agenda.create(job.type, job);
job.schedule('now');
job.priority(notification.priority || 'low');
job.save();
};
setTimeout(() => {
regJobToProcess({ type: 'PROCESS_SMS_OTP', priority: 'low', data: 1 });
regJobToProcess({ type: 'PROCESS_SMS_OTP', priority: 'high', data: 2 });
}, 5000);
When next job is picked, I expected that it will be the job with high priority. But result was not what i expected and It was the one with low priority. So I have gone through some of the code and found out that sorting order was not right and it was taking nextRunTime 1st and than priority. But for priority queue it should be other way around.
Let me know what is the expected behaviour? If current behaviour is not what is expected please review and merge the PR.
seems legit
Beware this could be a breaking change. 1.) Behavior changes 2.) Database query changes (other sorting/order means different index is required
Beware this could be a breaking change. 1.) Behavior changes 2.) Database query changes (other sorting/order means different index is required
I guess index findAndLockNextJobIndex will be used no need to change it. And as for behavior change, I guess the proposed behavior is the correct one. Let me know if I am missing something.