feat: add jobs queue

This commit is contained in:
h
2026-05-29 19:04:36 +02:00
parent 3c1a12750c
commit 4a471df8f1
8 changed files with 356 additions and 0 deletions
+9
View File
@@ -9,6 +9,7 @@ import uvloop
from dependencies.container import container
from userbot import PyroClient
from userbot.modules.capture import build_capture_context
from userbot.modules.jobs import JobConsumer
from utils.env import env
from utils.logging import logger, setup_logging
from utils.storage import ContentAddressedStorage
@@ -101,6 +102,7 @@ async def runner() -> None:
clients: list[PyroClient] = []
reload_tasks: set[asyncio.Task] = set()
consumer_tasks: list[asyncio.Task] = []
listen_conn: asyncpg.Connection | None = None
try:
for session_path in session_files:
@@ -116,12 +118,19 @@ async def runner() -> None:
account_id = await _sync_account(pool, client, session_name)
if account_id is not None:
await _setup_capture(pool, client, account_id, storage)
consumer = JobConsumer(client, pool, account_id)
consumer_tasks.append(asyncio.create_task(consumer.run()))
if clients:
listen_conn = await _listen_policy_changes(clients, reload_tasks)
logger.info("[green]Userbot running.[/]")
await asyncio.Event().wait()
finally:
for task in consumer_tasks:
task.cancel()
for task in consumer_tasks:
with contextlib.suppress(asyncio.CancelledError):
await task
if listen_conn is not None:
with contextlib.suppress(Exception):
await listen_conn.close()