TaskHandler.active method created

TaskHandler.active method created to check if a task is currently active.

test_delay unit test passes.
This commit is contained in:
davewiththenicehat 2021-04-18 09:59:45 -04:00
parent af44237838
commit bbc60b0340
2 changed files with 35 additions and 0 deletions

View file

@ -230,6 +230,32 @@ class TaskHandler(object):
else:
return False
def active(self, task_id):
"""
Check if a task is active (has not been called yet).
Args:
task_id (int): an existing task ID.
Returns:
True (bool): If a task is active (has not been called yet).
False (bool): if the task
is not active (has already been called),
does not exist
"""
if task_id in self.tasks:
# if the task has not been run, cancel it
d = self.get_deferred(task_id)
if d: # it is remotely possible for a task to not have a deferral
if d.called:
return False
else: # the callback has not been called yet.
return True
else: # this task has no deferral, and could not have been called
return True
else:
return False
def cancel(self, task_id):
"""