diff --git a/src/AutoScaler.php b/src/AutoScaler.php index 86c5082d..6c17c8f8 100644 --- a/src/AutoScaler.php +++ b/src/AutoScaler.php @@ -77,11 +77,18 @@ protected function poolsByQueue(Supervisor $supervisor) protected function timeToClearPerQueue(Supervisor $supervisor, Collection $pools) { return $pools->mapWithKeys(function ($pool, $queue) use ($supervisor) { - $size = $this->queue->connection($supervisor->options->connection)->readyNow($queue); + $queues = collect(explode(',', $queue))->map(function ($_queue) use ($supervisor) { + $size = $this->queue->connection($supervisor->options->connection)->readyNow($_queue); + + return [ + 'size' => $size, + 'time' => ($size * $this->metrics->runtimeForQueue($_queue)), + ]; + }); return [$queue => [ - 'size' => $size, - 'time' => ($size * $this->metrics->runtimeForQueue($queue)), + 'size' => $queues->sum('size'), + 'time' => $queues->sum('time'), ]]; }); } diff --git a/src/SupervisorOptions.php b/src/SupervisorOptions.php index 0c90dd0d..6a1aaf44 100644 --- a/src/SupervisorOptions.php +++ b/src/SupervisorOptions.php @@ -265,7 +265,7 @@ public function balancing() */ public function autoScaling() { - return $this->balance === 'auto'; + return $this->balance !== 'simple'; } /** diff --git a/tests/Feature/SupervisorTest.php b/tests/Feature/SupervisorTest.php index 4b33f06e..d1bffc5d 100644 --- a/tests/Feature/SupervisorTest.php +++ b/tests/Feature/SupervisorTest.php @@ -95,6 +95,28 @@ public function test_supervisor_starts_multiple_pools_when_balancing() ); } + public function test_supervisor_starts_pools_with_queues_when_balancing_is_off() + { + $options = $this->supervisorOptions(); + $options->queue = 'first,second'; + $this->supervisor = $supervisor = new Supervisor($options); + + $supervisor->scale(2); + $this->assertCount(2, $supervisor->processes()); + + $host = MasterSupervisor::name(); + + $this->assertSame( + 'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="first,second" --sleep=3 --timeout=60 --tries=0 --rest=0', + $supervisor->processes()[0]->getCommandLine() + ); + + $this->assertSame( + 'exec '.$this->phpBinary.' worker.php redis --name=default --supervisor='.$host.':name --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue="first,second" --sleep=3 --timeout=60 --tries=0 --rest=0', + $supervisor->processes()[1]->getCommandLine() + ); + } + public function test_recent_jobs_are_correctly_maintained() { $id = Queue::push(new Jobs\BasicJob); @@ -154,6 +176,7 @@ public function test_exceptions_are_caught_and_handled_during_loop() public function test_supervisor_information_is_persisted() { $this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions()); + $options->balance = 'simple'; $options->queue = 'default,another'; $supervisor->scale(2); @@ -184,7 +207,8 @@ public function test_supervisor_repository_returns_null_if_no_supervisor_exists_ public function test_processes_can_be_scaled_up() { - $this->supervisor = $supervisor = new Supervisor($this->supervisorOptions()); + $this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions()); + $options->balance = 'simple'; $supervisor->scale(2); $supervisor->loop(); @@ -198,6 +222,7 @@ public function test_processes_can_be_scaled_up() public function test_processes_can_be_scaled_down() { $this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions()); + $options->balance = 'simple'; $options->sleep = 0; $supervisor->scale(3); @@ -468,6 +493,7 @@ public function test_supervisor_processes_can_be_counted_externally() { SystemProcessCounter::$command = 'worker.php'; $this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions()); + $options->balance = 'simple'; $supervisor->scale(3); $supervisor->loop(); @@ -481,6 +507,7 @@ public function test_supervisor_does_not_start_workers_until_looped_and_active() { SystemProcessCounter::$command = 'worker.php'; $this->supervisor = $supervisor = new Supervisor($options = $this->supervisorOptions()); + $options->balance = 'simple'; $supervisor->scale(3);