mirror of
https://github.com/furyhawk/agent_delta.git
synced 2026-07-21 02:05:36 +00:00
refactor: migrate broker initialization to taskiq_app and remove unused broker import
feat: add channel event processing handler for Telegram and Slack
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
"""In-process handler for channel-bot webhook events (Telegram, Slack).
|
||||||
|
|
||||||
|
Dispatched via FastAPI ``BackgroundTasks`` from the webhook routes so the platform
|
||||||
|
gets a fast 200 OK while routing/AI happens in the background.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from app.db.session import get_db_context
|
||||||
|
from app.services.channels.router import ChannelMessageRouter
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
async def process_channel_event(incoming: Any) -> None:
|
||||||
|
"""Route an incoming channel event to its handler.
|
||||||
|
|
||||||
|
Errors are logged with full traceback but never re-raised — the response to the
|
||||||
|
platform has already been sent, and an unhandled exception here would just become
|
||||||
|
a noisy stack trace in the API process logs.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
async with get_db_context() as db:
|
||||||
|
await ChannelMessageRouter().route(incoming, db)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("channel_event_processing_failed")
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
"""Taskiq broker — shared across all task modules."""
|
|
||||||
|
|
||||||
from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend
|
|
||||||
|
|
||||||
from app.core.config import settings
|
|
||||||
|
|
||||||
# Create Taskiq broker with Redis
|
|
||||||
broker = ListQueueBroker(
|
|
||||||
url=settings.TASKIQ_BROKER_URL,
|
|
||||||
).with_result_backend(
|
|
||||||
RedisAsyncResultBackend(
|
|
||||||
redis_url=settings.TASKIQ_RESULT_BACKEND,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
@@ -2,13 +2,20 @@
|
|||||||
|
|
||||||
from taskiq import TaskiqScheduler
|
from taskiq import TaskiqScheduler
|
||||||
from taskiq.schedule_sources import LabelScheduleSource
|
from taskiq.schedule_sources import LabelScheduleSource
|
||||||
|
from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend
|
||||||
|
|
||||||
from app.worker.broker import broker
|
from app.core.config import settings
|
||||||
import app.worker.tasks # noqa: F401 — register @broker.task decorated functions
|
|
||||||
import app.worker.tasks.schedules # noqa: F401 — register scheduled tasks
|
# Create Taskiq broker with Redis
|
||||||
|
broker = ListQueueBroker(
|
||||||
|
url=settings.TASKIQ_BROKER_URL,
|
||||||
|
).with_result_backend(
|
||||||
|
RedisAsyncResultBackend(
|
||||||
|
redis_url=settings.TASKIQ_RESULT_BACKEND,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# Create scheduler for periodic tasks
|
# Create scheduler for periodic tasks
|
||||||
# LabelScheduleSource auto-discovers @broker.task(schedule=[...]) decorated functions
|
|
||||||
scheduler = TaskiqScheduler(
|
scheduler = TaskiqScheduler(
|
||||||
broker=broker,
|
broker=broker,
|
||||||
sources=[LabelScheduleSource(broker)],
|
sources=[LabelScheduleSource(broker)],
|
||||||
@@ -26,3 +33,6 @@ async def startup() -> None:
|
|||||||
async def shutdown() -> None:
|
async def shutdown() -> None:
|
||||||
"""Cleanup on shutdown."""
|
"""Cleanup on shutdown."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
import app.worker.tasks.schedules # noqa: F401
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import tempfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from app.worker.broker import broker
|
from app.worker.taskiq_app import broker
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""Taskiq scheduled tasks (cron-like)."""
|
"""Taskiq scheduled tasks (cron-like)."""
|
||||||
|
|
||||||
from app.worker.broker import broker
|
from app.worker.taskiq_app import broker
|
||||||
from app.worker.tasks.rag_tasks import check_scheduled_syncs
|
from app.worker.tasks.rag_tasks import check_scheduled_syncs
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user