Add NOTIFY/LISTEN wake-up to event processor
emit_activity() now fires NOTIFY ap_activity_pending inside the caller's transaction (delivered on commit). EventProcessor maintains a dedicated asyncpg LISTEN connection and wakes the poll loop immediately, dropping latency from ~2 s to sub-100 ms. The fixed- interval poll remains as a safety-net fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import uuid
|
||||
from collections import defaultdict
|
||||
from typing import Awaitable, Callable, Dict, List, Tuple
|
||||
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from shared.models.federation import APActivity
|
||||
@@ -119,4 +120,7 @@ async def emit_activity(
|
||||
)
|
||||
session.add(activity)
|
||||
await session.flush()
|
||||
# Wake any listening EventProcessor as soon as this transaction commits.
|
||||
# NOTIFY is transactional — delivered only after commit.
|
||||
await session.execute(text("NOTIFY ap_activity_pending"))
|
||||
return activity
|
||||
|
||||
Reference in New Issue
Block a user