sbt-idp/cope2n-ai-fi/celery_worker/mock_process_tasks_fi.py
PhanThanhTrung 5bcbc257de update
2024-10-29 15:03:31 +07:00

35 lines
1.3 KiB
Python
Executable File

import logging
import logging.config
from opentelemetry import trace
from celery_worker.client_connector_fi import CeleryConnector
from celery_worker.worker_fi import app
from common.process_pdf import compile_output_sbt
from utils.logging.logging import LOGGER_CONFIG
from .task_warpper import VerboseTask
# Load the logging configuration
logging.config.dictConfig(LOGGER_CONFIG)
# Get the logger
logger = logging.getLogger(__name__)
tracer = trace.get_tracer("sbt_celery_ai")
@app.task(base=VerboseTask,name="process_sbt_invoice", track_started=True)
def process_sbt_invoice(rq_id, list_url, metadata):
# TODO: simply returning 200 and 404 doesn't make any sense
c_connector = CeleryConnector()
try:
result = compile_output_sbt(list_url, metadata)
metadata['ai_inference_profile'] = result.pop("inference_profile")
hoadon = {"status": 200, "content": result, "message": "Success"}
logger.info(hoadon)
c_connector.process_sbt_invoice_result((rq_id, hoadon, metadata))
return {"rq_id": rq_id}
except Exception as e:
logger.info(f"[ERROR]: Failed to extract invoice: {e}")
logger.info(e)
hoadon = {"status": 404, "content": {}}
c_connector.process_sbt_invoice_result((rq_id, hoadon, metadata))
return {"rq_id": rq_id}