feat(sms): add selectable provider strategy
This commit is contained in:
@@ -8,12 +8,13 @@ from aio_pika.abc import AbstractIncomingMessage
|
||||
|
||||
from gapido_auth.config import get_settings
|
||||
from gapido_auth.domain.entities import SmsJob
|
||||
from gapido_auth.infrastructure.kavenegar_client import KavenegarSmsClient
|
||||
from gapido_auth.domain.ports import SmsClient
|
||||
from gapido_auth.infrastructure.rabbitmq import (
|
||||
SMS_ROUTING_KEY,
|
||||
connect_robust,
|
||||
declare_sms_topology,
|
||||
)
|
||||
from gapido_auth.infrastructure.sms_provider import create_sms_client
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
MAX_RETRIES = 3
|
||||
@@ -21,7 +22,7 @@ MAX_RETRIES = 3
|
||||
|
||||
async def handle_message(
|
||||
message: AbstractIncomingMessage,
|
||||
client: KavenegarSmsClient,
|
||||
client: SmsClient,
|
||||
exchange: Any,
|
||||
dlx: Any,
|
||||
) -> None:
|
||||
@@ -68,9 +69,9 @@ async def main() -> None:
|
||||
channel = await connection.channel()
|
||||
await channel.set_qos(prefetch_count=20)
|
||||
exchange, queue, dlx = await declare_sms_topology(channel)
|
||||
client = KavenegarSmsClient(settings.kavenegar_api_key)
|
||||
client = create_sms_client(settings)
|
||||
await queue.consume(lambda message: handle_message(message, client, exchange, dlx))
|
||||
logger.info("SMS worker started")
|
||||
logger.info("SMS worker started with provider=%s", settings.sms_provider)
|
||||
await asyncio.Future()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user