Answer the question
In order to leave comments, you need to log in
How to not add duplicate jobs to the queue in Laravel?
I can't find a solution to avoid adding duplicate jobs to the queue. The client now has the ability to execute tasks from the queue in only 1 thread, so a situation often arises when an important task is added, and there other tasks hang in front of an important task, which are essentially the same, i.e. if they perform a general analytics recalculation.
Is it possible to understand that such a task already exists in the system and not add it, so that queues of the same ones do not multiply, preventing more important tasks from being performed from the same queue?
About the software:
Laravel 5.6
PHP 7.1
MySQL 5.7
Queue in the database
Answer the question
In order to leave comments, you need to log in
Throw in the database, then when adding a task, compare for a duplicate.
I recorded the answer for you in video format, I hope it is intelligible
You can do as the authors of previous answers suggest, but if you need to change the connection type, then this solution will not work.
You can wrap adding to the queue in a command and run through the scheduler. It has a special method that allows you to check if the previous (same) command was completed before running it again.
Like withoutOverlapping.
Another option.
Create different queues for tasks with different priorities. And pass them to the handler in the required sequence.
php artisan queue:work --queue=high,low
One has to look in each case to see what works best.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question