Logs al job de repuve nacional

This commit is contained in:
Juan Felipe Zapata Moreno 2025-12-01 11:41:39 -06:00
parent ac57bdcbc4
commit b25db1a0d4
2 changed files with 54 additions and 5 deletions

View File

@ -5,6 +5,7 @@
use App\Services\RepuveService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
/*
*
@ -14,8 +15,8 @@ class ProcessRepuveResponse implements ShouldQueue
use Queueable;
public int $tries = 2;
public int $timeout = 120;
public array $backoff = [15, 30];
public int $timeout = 250;
public array $backoff = [30];
/**
* Crear instancia del trabajo
@ -32,20 +33,43 @@ public function handle(RepuveService $repuveService): void
{
$record = Record::findOrFail($this->recordId);
Log::info('ProcessRepuveResponse: Enviando inscripción a REPUVE Nacional...', [
'niv' => $this->responseData['niv'] ?? 'N/A',
'placa' => $this->responseData['placa'] ?? 'N/A',
]);
$apiResponse = $repuveService->inscribirVehiculo($this->responseData);
if(isset($apiResponse['repuve_response'])){
Log::info('📥 ProcessRepuveResponse: Respuesta recibida de REPUVE', [
'has_error' => $apiResponse['has_error'],
'error_code' => $apiResponse['error_code'] ?? null,
'timestamp' => $apiResponse['timestamp'] ?? null,
]);
if(isset($apiResponse['repuve_response']) && is_array($apiResponse['repuve_response'])){
$apiResponse['repuve_response']['folio_ci'] = $record->folio;
$apiResponse['repuve_response']['identificador_ci'] = $record->vehicle->tag->tag_number;
}
if($apiResponse['has_error']){
$error = Error::where('code', $apiResponse['error_code'])->first();
Log::error('ProcessRepuveResponse: Error en respuesta REPUVE', [
'error_code' => $apiResponse['error_code'],
'error_message' => $apiResponse['error_message'] ?? 'Sin mensaje',
'error_found_in_db' => $error ? 'Sí' : 'No',
]);
$record->update([
'error_id' => $error?->id,
'api_response' => $apiResponse,
'error_occurred_at' => now(),
]);
Log::warning('💾 ProcessRepuveResponse: Record actualizado con error', [
'record_id' => $record->id,
'error_id' => $error?->id,
]);
} else {
$record->update([
'error_id' => null,
@ -57,17 +81,42 @@ public function handle(RepuveService $repuveService): void
public function failed(\Throwable $exception): void
{
Log::critical('ProcessRepuveResponse: Job FALLÓ después de todos los intentos', [
'record_id' => $this->recordId,
'exception_class' => get_class($exception),
'exception_message' => $exception->getMessage(),
'exception_file' => $exception->getFile(),
'exception_line' => $exception->getLine(),
'attempts' => $this->attempts(),
]);
$record = Record::find($this->recordId);
if($record){
Log::info('🔍 ProcessRepuveResponse: Buscando error genérico código -1');
$error = Error::where('code', '-1')->first();
if(!$error){
Log::warning('ProcessRepuveResponse: Error código -1 NO encontrado en BD');
}
$record->update([
'error_id' => $error->id,
'error_id' => $error?->id,
'api_response' => [
'has_error' => true,
'error_message' => $exception->getMessage(),
],
'error_occurred_at' => now(),
]);
Log::error('ProcessRepuveResponse: Record actualizado con error crítico', [
'record_id' => $record->id,
'error_id' => $error?->id,
]);
} else {
Log::error('ProcessRepuveResponse: Record NO encontrado', [
'record_id' => $this->recordId,
]);
}
}
}

View File

@ -220,7 +220,7 @@ public function inscribirVehiculo(array $datos)
$datos['nombre'] ?? '', // 24. Nombre
$datos['ap_paterno'] ?? '', // 25. Apellido paterno
$datos['ap_materno'] ?? '', // 26. Apellido materno
$datos['ent_fed'] ?? '', // 27. Entidad federativa propietario (repetido?)
$datos['ent_fed'] ?? '', // 27. Entidad federativa propietario
$datos['munic'] ?? '', // 28. Municipio
$datos['callep'] ?? '', // 29. Calle principal
$datos['num_ext'] ?? '', // 30. Número exterior