71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?php namespace App\Jobs;
|
|
|
|
use App\Services\VehicleService;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ProcesarDeteccionVehiculo implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/**
|
|
* Número de intentos antes de marcar como fallido
|
|
*/
|
|
public $tries = 3;
|
|
|
|
/**
|
|
* Timeout en segundos (2 minutos)
|
|
*/
|
|
public $timeout = 120;
|
|
|
|
/**
|
|
* Tiempo entre reintentos en segundos
|
|
*/
|
|
public $backoff = 10;
|
|
|
|
/**
|
|
* Constructor del Job
|
|
*/
|
|
public function __construct(
|
|
public string $fastId,
|
|
public int $arcoId,
|
|
public ?string $antena = null
|
|
) {}
|
|
|
|
/**
|
|
* Ejecutar el job
|
|
*/
|
|
public function handle(VehicleService $vehicleService): void
|
|
{
|
|
try {
|
|
// Procesar la detección usando el servicio
|
|
$vehicleService->procesarDeteccion(
|
|
$this->fastId,
|
|
$this->arcoId,
|
|
$this->antena
|
|
);
|
|
} catch (\Exception $e) {
|
|
// Re-lanzar la excepción para que Laravel reintente el job
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Manejar fallo del job después de todos los reintentos
|
|
*/
|
|
public function failed(\Throwable $exception): void
|
|
{
|
|
Log::error('ProcesarDeteccionVehiculo: FALLIDO después de todos los intentos', [
|
|
'fast_id' => $this->fastId,
|
|
'arco_id' => $this->arcoId,
|
|
'antena' => $this->antena,
|
|
'error' => $exception->getMessage(),
|
|
'intentos_realizados' => $this->tries
|
|
]);
|
|
}
|
|
}
|