feat: revive relay after 24 hours from the last error

This commit is contained in:
Vlad Stan 2023-06-30 10:52:16 +03:00
parent ada5b2a51d
commit 39c2f881c8
2 changed files with 12 additions and 3 deletions

View file

@ -41,6 +41,8 @@ class Relay:
self.error_counter: int = 0
self.error_threshold: int = 100
self.error_list: List[str] = []
self.notice_list: List[str] = []
self.last_error_date: int = 0
self.num_received_events: int = 0
self.num_sent_events: int = 0
self.num_subscriptions: int = 0
@ -77,7 +79,7 @@ class Relay:
@property
def error_threshold_reached(self):
return self.error_threshold and self.error_counter > self.error_threshold
return self.error_threshold and self.error_counter >= self.error_threshold
@property
def ping(self):
@ -213,3 +215,4 @@ class Relay:
def _append_error_message(self, message):
self.error_list = ([message] + self.error_list)[:20]
self.last_error_date = int(time.time())

View file

@ -1,6 +1,7 @@
import ssl
import threading
import time
from loguru import logger
@ -97,7 +98,12 @@ class RelayManager:
def _restart_relay(self, relay: Relay):
if relay.error_threshold_reached:
return
time_since_last_error = time.time() - relay.last_error_date
if time_since_last_error < 60 * 60 * 24: # last day
return
relay.error_counter = 0
relay.error_list = []
logger.info(f"Restarting connection to relay '{relay.url}'")
self.remove_relay(relay.url)