I am creating a web application in laravel in which bidding is being done by users in multiple games. Bidding is being performed by front end users and by cron job as well. Cron job do bid on each game after each second. Therefore some collision was happening between bids when same row was accessed at same time. To resolve concurrency issue I decided to use laravel queues for bidding. But I am having multiple games and therefore I want simultaneously bids of each game. I don't want bids of same game to be process at same time because then concurrency issue can be occur. I want to know about multiple queues system in laravel. After having search on internet I got to know about multiple queues like
php artisan queue:work --queue=myJobQueue, myJobQueue1, myJobQueue2,..myJobQueue7
But I am not sure how it works. Please someone explain me in detail that all 7 queues work simultaneously or one by one.
Are looking for the queue:listen
command?
queue:work
will process all pending jobs that are stored by the queue driver, whereas queue:listen
will be waiting for jobs to be thrown at it to execute them as they come.
If you do php artisan queue:listen --queue=myJobQueue, myJobQueue1, myJobQueue2,..myJobQueue7
, 7 queues are being created and listening to new tasks on their own.
In your code, you can dispatch jobs like the following:
dispatch((new MyJob)->onQueue('myJobQueue'));
You might want to use a tool like Supervisor to make sure queue:listen
is always running in the background.
Hope this helps!
php artisan queue:work --queue=myJobQueue, myJobQueue1, myJobQueue2,..myJobQueue7
sets the priority in which queues will be executed. So with this all jobs on myJobQueue
will be executed before moving to execute jobs on myJobQueue1
then to myJobQueue2
in that order.
However if you want jobs on these queues to be executed simultaneously, you could run each queue in the background.
php artisan queue:work --queue=myJobQueue & php artisan queue:work --queue=myJobQueue1 & php artisan queue:work --queue=myJobQueue2 &
This will run each queue as single processes in the background.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With