watchdog thread
This commit is contained in:
@@ -198,6 +198,9 @@ class GotifyClient(GotifySession):
|
||||
self.listener.reset_wait_time()
|
||||
self.listener.stop()
|
||||
|
||||
def is_listening(self) -> bool:
|
||||
return self.listener.running
|
||||
|
||||
"""
|
||||
Health
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
|
||||
import websocket
|
||||
@@ -57,14 +58,17 @@ class Listener(QtCore.QThread):
|
||||
self.closed.emit(close_status_code, close_msg)
|
||||
|
||||
def stop(self):
|
||||
logger.debug("Listener: stopping.")
|
||||
self.ws.close()
|
||||
self.running = False
|
||||
|
||||
def run(self):
|
||||
self.running = True
|
||||
logger.debug(f"Listener: waiting {self.wait_time} seconds before connecting.")
|
||||
|
||||
try:
|
||||
time.sleep(self.wait_time)
|
||||
self.ws.run_forever()
|
||||
finally:
|
||||
logger.debug("Listener: stopped.")
|
||||
self.running = False
|
||||
|
||||
@@ -15,6 +15,7 @@ from gotify_tray.tasks import (
|
||||
GetApplicationMessagesTask,
|
||||
GetApplicationsTask,
|
||||
GetMessagesTask,
|
||||
ServerConnectionWatchdogTask,
|
||||
)
|
||||
from gotify_tray.utils import verify_server
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
@@ -112,6 +113,10 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
closed_callback=self.listener_closed_callback,
|
||||
)
|
||||
|
||||
self.watchdog = ServerConnectionWatchdogTask(self.gotify_client)
|
||||
self.watchdog.closed.connect(lambda: self.listener_closed_callback(None, None))
|
||||
self.watchdog.start()
|
||||
|
||||
self.link_callbacks()
|
||||
|
||||
self.show()
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import abc
|
||||
import logging
|
||||
import time
|
||||
|
||||
from PyQt6 import QtCore
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
|
||||
from gotify_tray.gotify.api import GotifyClient
|
||||
from gotify_tray.gotify.models import GotifyVersionModel
|
||||
|
||||
from . import gotify
|
||||
@@ -154,3 +156,21 @@ class VerifyServerInfoTask(BaseTask):
|
||||
self.incorrect_url.emit()
|
||||
except Exception as e:
|
||||
self.incorrect_url.emit()
|
||||
|
||||
|
||||
class ServerConnectionWatchdogTask(BaseTask):
|
||||
closed = pyqtSignal()
|
||||
|
||||
def __init__(self, gotify_client: GotifyClient):
|
||||
super(ServerConnectionWatchdogTask, self).__init__()
|
||||
self.gotify_client = gotify_client
|
||||
self.interval = 60
|
||||
|
||||
def task(self):
|
||||
while True:
|
||||
time.sleep(self.interval)
|
||||
if not self.gotify_client.is_listening():
|
||||
self.closed.emit()
|
||||
logger.debug(
|
||||
f"ServerConnectionWatchdogTask: gotify_client is not listening"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user