modificacion en el StatusController para capturar el cambio de estado ante un reboot o poweroff del cliente
testing/ogcore-api/pipeline/head This commit looks good
Details
testing/ogcore-api/pipeline/head This commit looks good
Details
parent
cd5eaf94e3
commit
76f2722676
|
|
@ -96,6 +96,28 @@ class StatusController extends AbstractController
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['nfn']) && in_array($data['nfn'], ['REBOOT', 'POWEROFF'], true)) {
|
||||
$clientIp = $data['iph'] ?? $request->getClientIp();
|
||||
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]);
|
||||
if ($client) {
|
||||
$traces = $this->entityManager->getRepository(Trace::class)->findBy(['client' => $client, 'status' => TraceStatus::IN_PROGRESS]);
|
||||
foreach ($traces as $trace) {
|
||||
$trace->setStatus(TraceStatus::SUCCESS);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->persist($trace);
|
||||
}
|
||||
|
||||
if ($client->getStatus() === ClientStatus::BUSY) {
|
||||
$newStatus = ($data['nfn'] === 'REBOOT') ? ClientStatus::INITIALIZING : ClientStatus::TURNING_OFF;
|
||||
$client->setStatus($newStatus);
|
||||
$this->entityManager->persist($client);
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
$this->logger->info('Reboot/Poweroff webhook received. Automatically resolved in-progress traces.', ['num_traces' => count($traces), 'nfn' => $data['nfn']]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['progress'])){
|
||||
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue