parser excel publish chain task build
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
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"))
|
||||
@@ -12,31 +12,33 @@ PROCESS_SEC = 10
|
||||
|
||||
async def produce(svc: ServiceBaseAsync):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
print(f"Parser Mail Producer produced {len([1,2])} events to '{svc.produce_key}'")
|
||||
|
||||
|
||||
async def handle_db_publish(svc: ServiceBaseAsync, job):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
async def handle_mail_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.excel.publish")
|
||||
print("Parser Mail Consumer parsed handle_mail_publish :", job_model.task_id)
|
||||
await svc.ack_current()
|
||||
print("Parser Mail Consumer from db:", job)
|
||||
|
||||
|
||||
async def handle_mongo_publish(svc: ServiceBaseAsync, job):
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
|
||||
|
||||
async def handle_mongo_publish(svc: ServiceBaseAsync, job: dict):
|
||||
job_model = Job(**job)
|
||||
await svc.ack_current()
|
||||
print("Parser Mail Consumer from mongo:", job)
|
||||
|
||||
|
||||
async def consume_default(svc: ServiceBaseAsync, job):
|
||||
print("Parser Mail Consumer default handle_mongo_publish :", job_model.task_id)
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
print("Parser Mail Consumer default:", job)
|
||||
|
||||
|
||||
async def consume_default(svc: ServiceBaseAsync, job: dict):
|
||||
job_model = Job(**job)
|
||||
await asyncio.sleep(PROCESS_SEC)
|
||||
print("Parser Mail Consumer default consume_default :", job_model.task_id)
|
||||
return
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
svc = ServiceBaseAsync(
|
||||
produce_fn=produce, consume_fn=consume_default,
|
||||
handlers={"database.service.publish": handle_db_publish, "mongo.service.publish": handle_mongo_publish},
|
||||
)
|
||||
svc = ServiceBaseAsync(produce_fn=produce, consume_fn=consume_default, handlers={"mail.service.publish": handle_mail_publish})
|
||||
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