feat: restart disconnected relays

This commit is contained in:
Vlad Stan 2023-06-26 10:21:06 +03:00
parent c81a804dea
commit ce8b95c2c7
4 changed files with 63 additions and 34 deletions

View file

@ -1,6 +1,8 @@
import asyncio
import threading
from loguru import logger
from . import nostr
from .crud import get_relays
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
@ -17,6 +19,16 @@ async def init_relays():
await nostr.client.connect()
async def check_relays():
""" Check relays that have been disconnected """
while True:
try:
await asyncio.sleep(20)
nostr.client.relay_manager.check_and_restart_relays()
except Exception as e:
logger.warning(f"Cannot restart relays: '{str(e)}'.")
async def subscribe_events():
while not any([r.connected for r in nostr.client.relay_manager.relays.values()]):
await asyncio.sleep(2)