[WIP] change frappy_config to frappy

work to be done:
- frappy() is now called as e device

work done:
- handle_notifications is not only waiting for triggers,
  but rechecks servers all 60 seconds
This commit is contained in:
2023-09-25 17:26:46 +02:00
parent 56fec16247
commit c73390195d

View File

@ -27,12 +27,11 @@ SEC Node with added functionality for starting and stopping frappy servers
connected to a SEC node connected to a SEC node
""" """
import time
import threading import threading
from nicos import config, session from nicos import config, session
from nicos.core import Override, Param, Moveable, status, POLLER, SIMULATION, DeviceAlias, \ from nicos.core import Override, Param, Moveable, status, POLLER, SIMULATION, DeviceAlias, \
Device, anytype, listof Device, anytype, listof
from nicos.devices.secop.devices import SecNodeDevice from nicos.devices.secop.devices import SecNodeDevice, NicosSecopClient
from nicos.core.utils import USER, User, createThread from nicos.core.utils import USER, User, createThread
from nicos.services.daemon.script import RequestError, ScriptRequest from nicos.services.daemon.script import RequestError, ScriptRequest
from nicos.utils.comparestrings import compare from nicos.utils.comparestrings import compare
@ -107,9 +106,9 @@ def all_info(all_cfg, prefix='currently configured: '):
def get_frappy_config(): def get_frappy_config():
try: try:
return session.devices['frappy_config'] return session.devices['frappy']
except KeyError: except KeyError:
session.log.error("'frappy_config' is not available - 'frappy' setup is not loaded") session.log.error("the frappy device is not available - 'frappy' setup is not loaded")
return None return None
@ -155,11 +154,12 @@ class FrappyConfig(Device):
def handle_notifications(self): def handle_notifications(self):
controller = session.daemon_device._controller controller = session.daemon_device._controller
while True: while True:
self._trigger_change.wait() # we do not wait for ever here, because there might be changes
# on an unconnected service
self._trigger_change.wait(60)
self._trigger_change.clear()
while self._trigger_change.wait(2): # triggered again within 2 sec
self._trigger_change.clear() self._trigger_change.clear()
time.sleep(2)
if self._trigger_change.is_set():
continue
try: try:
cfgs = self.check_services() cfgs = self.check_services()
guess_info = self.to_consider(cfgs) guess_info = self.to_consider(cfgs)
@ -491,9 +491,7 @@ class FrappyNode(SecNodeDevice, Moveable):
if isinstance(cfg, str): # may also be None or True if isinstance(cfg, str): # may also be None or True
self.restart(cfg) self.restart(cfg)
if cfg is None: # None means: server is not running, and does not need to be restarted if cfg is None: # None means: server is not running, and does not need to be restarted
# connect in background, as the server might be started later self._disconnect()
createThread('connect', self._connect)
# TODO: check if it is not better to add a try_period argument to SecNode._connect()
return return
try: try:
self._connect() self._connect()