From 29f7cdda9c85aecfd1bf31c4d71cf7f89a511e24 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 8 Feb 2023 14:18:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Cluster/Log.php | 15 +++++++-------- app/Support/ClusterSupport.php | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/Console/Commands/Cluster/Log.php b/app/Console/Commands/Cluster/Log.php index ce49425..f8791ef 100644 --- a/app/Console/Commands/Cluster/Log.php +++ b/app/Console/Commands/Cluster/Log.php @@ -40,18 +40,17 @@ private function format(string $event, array $message = []) { $status = $this->switch($event, $message['data']); - if (! $status) { + if (!$status) { return; } - $message = "[{$message['node']['type']}] {$message['node']['id']}:$event: ".$status; + $message = "[{$message['node']['type']}] {$message['node']['id']}:$event: " . $status; $this->info($message); } public function switch($event, $message = []): string|null { - // var_dump($event, $message); $events = [ 'node.ok' => '此节点初始化成功,并且已经加入集群。', 'node.online' => '此节点已经上线。', @@ -62,19 +61,19 @@ public function switch($event, $message = []): string|null 'config.synced' => '我已下载配置文件。', 'edge.deployed' => '已成功根据集群节点生成配置文件并应用。', 'edge.launched' => '边缘节点成功启动。', - 'edge.error' => $message['message'] ?? '未知错误', + 'edge.error' => fn($message) => $message['message'] ?? '未知错误', 'cluster.restart.web' => '正在重启 web 服务。', 'cluster.restart.all' => '正在重启 整个 服务。', 'cluster.restarted.web' => 'Web 重启好了。', 'cluster.restarted.all' => '整个 重启好了。', 'cluster.deployed' => '集群配置文件已经部署。', - 'cluster.deployed.error' => $message['message'] ?? '未知错误', + 'cluster.deployed.error' => fn($message) => $message['message'] ?? '未知错误', 'cluster.deployed.ok' => '集群配置文件部署成功。', - 'http.incoming' => fn ($message) => $this->handleIncomingRequest($message), - 'http.outgoing' => fn ($message) => $this->handleOutgoingRequest($message), + 'http.incoming' => fn($message) => $this->handleIncomingRequest($message), + 'http.outgoing' => fn($message) => $this->handleOutgoingRequest($message), ]; - $resp = $events[$event]; + $resp = $events[$event] ?? null; // if resp is callable if (is_callable($resp)) { diff --git a/app/Support/ClusterSupport.php b/app/Support/ClusterSupport.php index 7051da3..71b36ad 100644 --- a/app/Support/ClusterSupport.php +++ b/app/Support/ClusterSupport.php @@ -77,7 +77,7 @@ public static function listen(string|array $events, callable $callback, bool $ig ini_set('default_socket_timeout', -1); Redis::subscribe('cluster_ready', function ($message) use ($events, $callback, $ignore_self) { - echo $message; + // echo $message; $message = json_decode($message, true); if ($ignore_self && $message['node']['id'] === config('settings.node.id')) {