35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import asyncio
|
|
|
|
from app.services.common.service_base_async import ServiceBaseAsync, Job
|
|
|
|
|
|
PROCESS_SEC = 10
|
|
|
|
|
|
async def produce(_svc: ServiceBaseAsync):
|
|
# print("Parser Comment Producer produce :")
|
|
await asyncio.sleep(PROCESS_SEC)
|
|
|
|
|
|
async def handle_excel_publish(svc: ServiceBaseAsync, job: dict):
|
|
job_model = Job(**job)
|
|
mail_id = job_model.payload['mail_id']
|
|
task_id = f"IsBankServiceMailParser_{mail_id}"
|
|
await svc.enqueue(task_id=task_id, payload=job_model.payload, type_="parser.comment.publish")
|
|
print("Parser Comment Consumer from excel handle_excel_publish :", job_model.task_id)
|
|
await svc.ack_current()
|
|
await asyncio.sleep(PROCESS_SEC)
|
|
|
|
|
|
async def consume_default(svc: ServiceBaseAsync, job: dict):
|
|
job_model = Job(**job)
|
|
print("Parser Comment Consumer default :", job_model.task_id)
|
|
await asyncio.sleep(PROCESS_SEC)
|
|
await svc.ack_current()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"parser.excel.publish": handle_excel_publish})
|
|
asyncio.run(svc.run())
|