forked from mtusi2026/mtusi2026lab6
feat: ЛР6 - наблюдаемость OpenTelemetry, Grafana и исследование цены наблюдаемости
This commit is contained in:
+12
-1
@@ -8,6 +8,7 @@ from typing import Any
|
||||
import asyncpg
|
||||
|
||||
from app.broker import publisher
|
||||
from app.telemetry import set_oldest_job_age, set_queue_depth
|
||||
|
||||
logger = logging.getLogger("messenger.outbox")
|
||||
|
||||
@@ -90,7 +91,17 @@ class OutboxRelay:
|
||||
while self._running:
|
||||
try:
|
||||
dispatched = await self.process_pending(pool)
|
||||
# Если были отправлены задачи, проверяем сразу следующую порцию
|
||||
count = await publisher.get_queue_message_count()
|
||||
set_queue_depth(count)
|
||||
async with pool.acquire() as conn:
|
||||
age = await conn.fetchval(
|
||||
"""
|
||||
SELECT COALESCE(EXTRACT(EPOCH FROM (NOW() - MIN(created_at))), 0.0)
|
||||
FROM outbox_jobs
|
||||
WHERE status = 'pending'
|
||||
"""
|
||||
)
|
||||
set_oldest_job_age(float(age or 0.0))
|
||||
if dispatched > 0:
|
||||
continue
|
||||
except asyncio.CancelledError:
|
||||
|
||||
Reference in New Issue
Block a user