0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix(utils/bec_dispatcher): bec_dispatcher adjusted to the new BECClient; dropped support to inject bec_config.yaml, instead BECClient can be passed as arg

This commit is contained in:
wyzula-jan
2024-03-19 23:04:23 +01:00
parent 1d5442ac08
commit 86416d50cb
2 changed files with 6 additions and 14 deletions

View File

@ -35,19 +35,11 @@ class _Connection:
class _BECDispatcher(QObject):
"""Utility class to keep track of slots connected to a particular redis connector"""
def __init__(self, bec_config=None):
def __init__(self, client=None):
super().__init__()
self.client = BECClient()
self.client = BECClient() if client is None else client
self.client.start()
# TODO: this is a workaround for now to provide service config within qtdesigner, but is
# it possible to provide config via a cli arg?
if bec_config is None and os.path.isfile("bec_config.yaml"):
bec_config = "bec_config.yaml"
try:
self.client.initialize(config=ServiceConfig(config_path=bec_config))
except redis.exceptions.ConnectionError as e:
print(f"Failed to initialize BECClient: {e}")
self._connections = {}
def connect_slot(
@ -186,8 +178,8 @@ def BECDispatcher():
global _bec_dispatcher
if _bec_dispatcher is None:
parser = argparse.ArgumentParser()
parser.add_argument("--bec-config", default=None)
parser.add_argument("--bec-client", default=None)
args, _ = parser.parse_known_args()
_bec_dispatcher = _BECDispatcher(args.bec_config)
_bec_dispatcher = _BECDispatcher(args.bec_client)
return _bec_dispatcher

View File

@ -30,6 +30,6 @@ def bec_dispatcher(threads_check):
yield bec_dispatcher
bec_dispatcher.disconnect_all()
# clean BEC client
BECService.shutdown(bec_dispatcher.client)
bec_dispatcher.client.shutdown()
# reinitialize singleton for next test
bec_dispatcher_module._bec_dispatcher = None