Skip to content

Commit

Permalink
an option to split queues for auto balancing
Browse files Browse the repository at this point in the history
  • Loading branch information
AsemAlalami committed Sep 26, 2024
1 parent cc20648 commit f8b7e46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions config/horizon.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@

'memory_limit' => 64,

/*
|--------------------------------------------------------------------------
| Process Per Queue
|--------------------------------------------------------------------------
|
| This option allows you to execute separate processes for every
| supervisor's queue if the balancing strategy is "auto".
| Disabling it will stop splitting queues so the worker will
| will handle many queues
|
*/

'process_per_queue' => true,

/*
|--------------------------------------------------------------------------
| Queue Worker Configuration
Expand Down
4 changes: 2 additions & 2 deletions src/Repositories/RedisWorkloadRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public function get()

$splitQueues = Str::contains($queue, ',') ? $length->map(function ($length, $queueName) use ($connection, $totalProcesses, &$wait) {
return [
'name' => $queueName,
'name' => "$queueName",
'length' => $length,
'wait' => $wait += $this->waitTime->calculateTimeToClear($connection, $queueName, $totalProcesses),
'wait' => $wait += $this->waitTime->calculateTimeToClear($connection, "$queueName", $totalProcesses),
];
}) : null;

Expand Down
2 changes: 1 addition & 1 deletion src/Supervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct(SupervisorOptions $options)
*/
public function createProcessPools()
{
return $this->options->balancing()
return $this->options->balancing() && config('horizon.process_per_queue', true)
? $this->createProcessPoolPerQueue()
: $this->createSingleProcessPool();
}
Expand Down

0 comments on commit f8b7e46

Please sign in to comment.