refs #952. First revision status endpoint ogAgent
testing/ogcore-api/pipeline/head Something is wrong with the build of this commit Details

develop-jenkins
Manuel Aranda Rosales 2024-10-22 22:20:21 +02:00
parent 756bea4844
commit 0c94a1921e
1 changed files with 10 additions and 14 deletions

View File

@ -45,27 +45,23 @@ class StatusAction extends AbstractController
}
try {
$response = $this->httpClient->request('POST', 'https://'.$client->getIp().':8000/ogAdmClient/status');
$response = $this->httpClient->request('POST', 'https://' . $client->getIp() . ':8000/ogAdmClient/status');
if ($response->getStatusCode() !== Response::HTTP_OK) {
$client->setStatus('off');
$this->entityManager->persist($client);
$this->entityManager->flush();
} else if ($response->getStatusCode() === Response::HTTP_OK) {
$client->setStatus('active');
$this->entityManager->persist($client);
$this->entityManager->flush();
}
$statusCode = $response->getStatusCode();
$client->setStatus($statusCode === Response::HTTP_OK ? 'active' : 'off');
} catch (TransportExceptionInterface $e) {
$client->setStatus('off');
$this->entityManager->persist($client);
$this->entityManager->flush();
return new JsonResponse( data: 'An error occurred', status: Response::HTTP_INTERNAL_SERVER_ERROR);
return new JsonResponse(
data: ['error' => 'An error occurred while communicating with the client'],
status: Response::HTTP_INTERNAL_SERVER_ERROR
);
}
$this->entityManager->persist($client);
$this->entityManager->flush();
return new JsonResponse(status: Response::HTTP_OK);
}
}