mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix(cli/server): handle RedisError during heartbeat emission to properly close the app even if the Redis connection is lost
This commit is contained in:
@ -13,6 +13,7 @@ from bec_lib.logger import bec_logger
|
|||||||
from bec_lib.service_config import ServiceConfig
|
from bec_lib.service_config import ServiceConfig
|
||||||
from bec_lib.utils.import_utils import lazy_import
|
from bec_lib.utils.import_utils import lazy_import
|
||||||
from qtpy.QtCore import Qt, QTimer
|
from qtpy.QtCore import Qt, QTimer
|
||||||
|
from redis.exceptions import RedisError
|
||||||
|
|
||||||
from bec_widgets.cli.rpc.rpc_register import RPCRegister
|
from bec_widgets.cli.rpc.rpc_register import RPCRegister
|
||||||
from bec_widgets.qt_utils.error_popups import ErrorPopupUtility
|
from bec_widgets.qt_utils.error_popups import ErrorPopupUtility
|
||||||
@ -142,11 +143,14 @@ class BECWidgetsCLIServer:
|
|||||||
|
|
||||||
def emit_heartbeat(self):
|
def emit_heartbeat(self):
|
||||||
logger.trace(f"Emitting heartbeat for {self.gui_id}")
|
logger.trace(f"Emitting heartbeat for {self.gui_id}")
|
||||||
self.client.connector.set(
|
try:
|
||||||
MessageEndpoints.gui_heartbeat(self.gui_id),
|
self.client.connector.set(
|
||||||
messages.StatusMessage(name=self.gui_id, status=self.status, info={}),
|
MessageEndpoints.gui_heartbeat(self.gui_id),
|
||||||
expire=10,
|
messages.StatusMessage(name=self.gui_id, status=self.status, info={}),
|
||||||
)
|
expire=10,
|
||||||
|
)
|
||||||
|
except RedisError as exc:
|
||||||
|
logger.error(f"Error while emitting heartbeat: {exc}")
|
||||||
|
|
||||||
def shutdown(self): # TODO not sure if needed when cleanup is done at level of BECConnector
|
def shutdown(self): # TODO not sure if needed when cleanup is done at level of BECConnector
|
||||||
logger.info(f"Shutting down server with gui_id: {self.gui_id}")
|
logger.info(f"Shutting down server with gui_id: {self.gui_id}")
|
||||||
|
Reference in New Issue
Block a user