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

30 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import uuid
import asyncio
from app.services.common.service_base_async import ServiceBaseAsync
PRODUCE_ENABLED = os.getenv("PRODUCE_ENABLED", "true").lower() == "true"
PRODUCE_BATCH = int(os.getenv("PRODUCE_BATCH", "3")) # her produce tick'inde kaç iş
TASK_TYPE = os.getenv("TASK_TYPE", "db-task") # iş tipi (task_id'de de kullanılır)
CONSUME_SLEEP_SEC = float(os.getenv("CONSUME_SLEEP_SEC", "0.5")) # işleme süresi simülasyonu (sn)
STATIC_IDS = ["2c47f1073a9d4f05aad6c15484894a74", "65827e3452b545d6845e050a503401f4", "5c663088f09d4062b4e567f47335fb1e"]
async def produce(service: ServiceBaseAsync):
for biz_id in STATIC_IDS:
deterministic_task_id = f"{TASK_TYPE}:{biz_id}"
payload = {"id": biz_id, "op": "sync", "source": "db-service"}
await service.enqueue(payload, TASK_TYPE, task_id=deterministic_task_id)
print(f"[DB] produce tick attempted ids={','.join(STATIC_IDS)}")
async def consume(service: ServiceBaseAsync, job: dict):
await asyncio.sleep(CONSUME_SLEEP_SEC)
print(f"[DB] consumed task={job['task_id']} attempts={job.get('_attempts', 0)}")
if __name__ == "__main__":
asyncio.run(ServiceBaseAsync(produce, consume).run())