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'
Related
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.
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.
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?
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.
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!