Skip to content

Commit

Permalink
add 'halt_on_manual' argument to Workflow.complete_next() and .comple…
Browse files Browse the repository at this point in the history
…te_all(). Closes #52
  • Loading branch information
knipknap committed Jul 1, 2017
1 parent 2e591f0 commit b8c271f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
28 changes: 15 additions & 13 deletions SpiffWorkflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def complete_task_from_id(self, task_id):
msg = 'A task with the given task_id (%s) was not found' % task_id
raise WorkflowException(self.spec, msg)

def complete_next(self, pick_up=True):
def complete_next(self, pick_up=True, halt_on_manual=True):
"""
Runs the next task.
Returns True if completed, False otherwise.
Expand All @@ -226,24 +226,26 @@ def complete_next(self, pick_up=True):
if pick_up and self.last_task is not None:
try:
iter = Task.Iterator(self.last_task, Task.READY)
next = next(iter)
task = next(iter)
except:
next = None
task = None
self.last_task = None
if next is not None:
if next.complete():
self.last_task = next
return True
blacklist.append(next)
if task is not None:
if not (halt_on_manual and task.task_spec.manual):
if task.complete():
self.last_task = task
return True
blacklist.append(task)

# Walk through all ready tasks.
for task in Task.Iterator(self.task_tree, Task.READY):
for blacklisted_task in blacklist:
if task._is_descendant_of(blacklisted_task):
continue
if task.complete():
self.last_task = task
return True
if not (halt_on_manual and task.task_spec.manual):
if task.complete():
self.last_task = task
return True
blacklist.append(task)

# Walk through all waiting tasks.
Expand All @@ -254,7 +256,7 @@ def complete_next(self, pick_up=True):
return True
return False

def complete_all(self, pick_up=True):
def complete_all(self, pick_up=True, halt_on_manual=True):
"""
Runs all branches until completion. This is a convenience wrapper
around :meth:`complete_next`, and the pick_up argument is passed
Expand All @@ -263,7 +265,7 @@ def complete_all(self, pick_up=True):
:type pick_up: bool
:param pick_up: Passed on to each call of complete_next().
"""
while self.complete_next(pick_up):
while self.complete_next(pick_up, halt_on_manual):
pass

def get_dump(self):
Expand Down
6 changes: 5 additions & 1 deletion doc/custom-tasks/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@

# Create the workflow.
workflow = Workflow(spec)
workflow.complete_all()

# Execute until all tasks are done or require manual intervention.
# For the sake of this tutorial, we ignore the "manual" flag on the
# tasks. In practice, you probably don't want to do that.
workflow.complete_all(halt_on_manual=False)
4 changes: 3 additions & 1 deletion doc/tutorial/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
workflow = Workflow(spec)

# Execute until all tasks are done or require manual intervention.
workflow.complete_all()
# For the sake of this tutorial, we ignore the "manual" flag on the
# tasks. In practice, you probably don't want to do that.
workflow.complete_all(halt_on_manual=False)

# Alternatively, this is what a UI would do for a manual task.
#workflow.complete_task_from_id(...)

0 comments on commit b8c271f

Please sign in to comment.