From 08bedaa67bf38251641aa7fffb06a1392941c629 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 23 Nov 2022 03:10:36 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Jobs/CheckHostIfExistsOnModule.php | 10 +++++++--- app/Jobs/Module/FetchModule.php | 13 ++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/Jobs/CheckHostIfExistsOnModule.php b/app/Jobs/CheckHostIfExistsOnModule.php index 696dcab..430ed3a 100644 --- a/app/Jobs/CheckHostIfExistsOnModule.php +++ b/app/Jobs/CheckHostIfExistsOnModule.php @@ -32,11 +32,15 @@ public function __construct() */ public function handle() { - // now 添加1.5小时 - - // + // 删除所有模块中不存在的主机 Host::with('module')->where('created_at', '<', now()->subHour())->chunk(100, function ($hosts) { foreach ($hosts as $host) { + + // 忽略维护中的模块 + if ($host->module->status !== 'up') { + continue; + } + $http = Http::module($host->module->api_token, $host->module->url); $response = $http->get('hosts/' . $host->id); diff --git a/app/Jobs/Module/FetchModule.php b/app/Jobs/Module/FetchModule.php index 5615488..9de1e04 100644 --- a/app/Jobs/Module/FetchModule.php +++ b/app/Jobs/Module/FetchModule.php @@ -58,7 +58,6 @@ public function handle() continue; } - if ($response->successful()) { $json = $response->json(); @@ -82,6 +81,18 @@ public function handle() // $module->update([ // 'data' => $response->json() // ]); + } else { + + // if module return maintenance, then set module status to maintenance + if ($response->status() == 503) { + $module->update([ + 'status' => 'maintenance' + ]); + } else { + $module->update([ + 'status' => 'down' + ]); + } } }