I was running horizon with supervisor but then killed supervisor and am just running
php artisan horizon
I have 2 queues and separate supervisors for both. Here is the horizon config.
'defaults' => [
'logger' => [
'connection' => 'redis',
'queue' => [env('QUEUE_DEFAULT', '{default}')],
'balance' => 'simple',
'maxProcesses' => 1,
'memory' => 128,
'tries' => 2,
'timeout' => 30,
'nice' => 0,
],
'scheduler' => [
'connection' => 'redis',
'queue' => [env('QUEUE_SCHEDULE', '{schedule}')],
'balance' => 'simple',
'maxProcesses' => 1,
'memory' => 128,
'tries' => 3,
'timeout' => 30,
'nice' => 1,
],
],
'environments' => [
'production' => [
'logger' => [
'maxProcesses' => 3,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'memory' => 256
],
'scheduler' => [
'maxProcesses' => 2,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'memory' => 256
],
],
'develop' => [
'logger' => [
'maxProcesses' => 2,
'balanceMaxShift' => 1,
'balanceCooldown' => 3
],
'scheduler' => [
'maxProcesses' => 2,
'balanceMaxShift' => 1,
'balanceCooldown' => 3
],
],
'local' => [
'logger' => [
'maxProcesses' => 2,
],
'scheduler' => [
'maxProcesses' => 3,
],
],
],
When testing on develop env, horizon randomly processes one job on the default queue. default queue holds the jobs pushed by a queued event listener, which does nothing but writes logs to file.
It randomly works and processes a job and then everything goes into pending in horizon and never processed.
If I run
php aritsan horizon:terminate
and then restart horizon, sometimes it processes 1 job and then again starts placing everything in pending.
Here is my queue and database config for redis.
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('QUEUE_DEFAULT', '{default}'),
'retry_after' => 900,
'block_for' => null,
],
DB:
'redis' => [
'cluster' => true,
'client' => env('REDIS_CLIENT', 'predis'),
'options' => [
'cluster' => env('REDIS_CLUSTER', 'redis'),
],
'clusters' => [
'default' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 1),
],
],
Related
I tried to implement Horizon, from the terminal when I run commands like php artisan horizon:status or php artisan horizon:list I get positive feedbacks, everything seems to work just fine, but when I try to go to the /horizon view, no matter how many jobs I tried to run, in the dashboard I get this.
If I open the console from the browser I get Failed to load resource: the server responded with a status of 500 (Internal Server Error) on all the API calls like api/masters, api/stats or api/workload.
Searching online I found a lot of people saying to fix the .env file or the configuration files like queue.php or horizon.php, but after following their instructions my problem persists
.env:
CACHE_DRIVER=file
QUEUE_CONNECTION=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
APP_ENV=local
APP_DEBUG=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql
# Redis
REDIS_CLIENT=predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
queue.php:
<php?
return [
'default' => env('QUEUE_CONNECTION', 'redis'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 90,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'retry_after' => 90,
'block_for' => 0,
],
'sqs' => [
'driver' => 'sqs',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
'queue' => env('SQS_QUEUE', 'your-queue-name'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
],
],
'failed' => [
'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'failed_jobs',
],
];
horizon.php:
<?php
use Illuminate\Support\Str;
return [
'domain' => env('HORIZON_DOMAIN'),
'path' => env('HORIZON_PATH', 'horizon'),
'use' => 'default',
'prefix' => env(
'HORIZON_PREFIX',
Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:'
),
'middleware' => ['web'],
'waits' => [
'redis:default' => 60,
],
'trim' => [
'recent' => 60,
'pending' => 60,
'completed' => 60,
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
],
'metrics' => [
'trim_snapshots' => [
'job' => 24,
'queue' => 24,
],
],
'fast_termination' => false,
'memory_limit' => 64,
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'maxProcesses' => 1,
'maxTime' => 0,
'maxJobs' => 0,
'memory' => 128,
'tries' => 1,
'timeout' => 60,
'nice' => 0,
],
],
'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
],
'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
];
I install laravel horizon on a laravel 5.7 project and config it like this:
'domain' => null,
'path' => 'horizon',
'use' => 'default',
'prefix' => env('HORIZON_PREFIX', 'horizon:'),
'waits' => [
'redis:default' => 60,
],
'trim' => [
'recent' => 60,
'completed' => 60,
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
],
'fast_termination' => false,
'memory_limit' => 64,
'environments' => [
'production'=>[
'save_report' => [
'connection' => 'redis',
'queue' => ['save_report'],
'balance' => 'auto',
'processes' => 5,
'tries' => 1,
],
],
'local' => [
'save_report' => [
'connection' => 'redis',
'queue' => ['save_report'],
'balance' => 'auto',
'processes' => 5,
'tries' => 1,
],
],
],
This is full horizon config, and I'm almost sure it's ok.
But in the horizon panel, all the job is paused!
php artisan horizon is active on my terminal.
Check that your environment in .env is "production"
The environment name must match Horizon configuration.
We have Horizon running for quite some time now, and have no issues with it.
But after our most recent deploy on production, it remains inactive and there are no workers being started.
I fail to see the problem, nor do we get any errors logged into bugsnag, so I'm a bit lost here.
What would be the best way to debug issues with Horizon? I have verified, and I can talk to redis. The dashboard also displays jobs on the queue, so it's just a matter of the workers not being started.
We're setting up our instances using Laravel forge, and I can confirm that there is a daemon that runs php artisan horizon in the correct directory. Running that command manually on the server also doesn't give me much info that I can work with.
I'm sure here must be SOME error, but it's not beig caught / displayed / whatever. Any thoughts on how to properly debug this?
This is the contents of config/horizon.php:
<?php
return [
'use' => 'default',
'waits' => [
'redis:default' => 60,
],
'environments' => [
'dev' => [
'all-prio' => [
'connection' => 'redis',
'queue' => ['default', 'high', 'medium', 'low'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
'acc' => [
'all-prio' => [
'connection' => 'redis',
'queue' => ['default', 'high', 'medium', 'low'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
],
'production' => [
'high-prio' => [
'connection' => 'redis',
'queue' => ['high'],
'balance' => 'auto',
'processes' => 10,
'tries' => 5,
],
'default-prio' => [
'connection' => 'redis',
'queue' => ['medium', 'default'],
'balance' => 'auto',
'processes' => 10,
'tries' => 3,
],
'low-prio' => [
'connection' => 'redis',
'queue' => ['low'],
'balance' => 'auto',
'processes' => 5,
'tries' => 3,
],
],
],
];
The environment is correctly being set to 'production' on that environment.
This is the contents of the config/database.php redis section:
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
]
What does the 'queue' => 'default' setting do at config/queue.php?
It seems like it does not affect anything.
In config/queue.php my queue configuration is ga-fetcher-queue.
This is my config:
return [
'default' => 'redis',
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'ga-fetcher-queue',
'retry_after' => 360,
],
],
'failed' => []
];
My redis config at config/database.php is this:
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
]
I used redis for task queue in laravel, i want to use connection name per queue to handle config varibales conflict in queue in below code :
php artisan queue:work connection-name --deamon --queue=high,medium,low --sleep=3 --tries=3
But i dont know what is the connection name in below code to use:
'default' => env('QUEUE_DRIVER', 'redis'),
'connections' => [
'sync' => [
'driver' => 'sync',
],
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
'beanstalkd' => [
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
],
'sqs' => [
'driver' => 'sqs',
'key' => 'your-public-key',
'secret' => 'your-secret-key',
'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id',
'queue' => 'your-queue-name',
'region' => 'us-east-1',
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 60,
],
],
You have several connections configured.
Each connection is an element in the connections array and you just need to pass the relevant key as the name.
e.g.
php artisan queue:work sqs --daemon --queue=high --sleep=3 --tries=3