mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-15 04:34:16 +00:00
37b7f3d7cd
cd4da465 Merge pull request #264 from sartography/bugfix/dmn-equality-with-boolean 414a59eb disambiguate DMN expressions eea53c91 Merge pull request #263 from sartography/feature/cleanup-task-completion d248d5b1 execute postscript before other complete hook tasks c09f1a90 streamline predict & remove some duplicated calls to it 64c21791 remove duplicate calls to update 4ca1076d move task update to _on_complete to ensure data is copied consistently after task related activities are done d037a7eb small changes for readability 025bc30f Quick patch -- is_executable needs to be accurate immediately. 14d3d8c3 Merge pull request #262 from sartography/feature/parser_info_features 849c223e We are jumping through a lot of complex xml parsing in SpiffWorkflow-Backend because we need to know some basic information about a BPMN process at the moment it is saved. Rather than do that work in the backend, it seems better to have SpiffWorkflow handle parsing the xml and providing a bit of metadata, including: git-subtree-dir: SpiffWorkflow git-subtree-split: cd4da465e125ca1ae1b57d227bfa324d9d4c507c
112 lines
3.8 KiB
Python
112 lines
3.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from builtins import range
|
|
# Copyright (C) 2007 Samuel Abels
|
|
#
|
|
# 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 .base import TaskSpec
|
|
from ..operators import valueof
|
|
|
|
|
|
class MultiInstance(TaskSpec):
|
|
|
|
"""
|
|
When executed, this task performs a split on the current task.
|
|
The number of outgoing tasks depends on the runtime value of a
|
|
specified data field.
|
|
If more than one input is connected, the task performs an implicit
|
|
multi merge.
|
|
|
|
This task has one or more inputs and may have any number of outputs.
|
|
"""
|
|
|
|
def __init__(self, wf_spec, name, times, **kwargs):
|
|
"""
|
|
Constructor.
|
|
|
|
:type wf_spec: WorkflowSpec
|
|
:param wf_spec: A reference to the workflow specification.
|
|
:type name: str
|
|
:param name: The name of the task spec.
|
|
:type times: int or :class:`SpiffWorkflow.operators.Term`
|
|
:param times: The number of tasks to create.
|
|
:type kwargs: dict
|
|
:param kwargs: See :class:`SpiffWorkflow.specs.TaskSpec`.
|
|
"""
|
|
if times is None:
|
|
raise ValueError('times argument is required')
|
|
TaskSpec.__init__(self, wf_spec, name, **kwargs)
|
|
self.times = times
|
|
self.prevtaskclass = None
|
|
|
|
def _find_my_task(self, task):
|
|
for thetask in task.workflow.task_tree:
|
|
if thetask.thread_id != task.thread_id:
|
|
continue
|
|
if thetask.task_spec == self:
|
|
return thetask
|
|
return None
|
|
|
|
def _on_trigger(self, task_spec):
|
|
"""
|
|
May be called after execute() was already completed to create an
|
|
additional outbound task.
|
|
"""
|
|
# Find a Task for this TaskSpec.
|
|
my_task = self._find_my_task(task_spec)
|
|
if my_task._has_state(TaskState.COMPLETED):
|
|
state = TaskState.READY
|
|
else:
|
|
state = TaskState.FUTURE
|
|
for output in self.outputs:
|
|
new_task = my_task._add_child(output, state)
|
|
new_task.triggered = True
|
|
output._predict(new_task)
|
|
|
|
def _get_predicted_outputs(self, my_task):
|
|
split_n = int(valueof(my_task, self.times, 1))
|
|
|
|
# Predict the outputs.
|
|
outputs = []
|
|
for i in range(split_n):
|
|
outputs += self.outputs
|
|
return outputs
|
|
|
|
def _predict_hook(self, my_task):
|
|
split_n = int(valueof(my_task, self.times, 1))
|
|
my_task._set_internal_data(splits=split_n)
|
|
|
|
# Create the outgoing tasks.
|
|
outputs = []
|
|
for i in range(split_n):
|
|
outputs += self.outputs
|
|
if my_task._is_definite():
|
|
my_task._sync_children(outputs, TaskState.FUTURE)
|
|
else:
|
|
my_task._sync_children(outputs, TaskState.LIKELY)
|
|
|
|
def _on_complete_hook(self, my_task):
|
|
outputs = self._get_predicted_outputs(my_task)
|
|
my_task._sync_children(outputs, TaskState.FUTURE)
|
|
|
|
def serialize(self, serializer):
|
|
return serializer.serialize_multi_instance(self)
|
|
|
|
@classmethod
|
|
def deserialize(self, serializer, wf_spec, s_state):
|
|
return serializer.deserialize_multi_instance(wf_spec, s_state)
|