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' + ]); + } } }