se estan creando el registro de las tareas sin problemas
This commit is contained in:
@@ -2,6 +2,7 @@ from fastapi import APIRouter, BackgroundTasks, status, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
from .schemas import RemesaBaseSchema
|
||||
from .tasks import process_remesa_request
|
||||
from api.api_v2.modules.tasks.services import register_task
|
||||
import logging
|
||||
logger = logging.getLogger("app.api")
|
||||
|
||||
@@ -14,8 +15,16 @@ async def download_remesa(remesa_request: RemesaBaseSchema):
|
||||
"""
|
||||
remesa_dict = remesa_request.model_dump()
|
||||
|
||||
|
||||
# Ejecuta la tarea de Celery de forma asíncrona
|
||||
task = process_remesa_request.delay(remesa_dict)
|
||||
# Registrar la tarea en el servicio de seguimiento
|
||||
await register_task(
|
||||
task_id=task.id,
|
||||
message=f"Procesando descarga de remesa {remesa_dict.get('remesa', 'N/A')}",
|
||||
status="submitted",
|
||||
pedimento_id=remesa_dict.get('pedimento', {}).get('id'),
|
||||
organizacion_id=remesa_dict.get('pedimento', {}).get('organizacion'),
|
||||
servicio=5 # 5 corresponde a "Pedimento Remesas"
|
||||
)
|
||||
# Puedes devolver el ID de la tarea para consultar el estado después
|
||||
return {"status": "submitted", "detail": "La solicitud de descarga de la remesa ha sido enviada.", "task_id": task.id}
|
||||
|
||||
@@ -13,6 +13,7 @@ from .controllers import remesa_rest_controller, remesa_vu_controller, remesa_xm
|
||||
|
||||
|
||||
from utils.helpers import soap_error
|
||||
from ..common import create_service_response, create_error_response
|
||||
|
||||
# Logger configurado para el módulo
|
||||
logger = logging.getLogger("app.api")
|
||||
@@ -71,11 +72,8 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]:
|
||||
)
|
||||
# Generar nombre de archivo
|
||||
file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}.xml"
|
||||
|
||||
# Enviar documento
|
||||
try:
|
||||
if soap_error(soap_response):
|
||||
file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}.xml"
|
||||
if soap_error(soap_response):
|
||||
file_name = f"vu_RM_{pedimento_data.get('pedimento_app', 'unknown')}_ERROR.xml"
|
||||
document_response = await remesa_rest_controller.post_document(
|
||||
soap_response=soap_response,
|
||||
organizacion=pedimento_data.get('organizacion'),
|
||||
@@ -84,15 +82,17 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]:
|
||||
document_type=10,
|
||||
)
|
||||
raise HTTPException(status_code=500, detail="Error en la respuesta del servicio SOAP")
|
||||
else:
|
||||
document_response = await remesa_rest_controller.post_document(
|
||||
soap_response=soap_response,
|
||||
organizacion=pedimento_data.get('organizacion'),
|
||||
pedimento=pedimento_data.get('id'),
|
||||
file_name=file_name,
|
||||
document_type=3,
|
||||
)
|
||||
|
||||
# Enviar documento
|
||||
try:
|
||||
|
||||
document_response = await remesa_rest_controller.post_document(
|
||||
soap_response=soap_response,
|
||||
organizacion=pedimento_data.get('organizacion'),
|
||||
pedimento=pedimento_data.get('id'),
|
||||
file_name=file_name,
|
||||
document_type=3,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error al enviar documento: {e}")
|
||||
raise HTTPException(status_code=500, detail="Error al guardar documento")
|
||||
@@ -108,10 +108,19 @@ async def obtener_remesa(**kwargs) -> Dict[str, Any]:
|
||||
|
||||
logger.info(f"Remesa procesada exitosamente: {pedimento_data.get('pedimento')}")
|
||||
|
||||
return {
|
||||
"documento": document_response,
|
||||
"xml_content": remesas_data
|
||||
}
|
||||
return create_service_response(
|
||||
message="Remesa procesada exitosamente",
|
||||
data={
|
||||
"documento": document_response,
|
||||
"xml_content": remesas_data
|
||||
},
|
||||
metadata={
|
||||
"file_name": file_name,
|
||||
"document_type": 3,
|
||||
"pedimento_app": pedimento_data.get('pedimento_app'),
|
||||
"organizacion": pedimento_data.get('organizacion')
|
||||
}
|
||||
)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
@@ -170,7 +179,17 @@ async def post_remesa_data(**kwargs) -> Dict[str, Any]:
|
||||
|
||||
|
||||
logger.info("Procesamiento de pedimento completo finalizado")
|
||||
return result
|
||||
|
||||
# Crear respuesta estandarizada
|
||||
return create_service_response(
|
||||
success=True,
|
||||
message="Procesamiento de remesa completado",
|
||||
data=result,
|
||||
warnings=[result["coves_error"]] if result.get("coves_error") else None,
|
||||
metadata={
|
||||
"total_coves_procesados": len(result.get("coves_procesados", [])) if result.get("coves_procesados") else 0
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user