From 5e3ce8c8c3e9402d98b6ccdc1b5de5c70e2759ad Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Thu, 22 Jul 2021 14:09:39 -0400 Subject: [PATCH] Improved how Bazarr deals with Sonarr SignalR feed issues that are raising exceptions. --- bazarr/main.py | 6 ++++-- bazarr/signalr_client.py | 42 ++++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/bazarr/main.py b/bazarr/main.py index 71632d97e..e29164f9d 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -204,10 +204,12 @@ def proxy(protocol, url): return dict(status=False, error=result.raise_for_status()) +greenlets = [] if settings.general.getboolean('use_sonarr'): - Greenlet.spawn(sonarr_signalr_client.start) + greenlets.append(Greenlet.spawn(sonarr_signalr_client.start)) if settings.general.getboolean('use_radarr'): - Greenlet.spawn(radarr_signalr_client.start) + greenlets.append(Greenlet.spawn(radarr_signalr_client.start)) +gevent.joinall(greenlets) if __name__ == "__main__": diff --git a/bazarr/signalr_client.py b/bazarr/signalr_client.py index 941d8bd9f..583a7942f 100644 --- a/bazarr/signalr_client.py +++ b/bazarr/signalr_client.py @@ -33,26 +33,30 @@ class SonarrSignalrClient: self.connection = None def start(self): - if get_sonarr_version().startswith('2.'): + sonarr_version = get_sonarr_version() + if sonarr_version.startswith('2.'): logging.warning('BAZARR can only sync from Sonarr v3 SignalR feed to get real-time update. You should ' - 'consider upgrading.') - return - - logging.info('BAZARR trying to connect to Sonarr SignalR feed...') - self.configure() - while not self.connection.started: - try: - self.connection.start() - except ConnectionError: - gevent.sleep(5) - except json.decoder.JSONDecodeError: - logging.error("BAZARR cannot parse JSON returned by SignalR feed. This is a known issue when Sonarr " - "doesn't have write permission to it's /config/xdg directory.") - self.stop() - logging.info('BAZARR SignalR client for Sonarr is connected and waiting for events.') - if not args.dev: - scheduler.add_job(update_series, kwargs={'send_event': True}, max_instances=1) - scheduler.add_job(sync_episodes, kwargs={'send_event': True}, max_instances=1) + 'consider upgrading your version({}).'.format(sonarr_version)) + raise gevent.GreenletExit + else: + logging.info('BAZARR trying to connect to Sonarr SignalR feed...') + self.configure() + while not self.connection.started: + try: + self.connection.start() + except ConnectionError: + gevent.sleep(5) + except json.decoder.JSONDecodeError: + logging.error("BAZARR cannot parse JSON returned by SignalR feed. This is a known issue when " + "Sonarr have issue accessing it's /config/xdg directory. You should delete that " + "directory and restart Sonarr.") + raise gevent.GreenletExit + else: + logging.info('BAZARR SignalR client for Sonarr is connected and waiting for events.') + finally: + if not args.dev: + scheduler.add_job(update_series, kwargs={'send_event': True}, max_instances=1) + scheduler.add_job(sync_episodes, kwargs={'send_event': True}, max_instances=1) def stop(self, log=True): try: