From 28c1d48ed8b2cca89856ccad56a77751a3af66d1 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 26 Oct 2026 15:25:53 +0100 Subject: [PATCH] fix(trace): ignore agent error on kill and always cancel trace --- src/Service/Trace/KillJobService.php | 43 ++++------------------------ 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/Service/Trace/KillJobService.php b/src/Service/Trace/KillJobService.php index 1f017b2..03b5185 100644 --- a/src/Service/Trace/KillJobService.php +++ b/src/Service/Trace/KillJobService.php @@ -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);