add level 3 and 4

This commit is contained in:
Матвей
2026-11-05 22:23:52 +03:00
parent 66026d3ec9
commit 45c7aa0085
30 changed files with 1370 additions and 68 deletions
+7 -1
View File
@@ -2,15 +2,18 @@
import asyncio
import logging
import os
import json
from .broker import publish
from .config import load_settings
from .storage.postgres import PostgresStore
from . import telemetry as tel
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s outbox %(message)s")
async def run() -> None:
tel.setup("messenger-outbox")
settings = load_settings()
store = PostgresStore(settings.database_url)
await store.connect()
@@ -19,8 +22,11 @@ async def run() -> None:
while True:
try:
await store.schedule_due_jobs(int(os.environ.get('JOB_MAX_ATTEMPTS', '5')))
queue = await store.pool.fetchrow("SELECT count(*) AS depth, COALESCE(EXTRACT(EPOCH FROM now()-min(created_at)), 0)::float8 AS age FROM attachment_jobs WHERE status='queued'")
tel.state.update(queue_depth=queue['depth'], queue_age=queue['age'])
for event in await store.due_outbox_events():
await publish(event["payload"])
context = event['trace_context']
await publish(event["payload"], json.loads(context) if isinstance(context, str) else context)
await store.mark_outbox_published(event["id"])
except Exception:
logging.exception("outbox dispatch failed; durable event remains pending")