Deleting and Re-Adding Queue Jobs on Due Date Update in Laravel 11
In my Laravel 11 application, I am creating records that trigger queue jobs, such as sending notifications based on due dates. When a new record is created, a job is successfully added to the queue. However, if the user updates the due date of the same record, I need to delete the existing job related to that record and then add a new one with the updated due date. I am looking for an efficient way to identify, delete the old queued job, and create a new job for the updated record. Thank you.
When the job comes time to run, compare the date given to the job with the date on the model. If it's different then just close the job without doing anything.
Then you can add a second job when the date is changed and not worry about trying to find the original job in queue.
But I would advise against scheduling anything into the future for more than a few minutes. You never know when you might need to clear the queue.
I would have a scheduled task that looks for notifications that need sending and not rely on the queue
@Snapey Great! Thank you so much for your help sir. I'm using the queue specifically for sending instant notifications, and avoiding cron for this function since cron would require frequent server hits to handle instant notifications.
@Snapey I am creating task management where user can create task with dueDate-Time, etc. so here in case user changed dueDate-Time then need to check in job so that old due date notification does not trigger.
Instant notifications means notification will trigger as soon as dueDate-Time passed hence I am using queue. If I will use cron then it will hit server frequently. For example if i will set cron of every minute it will check in database every minute.