更新模块
This commit is contained in:
parent
83613ac5d6
commit
08bedaa67b
@ -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);
|
||||||
|
|
||||||
|
@ -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'
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user