I've got 3 Laravel apps all running on the same server that need use to Horizon.
I had a problem whereby the apps where clashing and jobs wouldn't be run.
After inspecting the Redis database using Medis I could see that there would be 3 entries for each job:
- PRODUCTION_horizon:2
- STAGING_horizon:2
- HRS_horizon:2
Where production
, staging
and hrs
are my application names and 2
is the ID of the job.
If the job was dispatched from staging
it may still be picked up by production
or hrs
and then just sit as pending for staging, never actually running.
After much searching i've found a work around for this by prefixing all of my queues with the app name.
So my config changed from this:
'production' => [
'default' => [
'connection' => 'redis',
'queue' => ['default', 'emails', 'calculations'],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
'long_running' => [
'connection' => 'redis',
'queue' => ['bulk_calculations', 'imports', 'build_parents'],
'balance' => 'simple',
'processes' => 1,
'tries' => 3,
'timeout' => 86400 // 1 day
]
],
'staging' => [
'default' => [
'connection' => 'redis',
'queue' => ['default', 'emails', 'calculations'],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
'long_running' => [
'connection' => 'redis',
'queue' => ['bulk_calculations', 'imports', 'build_parents'],
'balance' => 'simple',
'processes' => 1,
'tries' => 3,
'timeout' => 86400 // 1 day
]
],
'hrs' => [
'default' => [
'connection' => 'redis',
'queue' => ['default', 'emails', 'calculations'],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
'long_running' => [
'connection' => 'redis',
'queue' => ['bulk_calculations', 'imports', 'build_parents'],
'balance' => 'simple',
'processes' => 1,
'tries' => 3,
'timeout' => 86400 // 1 day
]
],
To this:
'production' => [
env('APP_NAME') . '_default' => [
'connection' => 'redis',
'queue' => [
env('APP_NAME') . '_default',
env('APP_NAME') . '_emails',
env('APP_NAME') . '_calculations'
],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
env('APP_NAME') . '_long_running' => [
'connection' => 'redis',
'queue' => [
env('APP_NAME') . '_bulk_calculations',
env('APP_NAME') . '_imports',
env('APP_NAME') . '_build_parents'
],
'balance' => 'simple',
'processes' => 1,
'tries' => 3,
'timeout' => 86400 // 1 day
]
],
'staging' => [
env('APP_NAME') . '_default' => [
'connection' => 'redis',
'queue' => [
env('APP_NAME') . '_default',
env('APP_NAME') . '_emails',
env('APP_NAME') . '_calculations'
],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
env('APP_NAME') . '_long_running' => [
'connection' => 'redis',
'queue' => [
env('APP_NAME') . '_bulk_calculations',
env('APP_NAME') . '_imports',
env('APP_NAME') . '_build_parents'
],
'balance' => 'simple',
'processes' => 1,
'tries' => 3,
'timeout' => 86400 // 1 day
]
],
'hrs' => [
env('APP_NAME') . '_default' => [
'connection' => 'redis',
'queue' => [
env('APP_NAME') . '_default',
env('APP_NAME') . '_emails',
env('APP_NAME') . '_calculations'
],
'balance' => 'simple',
'processes' => 10,
'tries' => 1,
],
env('APP_NAME') . '_long_running' => [
'connection' => 'redis',
'queue' => [
env('APP_NAME') . '_bulk_calculations',
env('APP_NAME') . '_imports',
env('APP_NAME') . '_build_parents'
],
'balance' => 'simple',
'processes' => 1,
'tries' => 3,
'timeout' => 86400 // 1 day
]
],
This actually got it working! So essentially i've fixed it.
But this feels really wrong.
Now when I dispatch a job to a specific queue I have to do MyJob::dispatch()->onQueue(config('app.name') . '_emails');
Which is obviously not ideal.
I feel like there must be a better way but there's nothing in the docs explaining how to do this.
Is there a way to stop horizon interfering with each other? Maybe I should be using multiple Redis databases or something?
I realise that may seem odd posting a question of something i've already found a solution to, but I wanted to try and fix it myself before blindly asking and although I have found a solution, it really irks me that there is probably a much easier solution i'm just not aware of. Worst case scenario, if there isn't a better solution, someone else with this same problem will find this and discover my solution.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xC2Ohd
via IFTTT
Aucun commentaire:
Enregistrer un commentaire