Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #503 from memfork/fix-task-worker-for-queue
Browse files Browse the repository at this point in the history
Fix: task worker num output zero always and enable task worker when defined connections in queue.php
  • Loading branch information
Arkanius authored Sep 10, 2021
2 parents 4c5fe33 + 51fae3a commit 29c6bfa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Commands/HttpServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,21 @@ protected function showInfos()
$workerNum = Arr::get($this->config, 'server.options.worker_num');
$taskWorkerNum = Arr::get($this->config, 'server.options.task_worker_num');
$isWebsocket = Arr::get($this->config, 'websocket.enabled');
$hasTaskWorker = $isWebsocket || Arr::get($this->config, 'queue.default') === 'swoole';

$queueConfig = $this->laravel->make('config')->get('queue');

// lookup for set swoole driver
$isDefinedSwooleDriver = in_array(
'swoole',
array_column(
$queueConfig['connections'] ?? [],
'driver'
),
true
) || ($queueConfig['default'] ?? null) === 'swoole';

$hasTaskWorker = $isWebsocket || $isDefinedSwooleDriver;

$logFile = Arr::get($this->config, 'server.options.log_file');
$pids = $this->laravel->make(PidManager::class)->read();
$masterPid = $pids['masterPid'] ?? null;
Expand Down
12 changes: 11 additions & 1 deletion src/HttpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,18 @@ protected function configureSwooleServer()
$config = $this->app->make('config');
$options = $config->get('swoole_http.server.options');

// lookup for set swoole driver
$isDefinedSwooleDriver = in_array(
'swoole',
array_column(
$config->get('queue.connections'),
'driver'
),
true
) || $config->get('queue.default') === 'swoole';

// only enable task worker in websocket mode and for queue driver
if ($config->get('queue.default') !== 'swoole' && ! $this->isWebsocket) {
if (! $isDefinedSwooleDriver && ! $this->isWebsocket) {
unset($options['task_worker_num']);
}

Expand Down

0 comments on commit 29c6bfa

Please sign in to comment.