se estan creando el registro de las tareas sin problemas
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
import logging
|
||||
import httpx
|
||||
from typing import Dict, Any
|
||||
from fastapi import HTTPException
|
||||
from ..common import create_error_response
|
||||
from core.config import settings
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def register_task(
|
||||
task_id: str,
|
||||
message: str,
|
||||
status: str,
|
||||
pedimento_id: str,
|
||||
organizacion_id: str,
|
||||
servicio: int
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Registra una tarea en el servicio de seguimiento.
|
||||
|
||||
Args:
|
||||
task_id: ID de la tarea de Celery
|
||||
message: Mensaje descriptivo de la tarea
|
||||
status: Estado actual de la tarea
|
||||
pedimento_id: ID del pedimento asociado
|
||||
organizacion_id: ID de la organización
|
||||
servicio: ID del tipo de servicio
|
||||
1: Estado de pedimento
|
||||
2: Listado de pedimentos
|
||||
3: Pedimento Completo
|
||||
4: Pedimento Partidas
|
||||
5: Pedimento Remesas
|
||||
6: Acuse
|
||||
7: EDocument
|
||||
8: Cove
|
||||
9: Acuse Cove
|
||||
|
||||
Returns:
|
||||
Dict con la respuesta del servicio
|
||||
"""
|
||||
try:
|
||||
headers = {
|
||||
"Authorization": f"Token {settings.API_TOKEN}"
|
||||
}
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(
|
||||
f"{settings.API_URL}/tasks/tasks/",
|
||||
json={
|
||||
"task_id": task_id,
|
||||
"message": message,
|
||||
"status": status,
|
||||
"pedimento": pedimento_id,
|
||||
"organizacion": organizacion_id,
|
||||
"servicio": servicio
|
||||
},
|
||||
headers=headers
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except httpx.HTTPError as e:
|
||||
logger.error(f"Error al registrar tarea {task_id}: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=create_error_response(
|
||||
message="Error al registrar la tarea",
|
||||
errors=[str(e)],
|
||||
metadata={
|
||||
"task_id": task_id,
|
||||
"status": status,
|
||||
"pedimento": pedimento_id
|
||||
}
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Error inesperado al registrar tarea {task_id}: {str(e)}")
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=create_error_response(
|
||||
message="Error inesperado al registrar la tarea",
|
||||
errors=[str(e)],
|
||||
metadata={"task_id": task_id}
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user