update command
This commit is contained in:
parent
54804b889e
commit
56771c12fd
|
|
@ -6,19 +6,25 @@ use Illuminate\Console\Command;
|
||||||
|
|
||||||
class QueueWorkCommand extends 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.';
|
protected $description = 'LaravelSupportCommand - Run multiple artisan queue:work processes, restart them if they exit.';
|
||||||
|
|
||||||
public function handle(): never
|
public function handle(): never
|
||||||
{
|
{
|
||||||
$workers = (int) $this->option('workers');
|
$workers = (int) $this->option('workers');
|
||||||
|
$connection = $this->option('connection');
|
||||||
|
$queue = $this->option('queue');
|
||||||
|
|
||||||
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
||||||
$this->warn('Killing any existing queue:work processes...');
|
$this->warn('Killing any existing queue:work processes...');
|
||||||
exec('pkill -f "artisan queue:work"');
|
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 = [];
|
$processes = [];
|
||||||
$pipesList = [];
|
$pipesList = [];
|
||||||
|
|
@ -29,7 +35,8 @@ class QueueWorkCommand extends Command
|
||||||
1 => ['pipe', 'w'], // stdout
|
1 => ['pipe', 'w'], // stdout
|
||||||
2 => ['pipe', 'w'], // stderr
|
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)) {
|
if (is_resource($process)) {
|
||||||
stream_set_blocking($pipes[1], false);
|
stream_set_blocking($pipes[1], false);
|
||||||
stream_set_blocking($pipes[2], false);
|
stream_set_blocking($pipes[2], false);
|
||||||
|
|
@ -68,7 +75,8 @@ class QueueWorkCommand extends Command
|
||||||
if (!$status['running']) {
|
if (!$status['running']) {
|
||||||
$this->warn("Worker {$i} stopped. Restarting...");
|
$this->warn("Worker {$i} stopped. Restarting...");
|
||||||
proc_close($process);
|
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'],
|
1 => ['pipe', 'w'],
|
||||||
2 => ['pipe', 'w'],
|
2 => ['pipe', 'w'],
|
||||||
], $pipes);
|
], $pipes);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue