diff --git a/src/Controller/OgAgent/RunScriptAction.php b/src/Controller/OgAgent/RunScriptAction.php index 9ee287b..f380d39 100644 --- a/src/Controller/OgAgent/RunScriptAction.php +++ b/src/Controller/OgAgent/RunScriptAction.php @@ -47,6 +47,10 @@ class RunScriptAction extends AbstractOgAgentController $data = $this->buildRequestData($client, $input->script); $response = $this->executeScript($client, $data); + if (isset($response['code']) && $response['code'] === 409) { + continue; + } + if ($this->isErrorResponse($response)) { $this->handleError($client, $input, $response); continue; @@ -98,7 +102,7 @@ class RunScriptAction extends AbstractOgAgentController private function executeScript(Client $client, array $data): array { - return $this->createRequest( + $response = $this->createRequest( method: 'POST', url: 'https://'.$client->getIp().':8000/opengnsys/EjecutarScript', params: [ @@ -106,6 +110,23 @@ class RunScriptAction extends AbstractOgAgentController ], token: $client->getToken(), ); + + if (isset($response['code']) && $response['code'] === 409) { + $this->createService->__invoke( + $client, + CommandTypes::RUN_SCRIPT, + TraceStatus::BUSY, + null, + ['script' => $data['script'] ?? $data['scp'] ?? ''], + 'Some job is already running, refusing to launch another one' + ); + + $this->logger->info('Trace created as busy due to 409 response', [ + 'client_ip' => $client->getIp() + ]); + } + + return $response; } private function isErrorResponse(array $response): bool