简体   繁体   中英

How to execute laravel job (queue)?

developers, I have a problem. My queue not working or i just not understand how it's works. I create a command which should add a new queue job. Driver for Queue is - database. After executing my command i see a new row in table 'jobs'. After that I try to do "php artisan queue:work" - but nothing happens.

Help me please, how can I execute this job?

From the documentation : [ Daemon Queue Listener ] The queue:work artisan command includes a --daemon option for forcing the queue worker to continue processing jobs without ever re-booting the framework. This results in a significant reduction of CPU usage when compared to the queue:listen command:

To start a queue worker in daemon mode, use the --daemon flag:

php artisan queue:work connection --daemon

However if you don't have multiple connections remove connection and execute it without connection :

php artisan queue:work --daemon

It worked for me.

Yes there are times when your queue jobs won't run. For deployment if you are using redis queue driver, if not you can follow this here to install and configure redis and after which you should create a table for failed jobs using php artisan queue:failed-table php artisan migrate and then use php artisan queue:work redis --tries=3 --backoff=3 to retry every failed jobs 3 times after 3 seconds of failure.

Try

php artisan queue:listen

instead.

To delay the next retry just add --delay=[NUM_OF_SECONDS] to your command.

For example, to wait 30 seconds to retry after failing just

run: php artisan queue:work tries=3 --delay=30

OR

php artisan queue:work --daemon --tries=3 --sleep=5 --delay=10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM