I have a lot of tasks, which should be processed in proper order. I would like to divide them by “type” to different queues. Queues should be created dynamically. Then I would like to start X workers, which will process the tasks from the queues. But there is one important rule – from each queue, only one task should be processed at once. The reason is – each task of the specified type can change the state of the application, so I can’t start processing a new task of the same type if the last one hasn’t finished.
I would like to use Laravel queue system with Redis driver, but I’m not sure it’s able to do that. How to prevent the queue system from taking more than one job from each queue at once? Any ideas?
Thank you in advance for your help.
2
Answers
If you are using
supervisor
then this is what you can do in your.conf
file.numprocs directive will instruct Supervisor to run 1 queue:work processes and monitor it, automatically restarting it if it fails. (Laravel Queue Supervisor Doc)
Job chaining allows you to specify a list of queued jobs that should be run in sequence after the primary job has executed successfully. If one job in the sequence fails, the rest of the jobs will not be run. To execute a queued job chain, you may use the
withChain
method on any of your dispatchable jobs.If you would like to specify the default connection and queue that should be used for the chained jobs, you may use the
allOnConnection
andallOnQueue
methods.See Laravel docs for more info.