production-evyos-systems-an.../ServicesTask/app/services/parser/comment/main.py

41 lines
1.4 KiB
Python

import asyncio
from app.services.common.service_base_async import ServiceBaseAsync
from app.services.types.queue import Enqueue
from app.services.types.task import Job
from app.services.types.mail import MailParsedResult
from app.services.types.mail import PlainMailReader
from app.services.types.mail import ProcessMailObject
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):
print("Parser Comment Consumer from excel handle_excel_publish :", job)
job_model = Job(**job)
mail_id = job_model.payload['mail_id']
task_id = f"IsBankServiceCommentParser_{mail_id}"
await svc.enqueue(task_id=task_id, payload=job_model.payload, action="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())