mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-29 19:25:50 +00:00
35ef5cbe54
1f51db962 Merge pull request #283 from sartography/feature/better_errors 69fb4967e Patching up some bugs and logical disconnects as I test out the errors. cf5be0096 * Making a few more things consistent in the error messages -- so there isn't filename for validation errors, and file_name for WorkflowExceptions. Same for line_number vs sourceline. * Assure than an error_type is consistently set on exceptions. * ValidationExceptions should not bild up a detailed error message that replicates information available within it. 440ee16c8 Responding to some excellent suggestions from Elizabeth: 655e415e1 Merge pull request #282 from subhakarks/fix-workfowspec-dump 1f6d3cf4e Explain that the error happened in a pre-script or post script. 8119abd14 Added a top level SpiffWorklowException that all exceptions inherit from. Aside from a message string you can append information to these exceptions with "add_note", which is a new method that all exceptions have starting in python 3.11 Switched arguments to the WorkflowException, WorkflowTaskException - which now always takes a string message as the first argument, and named arguments thereafter to be consistent with all other error messages in Python. Consistently raise ValidationExceptions whenever we encounter an error anywhere during parsing of xml. The BPMN/WorkflowTaskExecException is removed, in favor of just calling a WorkflowTaskException. There is nothing BPMN Specific in the logic, so no need for this. Consolidated error message logic so that things like "Did you mean" just get added by default if possible. So we don't have to separately deal with that logic each time. Better Error messages for DMN (include row number as a part of the error information) 13463b5c5 fix for workflowspec dump be26100bc Merge pull request #280 from sartography/feature/remove-unused-bpmn-attributes-and-methods 23a5c1d70 remove 'entering_* methods 4e5875ec8 remove sequence flow 5eed83ab1 Merge pull request #278 from sartography/feature/remove-old-serializer 614f1c68a remove compact serializer and references e7e410d4a remove old serializer and references git-subtree-dir: SpiffWorkflow git-subtree-split: 1f51db962ccaed5810f5d0f7d76a932f056430ab
120 lines
4.6 KiB
Python
120 lines
4.6 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 collections import deque
|
|
|
|
from ...task import TaskState
|
|
from .UnstructuredJoin import UnstructuredJoin
|
|
|
|
|
|
class InclusiveGateway(UnstructuredJoin):
|
|
"""
|
|
Task Spec for a bpmn:parallelGateway node. From the specification of BPMN
|
|
(http://www.omg.org/spec/BPMN/2.0/PDF - document number:formal/2011-01-03):
|
|
|
|
The Inclusive Gateway is activated if
|
|
* At least one incoming Sequence Flow has at least one token and
|
|
* For every directed path formed by sequence flow that
|
|
* starts with a Sequence Flow f of the diagram that has a token,
|
|
* ends with an incoming Sequence Flow of the inclusive gateway that has
|
|
no token, and
|
|
* does not visit the Inclusive Gateway.
|
|
* There is also a directed path formed by Sequence Flow that
|
|
* starts with f,
|
|
* ends with an incoming Sequence Flow of the inclusive gateway that has
|
|
a token, and
|
|
* does not visit the Inclusive Gateway.
|
|
|
|
Upon execution, a token is consumed from each incoming Sequence Flow that
|
|
has a token. A token will be produced on some of the outgoing Sequence
|
|
Flows.
|
|
|
|
TODO: Not implemented: At the moment, we can't handle having more than one
|
|
token at a single incoming sequence
|
|
TODO: At the moment only converging Inclusive Gateways are supported.
|
|
|
|
In order to determine the outgoing Sequence Flows that receive a token, all
|
|
conditions on the outgoing Sequence Flows are evaluated. The evaluation
|
|
does not have to respect a certain order.
|
|
|
|
For every condition which evaluates to true, a token MUST be passed on the
|
|
respective Sequence Flow.
|
|
|
|
If and only if none of the conditions evaluates to true, the token is
|
|
passed on the default Sequence Flow.
|
|
|
|
In case all conditions evaluate to false and a default flow has not been
|
|
specified, the Inclusive Gateway throws an exception.
|
|
"""
|
|
|
|
@property
|
|
def spec_type(self):
|
|
return 'Inclusive Gateway'
|
|
|
|
def _check_threshold_unstructured(self, my_task, force=False):
|
|
|
|
# Look at the tree to find all ready and waiting tasks (excluding ones
|
|
# that are our completed inputs).
|
|
tasks = []
|
|
for task in my_task.workflow.get_tasks(TaskState.READY | TaskState.WAITING):
|
|
if task.thread_id != my_task.thread_id:
|
|
continue
|
|
if task.workflow != my_task.workflow:
|
|
continue
|
|
if task.task_spec == my_task.task_spec:
|
|
continue
|
|
tasks.append(task)
|
|
|
|
inputs_with_tokens, waiting_tasks = self._get_inputs_with_tokens(
|
|
my_task)
|
|
inputs_without_tokens = [
|
|
i for i in self.inputs if i not in inputs_with_tokens]
|
|
|
|
waiting_tasks = []
|
|
for task in tasks:
|
|
if (self._has_directed_path_to(
|
|
task, self,
|
|
without_using_sequence_flow_from=inputs_with_tokens) and
|
|
not self._has_directed_path_to(
|
|
task, self,
|
|
without_using_sequence_flow_from=inputs_without_tokens)):
|
|
waiting_tasks.append(task)
|
|
|
|
return force or len(waiting_tasks) == 0, waiting_tasks
|
|
|
|
def _has_directed_path_to(self, task, task_spec,
|
|
without_using_sequence_flow_from=None):
|
|
q = deque()
|
|
done = set()
|
|
|
|
without_using_sequence_flow_from = set(
|
|
without_using_sequence_flow_from or [])
|
|
|
|
q.append(task.task_spec)
|
|
while q:
|
|
n = q.popleft()
|
|
if n == task_spec:
|
|
return True
|
|
for child in n.outputs:
|
|
if child not in done and not (
|
|
n in without_using_sequence_flow_from and
|
|
child == task_spec):
|
|
done.add(child)
|
|
q.append(child)
|
|
return False
|