fix: queue outgoing events when relay connection is down
Some checks failed
ci.yml / fix: queue outgoing events when relay connection is down (pull_request) Failing after 0s
Some checks failed
ci.yml / fix: queue outgoing events when relay connection is down (pull_request) Failing after 0s
When all relay connections are temporarily lost, EVENT messages published by extensions (nostrmarket, events) are now queued in a bounded deque (max 100) instead of being silently dropped. On reconnection, queued events are flushed to all connected relays. Dead relay queues are also drained before restart to preserve in-flight events. Closes aiolabs/nostrclient#1 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
801ce44561
commit
115e869225
3 changed files with 128 additions and 2 deletions
|
|
@ -1,6 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from queue import Queue
|
||||
|
||||
from loguru import logger
|
||||
|
|
@ -28,6 +31,7 @@ class Relay:
|
|||
self.num_subscriptions: int = 0
|
||||
|
||||
self.queue: Queue = Queue()
|
||||
self.on_connect: Callable[[Relay], None] | None = None
|
||||
|
||||
def connect(self):
|
||||
self.ws = WebSocketApp(
|
||||
|
|
@ -97,6 +101,11 @@ class Relay:
|
|||
logger.info(f"[Relay: {self.url}] Connected.")
|
||||
self.connected = True
|
||||
self.shutdown = False
|
||||
if self.on_connect:
|
||||
try:
|
||||
self.on_connect(self)
|
||||
except Exception as e:
|
||||
logger.warning(f"[Relay: {self.url}] on_connect callback error: {e}")
|
||||
|
||||
def _on_close(self, _, status_code, message):
|
||||
logger.warning(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue