db_kyc_project/batcher/app/src/domain/setting/usecase.py

25 lines
791 B
Python
Raw Normal View History

import decimal
import threading
2024-12-13 16:45:21 +03:00
import asyncio
from collections.abc import Callable, Awaitable
import aio_pika
2024-12-13 16:45:21 +03:00
from .repos.in_memory_storage import set_setting, get_setting as ims_get_setting
from .repos.rmq import consume_setting_updates
2024-12-13 16:45:21 +03:00
def get_setting(name: str) -> decimal.Decimal:
return ims_get_setting(name)
2024-12-13 16:45:21 +03:00
async def start_thread(rmq_connect_func: Callable[[], Awaitable[aio_pika.abc.AbstractRobustConnection]], *args):
conn = await rmq_connect_func()
async with conn:
chan = await conn.channel()
await consume_setting_updates(set_setting, chan)
2024-12-13 16:45:21 +03:00
def launch_consumer(rmq_connect_func: Callable[[], Awaitable[aio_pika.abc.AbstractRobustConnection]]):
t = threading.Thread(target=asyncio.run, args=(start_thread(rmq_connect_func),))
t.start()