fix(trace): ignore agent error on kill and always cancel trace
parent
82b2a4e460
commit
28c1d48ed8
|
|
@ -40,51 +40,20 @@ class KillJobService
|
|||
$client = $trace->getClient();
|
||||
|
||||
if ($client && $client->getIp()) {
|
||||
$clientIp = $client->getIp();
|
||||
$killed = false;
|
||||
|
||||
// 1. Intentar /opengnsys/KillJob (ogLive / nuevo ogagent)
|
||||
try {
|
||||
$response = $this->httpClient->request(
|
||||
$this->httpClient->request(
|
||||
'POST',
|
||||
'https://'.$clientIp.':8000/opengnsys/KillJob',
|
||||
'https://'.$client->getIp().':8000/opengnsys/KillJob',
|
||||
$this->buildRequestOptions(['json' => ['job_id' => $jobId]], $client->getToken())
|
||||
);
|
||||
$statusCode = $response->getStatusCode();
|
||||
if ($statusCode >= 200 && $statusCode < 300) {
|
||||
$killed = true;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->warning(sprintf('KillJob endpoint failed on client %s: %s', $clientIp, $e->getMessage()));
|
||||
}
|
||||
|
||||
// 2. Si KillJob devolvió 404 o falló, intentar fallback a /opengnsys/terminatescript (ogagent en Windows / Linux desktop)
|
||||
if (!$killed) {
|
||||
try {
|
||||
$response = $this->httpClient->request(
|
||||
'POST',
|
||||
'https://'.$clientIp.':8000/opengnsys/terminatescript',
|
||||
$this->buildRequestOptions(['json' => ['job_id' => $jobId]], $client->getToken())
|
||||
);
|
||||
$statusCode = $response->getStatusCode();
|
||||
if ($statusCode >= 200 && $statusCode < 300) {
|
||||
$killed = true;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->warning(sprintf('terminatescript endpoint also failed on client %s: %s', $clientIp, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
if ($killed) {
|
||||
$this->logger->info('Job successfully killed on client', ['client' => $client->getId(), 'job_id' => $jobId]);
|
||||
} else {
|
||||
$this->logger->warning('Could not signal agent to kill job (client may be offline or rebooting), cancelling trace locally', [
|
||||
'client' => $client->getId(),
|
||||
'job_id' => $jobId,
|
||||
]);
|
||||
// Si el trabajo ya no existe en el agente, da 404 o el cliente está apagado/reiniciando, se ignora
|
||||
$this->logger->info(sprintf('Could not notify agent on client %s: %s, cancelling trace locally', $client->getIp(), $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->info('Killing job', ['client' => $client?->getId(), 'job_id' => $jobId]);
|
||||
|
||||
$trace->setStatus(TraceStatus::CANCELLED);
|
||||
$trace->setFinishedAt(new \DateTime());
|
||||
$this->entityManager->persist($trace);
|
||||
|
|
|
|||
Loading…
Reference in New Issue