Skip to content
Snippets Groups Projects

Detect our custom polling with LofarDevice

Merged Jan David Mol requested to merge L2SS-1740-support-lofardevice-polling into L2SS-1740
1 file
+ 37
18
Compare changes
  • Side-by-side
  • Inline
@@ -102,6 +102,25 @@ class EventSubscriptions:
f"Callback {callback} for device {device} attribute {attribute_name} threw an exception: {exception_to_str(ex)}"
)
def poll_period(self, proxy: DeviceProxy, attr_name: str) -> int | None:
"""Return the polling period for the given attribute, in milliseconds,
or None if the attribute is not polled at all."""
# LofarDevice polls a set of attributes not covered by Tango's poll loop
try:
if is_attribute_polled_by_lofardevice(attr_name):
return DEFAULT_METRICS_POLLING_PERIOD_MS
except AttributeError:
# Not a LofarDevice
pass
# Check if polled by Tango
if proxy.is_attribute_polled(attr_name):
return proxy.get_attribute_poll_period(attr_name)
# No polling detected
return None
def subscribe_change_event(
self,
proxy: DeviceProxy,
@@ -120,6 +139,24 @@ class EventSubscriptions:
the callback.
"""
# make sure th attribute is polled often enough
current_period = poll_period(proxy, attr_name)
if current_period is None or current_period > period:
if current_period is None:
logger.info(f"Enabling polling for {proxy.name()}/{attr_name}.")
else:
logger.info(
"Adjusting tango controlled polling period from %d to %d",
current_period,
period,
)
# NB: This requires either abs_change or rel_change to be set
# for numerical attributes.
proxy.poll_attribute(attr_name, period)
# add or extend subscription to CHANGE_EVENT
if sub := self._get_subscription(proxy.name(), attr_name):
# extend existing subscription
logger.debug(
@@ -127,17 +164,6 @@ class EventSubscriptions:
)
sub.callbacks.append(callback)
# Check if polled by tango and adjust polling period if necessary
if proxy.is_attribute_polled(attr_name):
current_period = proxy.get_attribute_poll_period(attr_name)
if current_period > period:
logger.info(
"Adjusting tango controlled polling period from %d to %d",
current_period,
period,
)
proxy.poll_attribute(attr_name, period)
# manually trigger first call, mimicking Tango doing so when subscribing
try:
value = proxy.read_attribute(attr_name).value
@@ -157,13 +183,6 @@ class EventSubscriptions:
callbacks=[callback],
)
# make sure the attribute is polled, otherwise we wont receive event
if not proxy.is_attribute_polled_by_lofardevice(attr_name):
# LOFARDevice does not poll this attribute, but maybe Tango does
if not proxy.is_attribute_polled(attr_name):
logger.info(f"Enabling polling for {proxy.name()}/{attr_name}.")
proxy.poll_attribute(attr_name, period)
# subscribe
logger.debug(
f"Subscribing callback {callback} to CHANGE_EVENT on device {proxy} attribute {attr_name}"
Loading