sbt-idp/cope2n-api/fwd_api/celery_worker/worker.py
2024-02-05 12:56:51 +07:00

75 lines
2.4 KiB
Python
Executable File

import os
import django
from celery import Celery
from kombu import Queue
from fwd import settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fwd.settings")
django.setup()
app: Celery = Celery(
'postman',
broker=settings.BROKER_URL,
include=['fwd_api.celery_worker.process_result_tasks', 'fwd_api.celery_worker.internal_task', 'fwd_api.celery_worker.process_report_tasks'],
broker_transport_options={'confirm_publish': False},
)
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
@app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
from fwd_api.bg_tasks.clean_local_files import clean_media
sender.add_periodic_task(
10.0, clean_media.s(), expires=120.0
)
app.conf.update({
'task_queues':
[
Queue('invoice_sap_rs'),
Queue('invoice_fi_rs'),
Queue('invoice_manulife_rs'),
Queue('invoice_sbt_rs'),
Queue('do_pdf'),
Queue('upload_file_to_s3'),
Queue('upload_feedback_to_s3'),
Queue('upload_obj_to_s3'),
Queue('upload_report_to_s3'),
Queue('remove_local_file'),
Queue('csv_feedback'),
Queue('report'),
Queue('report_2'),
],
'task_routes': {
'process_sap_invoice_result': {'queue': 'invoice_sap_rs'},
'process_sap_invoice': {'queue': "invoice_sap"},
'process_fi_invoice_result': {'queue': 'invoice_fi_rs'},
'process_fi_invoice': {'queue': "invoice_fi"},
'process_manulife_invoice_result': {'queue': 'invoice_manulife_rs'},
'process_manulife_invoice': {'queue': "invoice_manulife"},
'process_sbt_invoice_result': {'queue': 'invoice_sbt_rs'},
'process_sbt_invoice': {'queue': "invoice_sbt"},
'do_pdf': {'queue': "do_pdf"},
'upload_file_to_s3': {'queue': "upload_file_to_s3"},
'upload_feedback_to_s3': {'queue': "upload_feedback_to_s3"},
'upload_obj_to_s3': {'queue': "upload_obj_to_s3"},
'upload_report_to_s3': {'queue': "upload_report_to_s3"},
'remove_local_file': {'queue': "remove_local_file"},
'csv_feedback': {'queue': "csv_feedback"},
'make_a_report': {'queue': "report"},
'make_a_report_2': {'queue': "report_2"},
}
})
if __name__ == "__main__":
argv = [
'worker',
'--loglevel=INFO',
'--pool=solo' # Window opts
]
app.worker_main(argv)