parser excel publish chain task build
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import os
|
||||
import uuid
|
||||
import asyncio
|
||||
|
||||
from app.services.common.service_base_async import ServiceBaseAsync
|
||||
from app.services.common.service_base_async import ServiceBaseAsync, Job
|
||||
|
||||
|
||||
PRODUCE_BURST = int(os.getenv("PRODUCE_BURST", "10"))
|
||||
@@ -13,28 +12,29 @@ PROCESS_SEC = 10
|
||||
|
||||
async def produce(svc: ServiceBaseAsync):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
print(f"Parser Excel Producer produced {len([1,2])} events to '{svc.produce_key}'")
|
||||
|
||||
|
||||
async def handle_from_parser(svc: ServiceBaseAsync, job):
|
||||
print("Parser Excel Consumer from parser:", job)
|
||||
job = Job(**job)
|
||||
await svc.ack_current()
|
||||
return
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
|
||||
|
||||
async def handle_from_mail(svc: ServiceBaseAsync, job):
|
||||
print("Parser Excel Consumer from mail:", job)
|
||||
job = Job(**job)
|
||||
await svc.enqueue(task_id=job.task_id, payload=job.payload, type_="parser.excel.publish")
|
||||
print("Parser Excel Consumer from mail handle_from_mail :", job.task_id)
|
||||
await svc.ack_current()
|
||||
return
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
|
||||
|
||||
async def consume_default(svc, job):
|
||||
print("Parser Excel Consumer default:", job)
|
||||
async def consume_default(svc: ServiceBaseAsync, job):
|
||||
job = Job(**job)
|
||||
await svc.ack_current()
|
||||
return
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"parser.publish": handle_from_parser, "mail.publish": handle_from_mail})
|
||||
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"parser.mail.publish": handle_from_mail})
|
||||
asyncio.run(svc.run())
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user