Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jbirddog committed Jun 28, 2024
1 parent ed6c428 commit a36ccad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
26 changes: 15 additions & 11 deletions SpiffWorkflow/bpmn/util/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ def matches(self, task):
def _catches_event(task):
return isinstance(task.task_spec, CatchingEvent) and task.task_spec.catches(task, self.catches_event)

return all([
super().matches(task),
self.catches_event is None or _catches_event(task),
self.lane is None or task.task_spec.lane == self.lane,
])
if not super().matches(task):
return False

if not (self.catches_event is None or _catches_event(task)):
return False

if not (self.lane is None or task.task_spec.lane == self.lane):
return False

return True


class BpmnTaskIterator(TaskIterator):
Expand All @@ -55,12 +60,11 @@ def _next(self):
task = self.task_list.pop(0)
subprocess = task.workflow.top_workflow.subprocesses.get(task.id)

if all([
len(task._children) > 0 or subprocess is not None,
task.state >= self.min_state or subprocess is not None,
self.depth < self.max_depth,
task.task_spec.name != self.end_at_spec,
]):
if (len(task._children) > 0 or subprocess is not None) and \
(task.state >= self.min_state or subprocess is not None) and \
self.depth < self.max_depth and \
task.task_spec.name != self.end_at_spec:

# Do not descend into a completed subprocess to look for unfinished tasks.
if (
subprocess is None
Expand Down
36 changes: 23 additions & 13 deletions SpiffWorkflow/util/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,25 @@ def matches(self, task):
Returns:
bool: indicates whether the task matches
"""
return all([
task.has_state(self.state),
task.last_state_change >= self.updated_ts,
self.manual is None or task.task_spec.manual == self.manual,
self.spec_name is None or task.task_spec.name == self.spec_name,
self.spec_class is None or isinstance(task.task_spec, self.spec_class),
])

if not task.has_state(self.state):
return False

if not task.last_state_change >= self.updated_ts:
return False

if not (self.manual is None or task.task_spec.manual == self.manual):
return False

if not (self.spec_name is None or task.task_spec.name == self.spec_name):
return False

if not (self.spec_class is None or isinstance(task.task_spec, self.spec_class)):
return False


return True


class TaskIterator:
"""Default task iteration class."""
Expand Down Expand Up @@ -218,12 +229,11 @@ def _next(self):
raise StopIteration()

task = self.task_list.pop(0)
if all([
len(task._children) > 0,
task.state >= self.min_state,
self.depth < self.max_depth,
task.task_spec.name != self.end_at_spec,
]):
if len(task._children) > 0 and \
task.state >= self.min_state and \
self.depth < self.max_depth and \
task.task_spec.name != self.end_at_spec:

if self.depth_first:
self.task_list = task.children + self.task_list
else:
Expand Down
4 changes: 4 additions & 0 deletions SpiffWorkflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, workflow_spec, deserializing=False):
self.last_task = None
self.success = True
self.tasks = {}
self.completed = False

# Events.
self.completed_event = Event()
Expand All @@ -72,10 +73,13 @@ def is_completed(self):
Returns:
bool: True if the workflow has no unfinished tasks
"""
if self.completed:
return True
iter = TaskIterator(self.task_tree, state=TaskState.NOT_FINISHED_MASK)
try:
next(iter)
except StopIteration:
self.completed = True
return True
return False

Expand Down

0 comments on commit a36ccad

Please sign in to comment.