改进 状态处理
This commit is contained in:
parent
71ab005e07
commit
4a3f6d20ff
@ -7,6 +7,7 @@
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
// use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
|
||||
@ -54,6 +55,15 @@ public function handle(): void
|
||||
|
||||
$host->load(['module']);
|
||||
|
||||
if ($host->module->status !== 'up') {
|
||||
Log::warning('模块不可用,跳过主机更新。', [
|
||||
'host' => $host->name,
|
||||
'module' => $host->module->name,
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->type) {
|
||||
case 'patch':
|
||||
$response = $host->module->http()->patch('hosts/'.$host->id, $host->toArray());
|
||||
|
@ -42,7 +42,13 @@ public function handle(): void
|
||||
try {
|
||||
$response = $module->http()->get('remote');
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error('无法连接到模块 - down: '.$e->getMessage());
|
||||
|
||||
// 如果模块状态不为 down,则更新为 down
|
||||
if ($module->status !== 'down') {
|
||||
$module->status = 'down';
|
||||
$module->save();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -51,6 +57,7 @@ public function handle(): void
|
||||
// 如果模块状态不为 up,则更新为 up
|
||||
if ($module->status !== 'up') {
|
||||
$module->status = 'up';
|
||||
Log::error('模块状态更新为 up: '.$module->name);
|
||||
}
|
||||
|
||||
$json = $response->json();
|
||||
|
@ -31,6 +31,7 @@ class Module extends Authenticatable
|
||||
'id',
|
||||
'name',
|
||||
'api_token',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@ -118,7 +119,6 @@ private function getResponse(Response $response): array
|
||||
* @param $method
|
||||
* @param $path
|
||||
* @param $requests
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function request($method, $path, $requests): array
|
||||
@ -126,7 +126,8 @@ public function request($method, $path, $requests): array
|
||||
try {
|
||||
return $this->baseRequest($method, "functions/$path", $requests);
|
||||
} catch (ConnectException|ConnectionException $e) {
|
||||
Log::error('在执行 call ' . $method . ' ' . $path . ' 时发生错误: ' . $e->getMessage());
|
||||
Log::error('在执行 call '.$method.' '.$path.' 时发生错误: '.$e->getMessage());
|
||||
|
||||
return [
|
||||
'body' => null,
|
||||
'json' => null,
|
||||
|
Loading…
Reference in New Issue
Block a user