Skip to content

Commit

Permalink
Merge pull request #108 from lsj9383/master
Browse files Browse the repository at this point in the history
Optimize the efficiency of acquisition tasks
  • Loading branch information
knipknap committed May 7, 2020
2 parents 9c09d5a + f8f2217 commit b5778a3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions SpiffWorkflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ def get_task(self, id):
:rtype: Task
:returns: The task with the given id.
"""
tasks = [task for task in self.get_tasks() if task.id == id]
return tasks[0] if len(tasks) == 1 else None
for task in self.get_tasks_iterator():
if task.id == id:
return task
return None

def get_tasks_from_spec_name(self, name):
"""
Expand All @@ -179,7 +181,7 @@ def get_tasks_from_spec_name(self, name):
:rtype: Task
:return: The task that relates to the spec with the given name.
"""
return [task for task in self.get_tasks()
return [task for task in self.get_tasks_iterator()
if task.task_spec.name == name]

def get_tasks(self, state=Task.ANY_MASK):
Expand All @@ -193,6 +195,17 @@ def get_tasks(self, state=Task.ANY_MASK):
"""
return [t for t in Task.Iterator(self.task_tree, state)]

def get_tasks_iterator(self, state=Task.ANY_MASK):
"""
Returns a iterator of Task objects with the given state.
:type state: integer
:param state: A bitmask of states.
:rtype: Task.Iterator
:returns: A list of tasks.
"""
return Task.Iterator(self.task_tree, state)

def complete_task_from_id(self, task_id):
"""
Runs the task with the given id.
Expand Down

0 comments on commit b5778a3

Please sign in to comment.