This commit is contained in:
2021-04-15 16:34:12 +08:00
parent 2f5f86a5ab
commit 1a24daf8dc
4 changed files with 9 additions and 12 deletions
+1 -3
View File
@@ -13,8 +13,7 @@ use Snowflake\Snowflake;
trait Server trait Server
{ {
/** @var Application */ public ?Application $application = null;
public $application;
/** /**
@@ -26,7 +25,6 @@ trait Server
*/ */
public function __construct($host, $port = null, $mode = null, $sock_type = null) public function __construct($host, $port = null, $mode = null, $sock_type = null)
{ {
$this->application = Snowflake::app();
parent::__construct($host, $port, $mode, $sock_type); parent::__construct($host, $port, $mode, $sock_type);
} }
+5 -5
View File
@@ -86,11 +86,11 @@ class Kafka extends \Snowflake\Process\Process
if ($message->err == RD_KAFKA_RESP_ERR_NO_ERROR) { if ($message->err == RD_KAFKA_RESP_ERR_NO_ERROR) {
$this->handlerExecute($message->topic_name, $message); $this->handlerExecute($message->topic_name, $message);
} else if ($message->err == RD_KAFKA_RESP_ERR__PARTITION_EOF) { } else if ($message->err == RD_KAFKA_RESP_ERR__PARTITION_EOF) {
$this->application->warning('No more messages; will wait for more'); logger()->warning('No more messages; will wait for more');
} else if ($message->err == RD_KAFKA_RESP_ERR__TIMED_OUT) { } else if ($message->err == RD_KAFKA_RESP_ERR__TIMED_OUT) {
$this->application->error('Kafka Timed out'); logger()->error('Kafka Timed out');
} else { } else {
$this->application->error($message->errstr()); logger()->error($message->errstr());
} }
} catch (Throwable $exception) { } catch (Throwable $exception) {
logger()->addError($exception, 'throwable'); logger()->addError($exception, 'throwable');
@@ -142,8 +142,8 @@ class Kafka extends \Snowflake\Process\Process
$conf->set('metadata.broker.list', $kafka['brokers']); $conf->set('metadata.broker.list', $kafka['brokers']);
$conf->set('socket.timeout.ms', '30000'); $conf->set('socket.timeout.ms', '30000');
$this->application->debug('kafka listen groupId ' . $kafka['groupId']); logger()->debug('kafka listen groupId ' . $kafka['groupId']);
$this->application->debug('kafka listen brokers ' . $kafka['brokers']); logger()->debug('kafka listen brokers ' . $kafka['brokers']);
if (function_exists('pcntl_sigprocmask')) { if (function_exists('pcntl_sigprocmask')) {
pcntl_sigprocmask(SIG_BLOCK, array(SIGIO)); pcntl_sigprocmask(SIG_BLOCK, array(SIGIO));
-1
View File
@@ -34,7 +34,6 @@ abstract class Process extends \Swoole\Process implements SProcess
public function __construct($application, $name, $enable_coroutine = true) public function __construct($application, $name, $enable_coroutine = true)
{ {
parent::__construct([$this, '_load'], false, 1, $enable_coroutine); parent::__construct([$this, '_load'], false, 1, $enable_coroutine);
$this->application = $application;
Snowflake::setProcessId($this->pid); Snowflake::setProcessId($this->pid);
} }
+3 -3
View File
@@ -265,8 +265,8 @@ class ServerInotify extends Process
if (str_contains($message, 'The file descriptor is not an inotify instance')) { if (str_contains($message, 'The file descriptor is not an inotify instance')) {
return; return;
} }
$this->application->debug('Error:' . $message); logger()->debug('Error:' . $message);
$this->application->debug($file . ':' . $line); logger()->debug($file . ':' . $line);
} }
@@ -279,7 +279,7 @@ class ServerInotify extends Process
{ {
//目录不存在 //目录不存在
if (!is_dir($dir)) { if (!is_dir($dir)) {
return $this->application->addError("[$dir] is not a directory."); return logger()->addError("[$dir] is not a directory.");
} }
//避免重复监听 //避免重复监听
if (isset($this->watchFiles[$dir])) { if (isset($this->watchFiles[$dir])) {