Skip to content

Commit

Permalink
FakeDataAgent: acq method can mark self as degraded
Browse files Browse the repository at this point in the history
  • Loading branch information
mhasself committed Jan 8, 2024
1 parent 8365e77 commit de16c07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion ocs/agents/fake_data/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ def set_job_done(self):
# Process functions.

@ocs_agent.param('test_mode', default=False, type=bool)
@ocs_agent.param('degradation_period', default=None, type=float)
def acq(self, session, params):
"""acq(test_mode=False)
"""acq(test_mode=False, degradation_period=None)
**Process** - Acquire data and write to the feed.
Parameters:
test_mode (bool, optional): Run the acq Process loop only once.
This is meant only for testing. Default is False.
degradation_period (float, optional): If set, then
alternately mark self as degraded / not degraded with
this period (in seconds).
Notes:
The most recent fake values are stored in the session data object in
Expand Down Expand Up @@ -88,6 +92,12 @@ def acq(self, session, params):
reporting_interval = 1.
next_report = next_timestamp + reporting_interval

is_degraded = False
next_deg_flip = None
if params['degradation_period'] is not None:
next_deg_flip = 0
session.data['degraded'] = is_degraded

self.log.info("Starting acquisition")

while True:
Expand All @@ -100,6 +110,12 @@ def acq(self, session, params):
return 10

now = time.time()

if next_deg_flip is not None and now > next_deg_flip:
is_degraded = not is_degraded
next_deg_flip = now + params['degradation_period']
session.data['degraded'] = is_degraded

delay_time = next_report - now
if delay_time > 0:
time.sleep(min(delay_time, 1.))
Expand Down
3 changes: 2 additions & 1 deletion tests/agents/test_fakedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_fake_data_set_heartbeat(agent):

def test_fake_data_acq(agent):
session = create_session('acq')
params = {'test_mode': True}
params = {'test_mode': True,
'degradation_period': None}
res = agent.acq(session, params=params)
assert res[0] is True

Expand Down

0 comments on commit de16c07

Please sign in to comment.