I'm working on queue and I found custom queue won't be run.
I run php artisan queue:work --queue=emails and I dispatch queue MyJob::dispatch()->onQueue('emails')->delay(now()->addMinutes(1)).
In database table jobs will be like this:
id
queue
payload
1
emails
...
After 1 minute:
id
queue
payload
2
default
...
It seems queue emails is processed, and remove from database. Then create another job for queue default with the same payload and job queue default will never run except I run php artisan queue:work --queue=emails,default
In Laravel documentation not mention to always run queue default. https://laravel.com/docs/8.x/queues#specifying-the-connection-queue
Is it correct behaviour?
In my case, the problem of duplicate rows occurs when I set QUEUE_CONNECTION to database in .env file like this:
QUEUE_CONNECTION=database
I solved the problem by keep value of QUEUE_CONNECTION as default of Laravel sync
And add database to command like this:
php artisan queue:work database --queue=my_custom_queue_name
Related
I'm dispatching a Job, which should go to jobs table, according to my .env config (QUEUE_DRIVER=database)
But what happens is that nothing appears in jobs table and the job doesnt even run on sync mode, for example. I've watched queue:listen, Laravel log file, failed_jobs table is empty as well. Please help me, my job is gone
OBS: I'm running artisan config:clear after changing .env file and then i restart PHP FPM service
One thing i noticed is that when I turn QUEUE_DRIVER to sync, it runs all jobs I've dispatched even they didnt go to jobs table
Am I loosing something?
When you set QUEUE_DRIVER to sync, dispatched jobs will be immediately run and not be inserted in the jobs table.
So you should set it to 'database' to get the desired action.
my function in controller Calling parallel and i create a job for use queue in laravel Because parallel call causing the problem
i call this job in my function :
$this->dispatch(new ProcessReferal($orderId));
and i run this command in terminal :
php artisan queue:work --tries=3
But my job is still running in parallel
And processes the process simultaneously
what's wrong?
If you are checking it on Local server. Then, You have to add QUEUE_DRIVER=database in .env file.
QUEUE_DRIVER=sync is used for parallel call
Hi there,
With queue laravel, you need config some info in your code:
See more: https://laravel.com/docs/5.8/queues#connections-vs-queues
First:
Driver: default sync, so you need change it to: database, redis...
You can change it in .env file (QUEUE_DRIVER=database...)
Connections: Very important if you setting driver is database and use mutil DB for your project.
Second:
Laravel queue have some config, but i think we need see 3 thing: retry_after, timeout, tries. When you work with large job, retry_after and timeout is very important.
Hope it can help you.
My application requires to have dynamically generated queues with some prefix like "process_user_1", "process_user_2", "process_user_n"
The main idea is to separate execution of some jobs depends on model ID.
To run watcher I need execute command php artisan queue:work --queue process_user_1
I didn't find possibility to put pattern like
php artisan queue:work --queue process_user_*
And only one way what I found it is to run them manually each time before job is sent. But it's so dirty...
Maybe someone know another way?
EXAMPLE:
I have 10 users. Each user has 100 jobs to process in queue.
If I put them to one queue like "process_user_job" users will wait a
lot of time when jobs will be finished.
So I want to separate queues to speed up result returning
I am using Laravel Queues and I am using IronMQ for it. But I have little bit confusion about how this process.
I have set my default connection in queue.php as 'default' => 'iron' and also set iron settings in same file.
Now I use
$this->dispatch(new createEvents($data, $user));
while createEvents class is a job class created as explained in Laravel tutorial. Now when following code is executed
$this->dispatch(new createEvents($data, $user));
It successfully creates a queue in my ironmQ account under project.
Now here is my confusion starts. I have queued some task to that queue but now how will I run that queue? How will I run the task that is queued? Do I need to create some extra code for it or Do I need to do some settings for it. Please guide
You don't need to go to your server and run this command by hand, you need to have process that will keep running, and perform those jobs.
I would recomment "supervisord"
http://supervisord.org/
This programs is for launching a script and keep it running, even if it fails, it will relaunch it(until certain amount of failures of course)
After you install it, you should probably create this supervisor task file:
[program:queue]
command=php artisan queue:listen --tries=3 --env=your_environment
directory=/path/to/laravel
stdout_logfile=/path/to/laravel/app/storage/logs/supervisord.log
redirect_stderr=true
autostart=true
autorestart=true
You can do php artisan queue:listen it will start all listed queue
or if you specify the queue name php artisan queue:listen queue_name
Don't forget to run php artisan queue:failed-table. This will make failed_jobs table in your database.
So if anything goes wrong when the queue run it will save failed queue to the database.
If you want the failed queue to get insert the database add this when run listen:
php artisan queue:listen connection-name --tries=3
to run the failed queue php artisan queue:retry all
Hope i answer your question.
Once your job is in the queue, and according to your question it is, you have two simple options:
Run one or more queue listeners on the same/different servers (using supervisor is recommended in Laravel documentation, see sample configuration)
Run queue worker manually or automatically, on regular basis (crontab)
php artisan queue:work iron
This command will fetch one job from the queue and process it. You launch it again – it fetches one more, and so on.
If you don't do extra processing and your queue driver is not 'sync' – your job will never see the day light.
My advice – launch queue workers manually on your development/test machine, and use supervisor on production server.
If your project is small and it doesn't require great scalability, you may want to simply switch to 'sync' driver (jobs will be processed immediately). There is no need to make the infrastructure more complicated, unless there is real necessity!
I'm using Lumen queues. To start the jobs being processed, the docs indicate to run the queue listener from the command line like so:
php artisan queue:listen
I'd like to trigger my queue jobs processes directly from my code. How to do so?
You can call any artisan command you like directly from your code:
Artisan::call('queue:listen');
For information, read the docs.