agenda icon indicating copy to clipboard operation
agenda copied to clipboard

Solved: Job which are queued with high priority were not given priority

Open MrSpark2591 opened this issue 6 years ago • 3 comments

//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.

MrSpark2591 avatar Jun 20 '19 06:06 MrSpark2591

seems legit

Uzlopak avatar May 26 '20 13:05 Uzlopak

Beware this could be a breaking change. 1.) Behavior changes 2.) Database query changes (other sorting/order means different index is required

simllll avatar Dec 11 '20 20:12 simllll

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.

MrSpark2591 avatar Dec 17 '20 06:12 MrSpark2591