parser excel publish chain task build

This commit is contained in:
2025-08-18 18:31:29 +03:00
parent 61529f7d94
commit e4f6afbc93
9 changed files with 91 additions and 75 deletions

View File

@@ -1,30 +1,34 @@
import asyncio
from app.services.common.service_base_async import ServiceBaseAsync
from app.services.common.service_base_async import ServiceBaseAsync, Job
PROCESS_SEC = 10
async def handle_mail_publish(svc: ServiceBaseAsync, job: dict):
async def produce(_svc: ServiceBaseAsync):
# print("Parser Comment Producer produce :")
await asyncio.sleep(PROCESS_SEC)
print("Parser Mail Consumer parsed:", job)
# await svc.ack_current()
# await svc.enqueue({"source": "parser-mail", "from_task": job}, "parser-mail-done", routing_key="parser.comment.publish")
async def consume_default(svc: ServiceBaseAsync, job):
print("Parser Mail Consumer default:", job)
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()
async def produce(_svc: ServiceBaseAsync):
print("Parser Mail Producer produce")
await asyncio.sleep(PROCESS_SEC)
if __name__ == "__main__":
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"mail.service.publish": handle_mail_publish})
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"parser.excel.publish": handle_excel_publish})
asyncio.run(svc.run())

View File

@@ -15,7 +15,8 @@ authors = [
dependencies = [
"aio-pika>=9.4.1",
"prometheus-client>=0.20.0",
"uvloop>=0.19.0"
"uvloop>=0.19.0",
"pydantic"
]
[project.optional-dependencies]