feat(ogcore): update client status from agent heartbeat busy field #109

Merged
narenas merged 1 commits from notify_ogagent_status into main 2026-05-08 07:10:06 +02:00
3 changed files with 46 additions and 8 deletions

View File

@ -65,14 +65,16 @@ class PowerOffAction extends AbstractOgAgentController
token: $client->getToken(),
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
$this->logger->error('Error powering off client', ['client' => $client->getId(), 'error' => $response['error']]);
$isBusy = isset($response['code']) && $response['code'] === Response::HTTP_CONFLICT;
$isError = isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR;
if ($isBusy || $isError) {
if ($isError) {
$this->logger->error('Error powering off client', ['client' => $client->getId(), 'error' => $response['error']]);
}
if ($input->queue) {
$this->createService->__invoke($client, CommandTypes::SHUTDOWN, TraceStatus::PENDING, null, []);
continue;
}
continue;
}

View File

@ -50,12 +50,13 @@ class RebootAction extends AbstractOgAgentController
token: $client->getToken(),
);
if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) {
$isBusy = isset($response['code']) && $response['code'] === Response::HTTP_CONFLICT;
$isError = isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR;
if ($isBusy || $isError) {
if ($input->queue) {
$this->createService->__invoke($client, CommandTypes::REBOOT, TraceStatus::PENDING, null, []);
continue;
}
continue;
}

View File

@ -81,6 +81,33 @@ class StatusController extends AbstractController
}
$client->setUpdatedAt(new \DateTime());
if (isset($data['busy'])) {
$previousStatus = $client->getStatus();
if ($data['busy'] === true) {
$client->setStatus(ClientStatus::BUSY);
$this->logger->info('Heartbeat: client marked as busy', [
'ip' => $data['iph'], 'previous_status' => $previousStatus, 'st' => $data['st'] ?? null,
]);
} elseif ($data['busy'] === false && $previousStatus === ClientStatus::BUSY) {
$idleStatusMap = [
'OGL' => ClientStatus::OG_LIVE,
'LNX' => ClientStatus::LINUX,
'WIN' => ClientStatus::WINDOWS,
'OSX' => ClientStatus::MACOS,
];
$newStatus = $idleStatusMap[$data['st'] ?? ''] ?? ClientStatus::OG_LIVE;
$client->setStatus($newStatus);
$this->logger->info('Heartbeat: client no longer busy', [
'ip' => $data['iph'], 'previous_status' => $previousStatus, 'new_status' => $newStatus, 'st' => $data['st'] ?? null,
]);
} else {
$this->logger->info('Heartbeat: no status change', [
'ip' => $data['iph'], 'current_status' => $previousStatus, 'busy' => $data['busy'], 'st' => $data['st'] ?? null,
]);
}
}
$this->entityManager->persist($client);
$this->entityManager->flush();
}
@ -111,10 +138,18 @@ class StatusController extends AbstractController
$this->entityManager->persist($trace);
}
if ($client->getStatus() === ClientStatus::BUSY) {
$previousStatus = $client->getStatus();
if ($previousStatus === ClientStatus::BUSY) {
$newStatus = ($data['nfn'] === 'REBOOT') ? ClientStatus::INITIALIZING : ClientStatus::TURNING_OFF;
$client->setStatus($newStatus);
$this->entityManager->persist($client);
$this->logger->info('Reboot/Poweroff received while client was busy, changing status', [
'ip' => $clientIp, 'nfn' => $data['nfn'], 'previous_status' => $previousStatus, 'new_status' => $newStatus,
]);
} else {
$this->logger->info('Reboot/Poweroff received but client was not busy, status unchanged', [
'ip' => $clientIp, 'nfn' => $data['nfn'], 'current_status' => $previousStatus,
]);
}
$this->entityManager->flush();