from celery_worker.worker_fi import app from celery_worker.client_connector_fi import CeleryConnector from common.process_pdf import compile_output_sbt from .task_warpper import VerboseTask import logging import logging.config from utils.logging.logging import LOGGER_CONFIG # Load the logging configuration logging.config.dictConfig(LOGGER_CONFIG) # Get the logger logger = logging.getLogger(__name__) @app.task(base=VerboseTask,name="process_fi_invoice") def process_invoice(rq_id, list_url): from celery_worker.client_connector_fi import CeleryConnector from common.process_pdf import compile_output_fi c_connector = CeleryConnector() try: result = compile_output_fi(list_url) hoadon = {"status": 200, "content": result, "message": "Success"} logger.info(hoadon) c_connector.process_fi_invoice_result((rq_id, hoadon)) return {"rq_id": rq_id} except Exception as e: logger.info(e) hoadon = {"status": 404, "content": {}} c_connector.process_fi_invoice_result((rq_id, hoadon)) return {"rq_id": rq_id} @app.task(base=VerboseTask,name="process_sap_invoice") def process_sap_invoice(rq_id, list_url): from celery_worker.client_connector_fi import CeleryConnector from common.process_pdf import compile_output logger.info(list_url) c_connector = CeleryConnector() try: result = compile_output(list_url) hoadon = {"status": 200, "content": result, "message": "Success"} c_connector.process_sap_invoice_result((rq_id, hoadon)) return {"rq_id": rq_id} except Exception as e: logger.info(e) hoadon = {"status": 404, "content": {}} c_connector.process_sap_invoice_result((rq_id, hoadon)) return {"rq_id": rq_id} @app.task(base=VerboseTask,name="process_manulife_invoice") def process_manulife_invoice(rq_id, list_url): from celery_worker.client_connector_fi import CeleryConnector from common.process_pdf import compile_output_manulife # TODO: simply returning 200 and 404 doesn't make any sense c_connector = CeleryConnector() try: result = compile_output_manulife(list_url) hoadon = {"status": 200, "content": result, "message": "Success"} logger.info(hoadon) c_connector.process_manulife_invoice_result((rq_id, hoadon)) return {"rq_id": rq_id} except Exception as e: logger.info(e) hoadon = {"status": 404, "content": {}} c_connector.process_manulife_invoice_result((rq_id, hoadon)) return {"rq_id": rq_id} @app.task(base=VerboseTask,name="process_sbt_invoice") 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}