feat(sms): add selectable provider strategy

This commit is contained in:
2026-07-14 09:45:40 +03:30
parent 2264b7fc95
commit e382c4f93a
10 changed files with 171 additions and 12 deletions

View File

@@ -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()