timgit / pg-boss

Queueing jobs in Node.js using PostgreSQL like a boss
MIT License
1.73k stars 144 forks source link

Bug: debounce mechanism schedule multiple jobs #414

Open manavi-litmusblox opened 11 months ago

manavi-litmusblox commented 11 months ago

I am using sendDebounced method to debounce my tasks. My debounce time is 10 minutes.

If I add the same job with same key I want previous job's sendAfter time to be increased by 10 minutes and do not schedule current task at all.

For example : If I am assigning assignments to students using a for loop I am scheduling email job each time the assignment is assigned to student with startAfter value 10 mins. The singleton key for job is studentId. Now, If the next assignment is assigned, it should not be added in the queue but the startAfter time of the first job should be increased by more 10 mins.

But it is scheduling 2 task irrespective of number of assignments when the assignment size is > 2

I can use sendThrottled but it is not adding 10 mins to sendAfter value when the next job is scheduled within the debounce time.

timgit commented 11 months ago

Job queues don't typically offer job mutation features like this after they are created, because the queue system needs to have total control of its state to be reliable. Debouncing is offered as a way to limit job creation over time (like throttling). It's not meant to replace all database-type use cases you can do with a table, which is what it sounds like you're needing.

For example, if you schedule an email to be sent, then decide you don't want to send it, you could cancel the previous job and create a new one if it hasn't been sent already.