Skip to content
Snippets Groups Projects

L2SS-1893: Use PeriodicTask instead of subscriptions to manage observation states

Merged L2SS-1893: Use PeriodicTask instead of subscriptions to manage observation states
Merged Jan David Mol requested to merge remove-observation-subscriptions into master
Files
10
@@ -5,13 +5,14 @@ import logging
import numpy
from tango import (
DebugIt,
Util,
DevBoolean,
DevString,
)
from tango.server import command, attribute
from tango.server import command, attribute, device_property
from tangostationcontrol.observation.observation_controller import ObservationController
from tangostationcontrol.common.asyncio import PeriodicTask
from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD_MS
from tangostationcontrol.common.lofar_logging import (
device_logging_to_python,
log_exceptions,
@@ -59,10 +60,9 @@ class ObservationControl(LOFARDevice):
- If status() is NOT STANDBY, abort with an exception
- Wait for start_time - lead_time
- Call On()
- Subscribe to the ObservationField.alive_R MP's periodic event
- Register the observation in the dict self.running_observations[ID]
- The Observation updates the MP every second with the current time
- The callback gets called periodically.
- The update callback gets called periodically.
It checks if MP value > stop (stored in the dict under the obs IDS.
By this it can determine if the observation is done.
- if MP value > observation end
@@ -75,6 +75,17 @@ class ObservationControl(LOFARDevice):
- string version
"""
# -----------------
# Device Properties
# -----------------
Observation_Update_Interval = device_property(
dtype="DevFloat",
doc="Interval with which check for updates for observation states.",
mandatory=False,
default_value=1.0,
)
# Attributes
@attribute(
doc="List of registered observations.",
@@ -103,7 +114,23 @@ class ObservationControl(LOFARDevice):
def active_antenna_fields_R(self):
return self._observation_controller.active_antenna_fields
observation_update_thread_running_R = attribute(
doc="Whether the observation states are being updated.",
dtype=bool,
fget=lambda self: (
self.event_loop_thread
and self.event_loop_thread.is_running()
and self.observation_update_task
and self.observation_update_task.is_running()
),
# Tango needs to poll this, as otherwise this attribute will never
# be exposed as "False" as the event thread must run to do so.
polling_period=DEFAULT_POLLING_PERIOD_MS,
)
def __init__(self, cl, name):
self.observation_update_task = None
# Super must be called after variable assignment due to executing init_device!
super().__init__(cl, name)
@@ -131,16 +158,8 @@ class ObservationControl(LOFARDevice):
)
# Core functions
@log_exceptions()
@DebugIt()
def init_device(self):
logger.debug("[ObservationControl] init device")
super().init_device()
# Increase the number of polling threads for this device server.
# NB: This server hosts both ObservationControl and Observation
# devices.
Util.instance().set_polling_threads_pool_size(10)
async def _update_observations(self):
self._observation_controller.update_all_observations()
@log_exceptions()
def configure_for_initialise(self):
@@ -148,6 +167,12 @@ class ObservationControl(LOFARDevice):
self.metadata = self.control.child(DeviceTypes.Metadata)
self.observation_update_task = PeriodicTask(
self.event_loop_thread.event_loop,
self._update_observations,
self.Observation_Update_Interval,
)
# Lifecycle functions
@log_exceptions()
def configure_for_off(self):
Loading