Fixed sync error
testing/ogcore-api/pipeline/head There was a failure building this commit Details

pull/102/head
Manuel Aranda Rosales 2026-04-29 11:38:37 +02:00
parent a5a0f60c59
commit 40be572cfc
3 changed files with 41 additions and 0 deletions

View File

@ -47,6 +47,7 @@ class StatusController extends AbstractController
const string REFRESH = 'RESPUESTA_Actualizar';
const string SOFTWARE_INVENTORY = 'RESPUESTA_InventarioSoftware';
const string RUN_SCRIPT = 'RESPUESTA_EjecutarScript';
const string INICIAR_SESION = 'RESPUESTA_IniciarSesion';
public function __construct(
protected readonly EntityManagerInterface $entityManager,
@ -355,6 +356,32 @@ class StatusController extends AbstractController
$this->entityManager->flush();
}
if (isset($data['nfn']) && $data['nfn'] === self::INICIAR_SESION) {
$clientIp = $data['iph'] ?? $request->getClientIp();
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]);
if ($client && isset($data['res']) && (int) $data['res'] !== 1) {
// IniciarSesion failed on the agent side; re-queue the login trace
$trace = $this->entityManager->getRepository(Trace::class)->findOneBy([
'client' => $client,
'command' => CommandTypes::LOGIN,
'status' => TraceStatus::PENDING,
]);
if (!$trace) {
$this->logger->warning('RESPUESTA_IniciarSesion: failure, no pending trace to retry', [
'ip' => $clientIp,
'job_id' => $data['job_id'] ?? null,
'res' => $data['res'] ?? null,
]);
} else {
$this->logger->warning('RESPUESTA_IniciarSesion: failure, trace kept pending for retry', [
'ip' => $clientIp,
'trace_id' => $trace->getId(),
'res' => $data['res'] ?? null,
]);
}
}
}
return new JsonResponse(data: 'Webhook finished', status: Response::HTTP_OK);
}

View File

@ -3,6 +3,7 @@
namespace App\EventListener;
use App\Entity\Client;
use App\Model\ClientStatus;
use App\Service\UDS\UDSClient;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PostFlushEventArgs;
@ -37,6 +38,14 @@ class UdsSyncOnClientStatusListener
return;
}
// INITIALIZING is a transient state set during the RemotePC reserve flow.
// Syncing with UDS at this point sends max_srvs=0/visible=false, which causes
// UDS to cancel the active reservation with an unreserve call after ~20 seconds.
[, $newStatus] = $changeSet['status'];
if ($newStatus === ClientStatus::INITIALIZING) {
return;
}
$ou = $entity->getOrganizationalUnit();
if (!$ou || !$ou->getRemoteCalendar()) {
return;

View File

@ -231,6 +231,11 @@ class UDSClient
continue;
}
$remotePC = $client->getRemotePC();
if ($remotePC && $remotePC->isReservedActive()) {
continue;
}
if ($imageId !== null && !$this->clientHasImage($client, $imageId)) {
continue;
}