sbt-idp/cope2n-ai-fi/celery_worker/mock_process_tasks_fi.py

84 lines
3.3 KiB
Python
Raw Normal View History

2023-11-30 11:22:16 +00:00
from celery_worker.worker_fi import app
2023-12-22 07:03:56 +00:00
from celery_worker.client_connector_fi import CeleryConnector
from common.process_pdf import compile_output_sbt
2024-07-05 13:14:47 +00:00
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__)
2023-11-30 11:22:16 +00:00
2024-07-05 13:14:47 +00:00
@app.task(base=VerboseTask,name="process_fi_invoice")
2023-11-30 11:22:16 +00:00
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"}
2024-07-05 13:14:47 +00:00
logger.info(hoadon)
2023-11-30 11:22:16 +00:00
c_connector.process_fi_invoice_result((rq_id, hoadon))
return {"rq_id": rq_id}
except Exception as e:
2024-07-05 13:14:47 +00:00
logger.info(e)
2023-11-30 11:22:16 +00:00
hoadon = {"status": 404, "content": {}}
c_connector.process_fi_invoice_result((rq_id, hoadon))
return {"rq_id": rq_id}
2024-07-05 13:14:47 +00:00
@app.task(base=VerboseTask,name="process_sap_invoice")
2023-11-30 11:22:16 +00:00
def process_sap_invoice(rq_id, list_url):
from celery_worker.client_connector_fi import CeleryConnector
from common.process_pdf import compile_output
2024-07-05 13:14:47 +00:00
logger.info(list_url)
2023-11-30 11:22:16 +00:00
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:
2024-07-05 13:14:47 +00:00
logger.info(e)
2023-11-30 11:22:16 +00:00
hoadon = {"status": 404, "content": {}}
c_connector.process_sap_invoice_result((rq_id, hoadon))
return {"rq_id": rq_id}
2024-07-05 13:14:47 +00:00
@app.task(base=VerboseTask,name="process_manulife_invoice")
2023-11-30 11:22:16 +00:00
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"}
2024-07-05 13:14:47 +00:00
logger.info(hoadon)
2023-11-30 11:22:16 +00:00
c_connector.process_manulife_invoice_result((rq_id, hoadon))
return {"rq_id": rq_id}
except Exception as e:
2024-07-05 13:14:47 +00:00
logger.info(e)
2023-11-30 11:22:16 +00:00
hoadon = {"status": 404, "content": {}}
c_connector.process_manulife_invoice_result((rq_id, hoadon))
return {"rq_id": rq_id}
2024-07-05 13:14:47 +00:00
@app.task(base=VerboseTask,name="process_sbt_invoice")
def process_sbt_invoice(rq_id, list_url, metadata):
2023-11-30 11:22:16 +00:00
# TODO: simply returning 200 and 404 doesn't make any sense
c_connector = CeleryConnector()
try:
2024-04-05 11:50:41 +00:00
result = compile_output_sbt(list_url, metadata)
metadata['ai_inference_profile'] = result.pop("inference_profile")
2023-11-30 11:22:16 +00:00
hoadon = {"status": 200, "content": result, "message": "Success"}
2024-07-05 13:14:47 +00:00
logger.info(hoadon)
c_connector.process_sbt_invoice_result((rq_id, hoadon, metadata))
2023-11-30 11:22:16 +00:00
return {"rq_id": rq_id}
except Exception as e:
2024-07-05 13:14:47 +00:00
logger.info(f"[ERROR]: Failed to extract invoice: {e}")
logger.info(e)
2023-11-30 11:22:16 +00:00
hoadon = {"status": 404, "content": {}}
c_connector.process_sbt_invoice_result((rq_id, hoadon, metadata))
2023-11-30 11:22:16 +00:00
return {"rq_id": rq_id}