update command

This commit is contained in:
root 2025-11-08 00:19:15 +00:00
parent 54804b889e
commit 56771c12fd
1 changed files with 12 additions and 4 deletions

View File

@ -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);