Skip to content

Commit

Permalink
Merge d0b44e9 into 7356b59
Browse files Browse the repository at this point in the history
  • Loading branch information
mhasself committed Sep 24, 2020
2 parents 7356b59 + d0b44e9 commit 62dd09c
Show file tree
Hide file tree
Showing 14 changed files with 1,872 additions and 194 deletions.
38 changes: 38 additions & 0 deletions agents/fake_data/fake_data_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import threading
import os
from autobahn.wamp.exception import ApplicationError
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.util import sleep as dsleep
import numpy as np

class FakeDataAgent:
Expand Down Expand Up @@ -124,6 +126,8 @@ def stop_acq(self, session, params=None):
return (ok, {True: 'Requested process stop.',
False: 'Failed to request process stop.'}[ok])

# Tasks

def set_heartbeat_state(self, session, params=None):
"""Task to set the state of the agent heartbeat.
Expand All @@ -139,6 +143,39 @@ def set_heartbeat_state(self, session, params=None):

return True, "Set heartbeat_on: {}".format(heartbeat_state)

@inlineCallbacks
def delay_task(self, session, params={}):
"""Task that will take the requested number of seconds to complete.
This can run simultaneously with the acq Process. This Task
should run in the reactor thread.
The session data will be updated with the requested delay as
well as the time elapsed so far, for example::
{'requested_delay': 5.,
'delay_so_far': 1.2}
Args:
delay (float): Time to wait before returning, in seconds.
Defaults to 5.
succeed (bool): Whether to return success or not.
Defaults to True.
"""
session.set_status('running')
delay = params.get('delay', 5)
session.data = {'requested_delay': delay,
'delay_so_far': 0}
succeed = params.get('succeed', True) is True
t0 = time.time()
while True:
session.data['delay_so_far'] = time.time() - t0
sleep_time = min(0.5, delay - session.data['delay_so_far'])
if sleep_time < 0:
break
yield dsleep(sleep_time)
return succeed, 'Exited after %.1f seconds' % session.data['delay_so_far']


def add_agent_args(parser_in=None):
Expand Down Expand Up @@ -171,5 +208,6 @@ def add_agent_args(parser_in=None):
agent.register_process('acq', fdata.start_acq, fdata.stop_acq,
blocking=True, startup=startup)
agent.register_task('set_heartbeat', fdata.set_heartbeat_state)
agent.register_task('delay_task', fdata.delay_task, blocking=False)

runner.run(agent, auto_reconnect=True)
Binary file added docs/_static/ocs_web_uibox.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 62dd09c

Please sign in to comment.