Skip to content

Commit

Permalink
OCSAgent: make process stop() report it's been run
Browse files Browse the repository at this point in the history
Also catch errors in the stop function.  Document the signatures for
process/task start/stop functions.
  • Loading branch information
simonsobs committed Jan 19, 2022
1 parent aa6fda0 commit cba8f7b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ocs/ocs_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,12 @@ def register_task(self, name, func, blocking=True, startup=False):
launched on startup. If the ``startup`` argument is a
dictionary, this is passed to the Operation's start
function.
Notes:
The function func will be called with arguments (session,
params) where session is the active OpSession and params
is passed from the client.
"""
self.tasks[name] = AgentTask(func, blocking=blocking)
self.sessions[name] = None
Expand All @@ -412,6 +418,14 @@ def register_process(self, name, start_func, stop_func, blocking=True, startup=F
dictionary, this is passed to the Operation's start
function.
Notes:
The functions start_func and stop_func will be called with
arguments (session, params) where session is the active
OpSession and params is passed from the client.
(Passing params to the stop_func might not be supported in
the client library so don't count on that being useful.)
"""
self.processes[name] = AgentProcess(start_func, stop_func,
blocking=blocking)
Expand Down Expand Up @@ -756,15 +770,20 @@ def stop(self, op_name, params=None):
ocs.OK: the Process stop routine has been launched.
"""
print('stop called for {}'.format(op_name))
if op_name in self.tasks:
return (ocs.ERROR, 'No implementation for "%s" because it is a task.' % op_name,
{})
elif op_name in self.processes:
def _errback(self, *args, **kw):
print(f'Error calling stopper for "{op_name}"; args:',
args, kw)
session = self.sessions.get(op_name)
if session is None:
return (ocs.ERROR, 'No session active.', {})
proc = self.processes[op_name]
d2 = threads.deferToThread(proc.stopper, session, params)
d2.addErrback(_errback)
return (ocs.OK, 'Requested stop on process "%s".' % op_name, session.encoded())
else:
return (ocs.ERROR, 'No process called "%s".' % op_name, {})
Expand Down

0 comments on commit cba8f7b

Please sign in to comment.