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.
Try
php artisan queue:listen
instead.
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.
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
Related
In Laravel job given queue connection as QUEUE_CONNECTION=database. when using QUEUE_CONNECTION=sync php artisan queue:work is running but when using QUEUE_CONNECTION=database queue is not triggering. php artisan queue:listen also not triggering the job.
You need to run
php artisan queue:restart
in one tab and another tab that is running
php artisan queue:work
Please run
php artisan queue:work --queue orders
I'm want to queue some jobs using Redis,so I made an Event and its Listener.
The Listener implements ShouldQueue. I deliberately throw exception to test whether it fails. By entering the the command php artisan queue:work --tries=3 it should try the job 3 times and if it can't be done, add it to failed-jobs right? but it doesn't do so. I tried using database driver but nothing changed.
One time I used php artisan queue:work --tries=3 --daemon despite the fact that --daemon is deprecated, and after 3 tries,the job was marked as failed - but when I stopped the command and ran it again, it didn't fail again.
why is this happening? Thanks in advance :)
I think you should deal with the failed jobs and check for the reasons ,
I suggest Adding Failed_jobs Table and check for failure reasons run theses commands to use that
php artisan queue:failed-table
php artisan migrate
Then try
php artisan queue:work redis --tries=3 --delay=3
If the job failed check the failed jobs table
In my table "jobs" have 5 jobs, i used the process "php artisan queue:listen" on localhost then it ran all jobs and finished. But when i used this process on server then it only once ran one jobs (same "php artisan queue:work"). I use queue_driver is "database".
Update - Laravel 5.5+
Just use:
php artisan queue:work --once
TL;DR
php artisan queue:work = run one queued job and stop
php artisan queue:listen = run all queued jobs and listen for more until stopped
Further detail:
How are you running the commands? Are you just opening a terminal and running it or do you have a cron job to run at intervals?
If you're just opening a terminal and running php artisan queue:work will complete one task on the queue then stop, whereas if you run php artisan queue:listen it will process all the jobs in the queue and continue to listen for any further jobs until it is stopped.
Read further in the docs regarding queue:work:
Starting The Queue Listener
Laravel includes an Artisan command that will run new jobs as they are
pushed onto the queue. You may run the listener using the queue:listen
command:
php artisan queue:listen
Processing The First Job On The Queue
To process only the first job on the queue, you may use the queue:work command:
php artisan queue:work
What you should be doing?
I am guessing what you ideally want to do on your server is set up a cron job to run continuously at intervals and have it run queue:work. Better yet, acquaint yourself with the docs and make a decision after that.
See similar question answered here: What is the difference between queue:work --daemon and queue:listen
I'm running a queue in Laravel for my parser program. I use the database driver in the queue.php config and set the expire to 3600. The queue is maintained using supervisord. Here is the supervisor configuration for the queue program:
[program:laravel_queue]
command=php /var/www/html/artisan queue:listen --memory=2048 --timeout=600
user=mainuser
autostart=true
autorestart=true
stderr_logfile=/var/www/html/storage/logs/laraqueue.err.log
stdout_logfile=/var/www/html/storage/logs/laraqueue.out.log
This is what shows up when I searched for PHP processes that was currently running :
/usr/bin/php artisan queue:work --queue=default --delay=0 --memory=2048 --sleep=3 --tries=0 --env=local
grep php
php /var/www/html/artisan queue:listen --memory=2048 --timeout=600
My problem is that when I use the queue, it always timed out when it reached 60 seconds, even though I already set --timeout=600. And I noticed that the timeout setting didn't show up in the queue:work process. Can anyone help me on this?
I have installed beanstaled and its working fine with laravel. The point where I am puzzled is that we have to do
php artisan queue:listen
to start listening queue. Right now, I am using it on amazone ec2 instance remotely through putty. but what is i close terminal? Will the jobs created through the code will work? Is it manually calling php artisan queue:listen or php artisan queue:work all time. Which does not seems fair.
If once php artisan queue:listen done, will it keep on running even if we close terminal?
Actually I dont know.
you need to install supervisor also. Here is a tutorial on using beanstalkd with laravel:
http://fideloper.com/ubuntu-beanstalkd-and-laravel4
Here are details on supervisor also:
http://supervisord.org/installing.html
I personally use a redis instance and run my queue with supervisor from there.
I find its a bit more memory effective then beanstalkd personally but each to there own.
Supervisor will execute the queue:listen command from artisan and this will run a job, if you have multiple supervisor processes then you can run multiple in line items.
depending on what you are doing i would almost look into python and multithereading also as i have used this for a few things i used to use a queue for and it has provided even better results.
example config file for supervisor:
[program:myqueue]
command=php artisan queue:listen --env=your_environment
directory=/path/to/laravel
stdout_logfile=/path/to/laravel/app/storage/logs/myqueue_supervisord.log
redirect_stderr=true
autostart=true
autorestart=true
You can also make use of Laravel's Task Scheduler i.e add the php artisan queue:listen command to the scheduler and sets its frequency to whatever you wants.
So that will make sure to call queue listen process automatically.
Hope it will make sense.