43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import os
|
|
import asyncio
|
|
|
|
from app.services.common.service_base_async import ServiceBaseAsync
|
|
|
|
|
|
PRODUCE_BURST = int(os.getenv("PRODUCE_BURST", "10"))
|
|
PRODUCE_ONCE = os.getenv("PRODUCE_ONCE", "true").lower() == "true"
|
|
EVENT_TYPE = os.getenv("EVENT_TYPE", "db-mongo")
|
|
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)
|
|
await svc.ack_current()
|
|
print("Parser Mail Consumer from db:", job)
|
|
|
|
|
|
async def handle_mongo_publish(svc: ServiceBaseAsync, job):
|
|
await asyncio.sleep(PROCESS_SEC)
|
|
await svc.ack_current()
|
|
print("Parser Mail Consumer from mongo:", job)
|
|
|
|
|
|
async def consume_default(svc: ServiceBaseAsync, job):
|
|
await asyncio.sleep(PROCESS_SEC)
|
|
print("Parser Mail Consumer default:", job)
|
|
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},
|
|
)
|
|
asyncio.run(svc.run())
|