spiff-arena/SpiffWorkflow/bpmn/specs/UnstructuredJoin.py
burnettk d581ac9b22 Squashed 'SpiffWorkflow/' changes from bee868d38..96ad2a2b0
96ad2a2b0 Merge pull request #311 from sartography/feature/error-message-on-bad-child-task
3fb69038d Merge remote-tracking branch 'origin/main' into feature/error-message-on-bad-child-task
df703ebb8 Merge remote-tracking branch 'origin/feature/add_task_not_found_error'
d6e244bcf also raise TaskNotFoundException from bpmn workflow w/ burnettk
37d7ae679 Merge pull request #310 from sartography/feature/add_task_not_found_error
7f4d38ce2 give us a better error if for some reason a task does not exist
b98efbd20 added an exception for task not found w/ burnettk
e1add839d Merge pull request #308 from sartography/bugfix/execute-event-gateways-on-ready
964c0231a do not predict tasks when deserializing, add method to predict all unfinished tasks
114f87aa9 update event gateway
62454c99c Merge pull request #307 from sartography/feature/standardize-task-execution
a087d29ea update task_spec._run to return a boolean & misc cleanup
9864d753d reenable recursion test
1bb1246a0 rename methods & move ready_before tasks from run to ready
12ce08519 move event task execution to run
d51bb68eb cleanup predictions
5e05458a3 make all tasks execute when run rather than completed (except bpmn events)
273d7b325 create a run method for tasks
3c3345c85 Merge pull request #306 from sartography/feature/create-core-test-package
ed85547d7 hopefully fix CI job, also update some deprecated assertions
80d68c231 cleanup around finding tasks
ea5ffff41 create tests based on individual patterns
afe41fba1 move core tests into one package
c075d52bc remove locks from task spec -- they don't do anything
d78c7cc04 reorganize so that related methods are near each other
f162aac43 Merge pull request #305 from sartography/feature/remove-loop-reset
6cad29817 'fix' old serializer to remove loop resets -- or at least get the tests to pass
a95d2fc12 add serialization migration that removes loop resets
c076175c8 account for DST in timers
42b483054 Merge pull request #303 from sartography/bugfix/execute-tasks-on-ready
2bb08aae1 update script/service tasks to execute on ready
0bd23a0ab fix scripts in business rule tasks
13034aaf1 prevent loop reset tasks from being inserted
3fb80518d update join execution model

git-subtree-dir: SpiffWorkflow
git-subtree-split: 96ad2a2b060deb445c39374f065690023351de19
2023-04-07 11:46:14 -04:00

96 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
# Copyright (C) 2012 Matthew Hampton
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
from ...task import TaskState
from .BpmnSpecMixin import BpmnSpecMixin
from ...specs.Join import Join
class UnstructuredJoin(Join, BpmnSpecMixin):
"""
A helper subclass of Join that makes it work in a slightly friendlier way
for the BPMN style threading
"""
def _get_inputs_with_tokens(self, my_task):
# Look at the tree to find all places where this task is used.
tasks = [ t for t in my_task.workflow.get_tasks_from_spec_name(self.name) if t.workflow == my_task.workflow ]
# Look up which tasks have parents completed.
waiting_tasks = []
completed_inputs = set()
for task in tasks:
if task.parent.state == TaskState.COMPLETED:
completed_inputs.add(task.parent.task_spec)
# Ignore predicted tasks; we don't care about anything not definite
elif task.parent._has_state(TaskState.READY | TaskState.FUTURE | TaskState.WAITING):
waiting_tasks.append(task.parent)
return completed_inputs, waiting_tasks
def _do_join(self, my_task):
split_task = self._get_split_task(my_task)
# Identify all corresponding task instances within the thread.
# Also remember which of those instances was most recently changed,
# because we are making this one the instance that will
# continue the thread of control. In other words, we will continue
# to build the task tree underneath the most recently changed task.
last_changed = None
thread_tasks = []
for task in split_task._find_any(self):
if task.thread_id != my_task.thread_id:
# Ignore tasks from other threads. (Do we need this condition?)
continue
if not task.parent._is_finished():
# For an inclusive join, this can happen - it's a future join
continue
if my_task._is_descendant_of(task):
# Skip ancestors (otherwise the branch this task is on will get dropped)
continue
# We have found a matching instance.
thread_tasks.append(task)
# Check whether the state of the instance was recently changed.
changed = task.parent.last_state_change
if last_changed is None or changed > last_changed.parent.last_state_change:
last_changed = task
# Update data from all the same thread tasks.
thread_tasks.sort(key=lambda t: t.parent.last_state_change)
collected_data = {}
for task in thread_tasks:
collected_data.update(task.data)
for task in thread_tasks:
if task != last_changed:
task._set_state(TaskState.CANCELLED)
task._drop_children()
else:
task.data.update(collected_data)
def task_should_set_children_future(self, my_task):
return True
def task_will_set_children_future(self, my_task):
# go find all of the gateways with the same name as this one,
# drop children and set state to WAITING
for t in list(my_task.workflow.task_tree):
if t.task_spec.name == self.name and t.state == TaskState.COMPLETED:
t._set_state(TaskState.WAITING)