Notifications not added to queue - laravel

I've provisioned a Laravel Forge server and configured it to use redis for queues via .env:
QUEUE_DRIVER=redis
My settings for Redis in both config/queue.php and config/database.php are the defaults found in a new laravel project.
The problem is that when a mail notification is triggered, it is never added to the queue. It never gets to the processing stage.
I've tried using forge's queue interface as well as SSH into the server and running a simple
php artisan queue:listen
without any parameters. In both cases, no results (using the artisan command confirms no job is added to the queue).
Interestingly, I tried Beanstalkd:
QUEUE_DRIVER=beanstalkd
and suffered the same problem.
As a sanity check, I set the queue driver to sync:
QUEUE_DRIVER=sync
and the notification was delivered without issue, so there isn't a problem with my code in the notification class, it's somewhere between calling the notify method and being added to the queue.
The same configuration running locally works fine. I can use
php artisan queue:listen
and the notifications go through.

After an insane amount of time trying to address this, I discovered it was because the app was in maintenance mode. To be fair, the documentation does state that queued jobs aren't fired in maintenance mode, but unless you knew maintenance mode was the culprit you probably wouldn't be looking in that section.

Related

Recently added json language file values are not updated in email blade

I send mail as a cron job with Laravel. For this, when I want to use the last value I added in my resources/lang/de.json file in the mail blade template file(resources/views/mails/...blade.php), it gives an output as if such a value is not defined. However, if I use the same key in a blade file I created before, it works without any errors. In addition, the keys that I added to the same file (de.json) in the first time work without errors in the same mail blade file.
Thinking it's some kind of cache situation, I researched and found out that restarting the queue worker might fix the problem. However, both locally and on the server with ssh.
'php artisan queue:restart'
Even though I ran the command, there was no improvement.
Do you have any ideas?
Since queue workers are long-lived processes, they will not notice changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. https://laravel.com/docs/9.x/queues#queue-workers-and-deployment
but php artisan queue:restart will instruct all queue workers to gracefully exit after they finish processing their current job so that no existing jobs are lost. And I see a lot of issues with this command not to solve restart and deploy the worker.
So, Simplest way,
try to stop the worker manually (ctrl+C)
start the worker again with php artisan queue:work again.
might this help.

How to stop Laravel Queues from caching everything?

The documentation doesn't seem to be quite updated yet, and the answers on the net are mostly wrong, but if you want to have a 'dev' version of a queue worker/processor/listener, then use the 'queue:listen' option instead of the 'queue:work' option.
'queue:work' will absolutely cache everything, and nothing in the world save for killing the process and restarting it will prevent it from caching. that includes using the 'none' cache driver, etc.
This includes using the 'queue:restart' option, which is supposed to soft-restart the worker queue. Maybe it does that, but it doesn't kill the cache.
Use php artisan queue:listen instead of php artisan queue:work.

how to use queue when requests are parallel in laravel

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.

Confusions about Laravel Queues

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!

How to fire Laravel Queues with beanstalkd

I'm pretty new to the whole Queue'd jobs thing in Laravel 4. I have some process heavy tasks I need the site to run in the background after being fired by the user doing a particular action.
When I was doing the local development for my site I was using this:
Queue::push('JobClass', array('somedata' => $dataToBeSent));
And I was using the local "sync" driver to do it. (The jobs would just automatically fire, impacting on the user experience but I assumed when going into the production phase I could switch it to beanstalkd and they would then be run in the background)
Which brings me to where I'm at now. I have beanstalkd set up with the dependencies installed with composer and the beanstalkd process listening for new jobs. I installed a beanstalk admin interface and can see my jobs going into the queue, but I have no idea how to actually get them to run!
Any help would be apprieciated, thanks!
This is actually a really badly documented feature in Laravel.
What you actually need to do is have the JobClass.php in a folder that is auto-loaded, I use app/commands, but they can also be in app/controllers or app/models if you like. And this function needs to have a fire event that takes the $job and $data argument.
To run these, simply execute php artisan queue:listen --timeout=60 in your terminal, and it will be busy emptying the queue, until it's empty, or it's been running for longer then 60 seconds. (Small note: The timeout is the time-limit to start a queue, so it may run for 69 seconds if 1 job takes 10 seconds.
If you only want to run 1 job (perfect for testing), run php artisan queue:work
There are tools like Supervisord that make sure your job handlers keep running, but I recommend to just make a Cron task that starts every X minutes based on how fast the data needs to be processed, and on how much data comes in.
Keep in mind you need to path your artisan.
php /some/path/to/artisan queue:work

Resources