diff --git a/src/QueueWorkCommand.php b/src/QueueWorkCommand.php index 9574af0..da3ed7e 100644 --- a/src/QueueWorkCommand.php +++ b/src/QueueWorkCommand.php @@ -6,19 +6,25 @@ use Illuminate\Console\Command; class QueueWorkCommand extends Command { - protected $signature = 'QueueWork {--workers=3 : Number of workers to run}'; + protected $signature = 'QueueWork + {--workers=3 : Number of workers to run} + {--connection=database : The queue connection to use} + {--queue=default : The queue name to work on}'; + protected $description = 'LaravelSupportCommand - Run multiple artisan queue:work processes, restart them if they exit.'; public function handle(): never { $workers = (int) $this->option('workers'); + $connection = $this->option('connection'); + $queue = $this->option('queue'); if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { $this->warn('Killing any existing queue:work processes...'); exec('pkill -f "artisan queue:work"'); } - $this->info("Starting {$workers} queue:work processes..."); + $this->info("Starting {$workers} queue:work processes on connection '{$connection}' and queue '{$queue}'..."); $processes = []; $pipesList = []; @@ -29,7 +35,8 @@ class QueueWorkCommand extends Command 1 => ['pipe', 'w'], // stdout 2 => ['pipe', 'w'], // stderr ]; - $process = proc_open('php artisan queue:work', $descriptors, $pipes); + $cmd = "php artisan queue:work {$connection} --queue={$queue}"; + $process = proc_open($cmd, $descriptors, $pipes); if (is_resource($process)) { stream_set_blocking($pipes[1], false); stream_set_blocking($pipes[2], false); @@ -68,7 +75,8 @@ class QueueWorkCommand extends Command if (!$status['running']) { $this->warn("Worker {$i} stopped. Restarting..."); proc_close($process); - $process = proc_open('php artisan queue:work', [ + $cmd = "php artisan queue:work {$connection} --queue={$queue}"; + $process = proc_open($cmd, [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'], ], $pipes);