Can't delete failed jobs (laravel 7) - laravel

I have a couple thousand failed jobs in my redis queue and every time I start up Horizon, they all retry and fail. I need to get rid of them all.
I've tried php artisan queue:flush which outputs the message "All failed jobs deleted successfully!"
But they're all still there.
I've noticed on Laravel 8 Horizion documentation, they added php artisan horizon:clear, but I can't upgrade right now. What can I do to delete everything?

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.

Laravel queue using redis is not stable?

I am using redis-server ver 5.x on my vps ubuntu ver 20.x.Sometimes, few jobs do not execute and stop immediately.
My command to create worker:
php artisan queue:work --timeout=0 --tries=2
So maybe there is something wrong with redis-server? I tried to refresh the redis and even reinstall it. Nothing change.
P/s: No exception was threw in each job. Every jobs take only one second to execute. There is nothing unusual in logs of redis-server and Laravel app
Turns out, I have an another app using the same redis server. And workers of the second app a executed jobs in the first app. Problem solved.

Laravel Horizon not showing jobs

On a new Laravel 8 project my jobs are not appearing in the Horizon UI. Here's what I did:
Install horizon and did php artisan horizon:install
Configured the Redis queue driver
When I do php artisan horizon the output shows that it's successfully processing jobs
If I check my Redis database I can see the completed jobs being stored there (and failed jobs are stored in the mysql table)
So everything is working as expected.
The problem is that the Horizon interface does not show anything, it just shows the loading state everywhere. I've ran php artisan optimize:clear to make sure that it has the latest ENV and config settings but that didn't resolve the issue.
OK party people, here's what went down. In config/horizon.php you can set Horizon's path. I've just learned that you should not start this path with a /, because then Horizon's API calls to fetch the job data will fail.
Don't use
'path' => '/subfolder/horizon'
Do use
'path' => 'subfolder/horizon'

Job not dispatching to jobs table Laravel

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.

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