更新模块

This commit is contained in:
iVampireSP.com 2022-11-23 03:10:36 +00:00
parent 83613ac5d6
commit 08bedaa67b
2 changed files with 19 additions and 4 deletions

View File

@ -32,11 +32,15 @@ public function __construct()
*/ */
public function handle() public function handle()
{ {
// now 添加1.5小时 // 删除所有模块中不存在的主机
//
Host::with('module')->where('created_at', '<', now()->subHour())->chunk(100, function ($hosts) { Host::with('module')->where('created_at', '<', now()->subHour())->chunk(100, function ($hosts) {
foreach ($hosts as $host) { foreach ($hosts as $host) {
// 忽略维护中的模块
if ($host->module->status !== 'up') {
continue;
}
$http = Http::module($host->module->api_token, $host->module->url); $http = Http::module($host->module->api_token, $host->module->url);
$response = $http->get('hosts/' . $host->id); $response = $http->get('hosts/' . $host->id);

View File

@ -58,7 +58,6 @@ public function handle()
continue; continue;
} }
if ($response->successful()) { if ($response->successful()) {
$json = $response->json(); $json = $response->json();
@ -82,6 +81,18 @@ public function handle()
// $module->update([ // $module->update([
// 'data' => $response->json() // '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'
]);
}
} }
} }