Files
webmail-client/backend/app/queue.py
T

32 lines
785 B
Python
Raw Normal View History

2026-07-17 23:20:34 +02:00
"""arq queue helpers (enqueue side, used by the API)."""
from __future__ import annotations
from arq import create_pool
from arq.connections import ArqRedis, RedisSettings
from app.config import get_settings
_pool: ArqRedis | None = None
def redis_settings() -> RedisSettings:
"""Return arq RedisSettings derived from ``REDIS_URL``."""
return RedisSettings.from_dsn(get_settings().redis_url)
async def get_arq_pool() -> ArqRedis:
"""Return (creating on first use) the shared arq enqueue pool."""
global _pool
if _pool is None:
_pool = await create_pool(redis_settings())
return _pool
async def close_arq_pool() -> None:
"""Close the arq pool."""
global _pool
if _pool is not None:
await _pool.aclose()
_pool = None