I'm using Laravel forge and have setup Horizon for processing jobs.
The jobs are being processed I can see that in the forge logs. However, the jobs are not visible in my horizon dashboard. I can see that horizon is active, everything looks fine but they just don't show up.
My horizon config file is pretty basic:
'environments' => [
'prod' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'simple',
'processes' => 20,
'tries' => 1,
],
],
'local' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'simple',
'processes' => 3,
'tries' => 1,
],
],
],
The jobs are being dispatched on the default queue.
When I look into my failed_jobs table I see records showing up, but not in my horizon dashboard!
What could be wrong here? I already have restarted server/horizon/nginx. But nothing seems to work.
Related
we're using Laravel 8.x and we've just switched our queue driver from database to redis/horizon. Now we're getting some strange behavior with some jobs.
The Job itself does converting stuff over some time between a few minutes up to 90 minutes. With the database-driver the job is executed properly. With horizon the job is executed for some time and then seems to get stucked. We've tested the job many times with the same payload and it get stucked at different runtimes and get marked as failed after the timeout (with the same timestamp as start).
The logfile of supervisor contains the following:
[2022-01-07 18:08:33][b69e5cf9-4f88-4005-a5c4-4722e46fe7d0] Processing: App\Jobs\ConvertJob
[2022-01-07 18:08:33][b69e5cf9-4f88-4005-a5c4-4722e46fe7d0] Failed: App\Jobs\ConvertJob
The (other) logfiles doesn't contain any (other) errors :-/
Our config for horizon looks like this (just the relevant parts):
'memory_limit' => 64,
'defaults' => [
'converter' => [
'connection' => 'redis',
'queue' => ['convert'],
'balance' => 'auto',
'maxProcesses' => 1,
'memory' => 128,
'tries' => 1,
'nice' => 0,
],
'worker' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'maxProcesses' => 1,
'memory' => 128,
'tries' => 1,
'nice' => 0,
],
],
'environments' => [
'local' => [
'converter' => [
'minProcesses' => 4,
'maxProcesses' => 9,
'balanceMaxShift' => 3,
'balanceCooldown' => 2,
],
'worker' => [
'maxProcesses' => 6,
'balanceMaxShift' => 2,
'balanceCooldown' => 3,
]
],
],
Supervisor config:
[program:horizon]
process_name=%(program_name)s
command=php /app/artisan horizon
autostart=true
autorestart=true
user=%(ENV_SUPERVISOR_USER)s
redirect_stderr=true
stdout_logfile=/app/logs/sv-horizon.log
stopwaitsecs=5400
Queue config:
'redis' => [
'driver' => 'redis',
'connection' => 'queue',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 5430,
'block_for' => null,
'after_commit' => false,
],
The Job itself sets tries to 1, timeout to 5400 seconds and failOnTimeout true.
Maybe anyone of you can give me a hint?
I have a system where I spin up, every hour, tons of jobs and I would like them to be handled on a different redis connection, separate from the main one jobs are popped on to so they do not interfere with other jobs (ie, delaying them) that get pushed on to the queue.
So I did the following, I created a new redis connection:
'kingdom_jobs' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_CACHE_DB', 2),
],
Then created a new Queue Connection:
'kingdom_jobs' => [
'driver' => 'redis',
'connection' => 'kingdom_jobs', // Uses the new connection
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
],
Then in the loop that spins up all these jobs:
Kingdom::chunkById(250, function($kingdoms) use ($service) {
foreach ($kingdoms as $kingdom) {
UpdateKingdomJob::dispatch($kingdom)->onConnection('kingdom_jobs');
}
});
The issue?
Ya they get pushed to this new connection, I see them in horizon - over 500 of them - but they don't do anything. They don't get processed. Is there a way to tell horizon to process this additional connection?
I currently use php artisan horizon in development to process jobs - is there another step?
I assume from the docs, there is some step I am missing, I assume it has to do with php artisan queue:work --tries = 3 from the docs? Trying that did nothing. Do I need another instance of horizon for this new connection or do I configure horizon to know about this connection?
Help?
It is likely that you don't have a Horizon supervisor setup to watch your new queue.
Looking at the Horizon config:
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'tries' => 3,
],
],
],
It looks like we can just add another supervisor to the production environment (and others if you need it):
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'tries' => 3,
],
'supervisor-2' => [
'connection' => 'kingdom_jobs',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'tries' => 3,
],
],
],
I using laravel horizon for creating products using api.
but I facing issue of 429 too many request.
below is my horizon setup
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 4,
'tries' => 1,
],
],
'local' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 4,
'tries' => 1,
],
],
],
I got a solution.
I made one cron who will track the total count in Shopify pending basket.
if cron found countless then 30 then it will more 100 requests.
every minute cron will check this.
When trying to use Laravel Horizon instead of Laravel Forge's queue setup, I have an issue with "translating" two workers into the horizon config.php file.
Let's say we have two queues: "queue1" and "queue2" but one queue shall have different processes and a different timeout, how can I achieve this with only one supervisor?
The current setup is:
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['queue1'],
'balance' => 'simple',
'processes' => 20,
'tries' => 3,
'timeout' => 30,
],
'supervisor-2' => [
'connection' => 'redis',
'queue' => ['queue2'],
'balance' => 'simple',
'processes' => 5, // different
'tries' => 1, // different
'timeout' => 60, // different
],
],
But I do not want to have 2 supervisors but only 1. How can this be achieved whilst maintaining different tries, processes and timeouts?
I'm a bit confuse about how to run the job only once, because when I set the parameter "tries" to 1 and the job fails, it execute one more time. If I set the tries parameter to 3, the job runs 4 times. And finally if I set to 0, the jobs run indefinitely. Below my settings in config/horizon.php:
'production' =
'default' => [
'connection' => 'redis',
'queue' => [
'default',
'notifications',
'dom'
],
'balance' => 'auto',
'maxProcesses' => env('MAX_PROCESSES', 45),
'timeout' => 60,
'tries' => 1,
],
],
And below my settings in config/queue.php
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'retry_after' => 90,
],
And other question, what setting dispatch the "has been attempted to many times or run too along"?
Just set an attribute $tries = 1 to the Job, and on the catch of possible errors, call $this->fail();