mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-05 22:53:57 +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
116 lines
3.9 KiB
Python
116 lines
3.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
from copy import deepcopy
|
|
|
|
from SpiffWorkflow.task import TaskState
|
|
from .BpmnSpecMixin import BpmnSpecMixin
|
|
from ...specs.base import TaskSpec
|
|
|
|
|
|
class SubWorkflowTask(BpmnSpecMixin):
|
|
"""
|
|
Task Spec for a bpmn node containing a subworkflow.
|
|
"""
|
|
def __init__(self, wf_spec, name, subworkflow_spec, transaction=False, **kwargs):
|
|
"""
|
|
Constructor.
|
|
|
|
:param bpmn_wf_spec: the BpmnProcessSpec for the sub process.
|
|
:param bpmn_wf_class: the BpmnWorkflow class to instantiate
|
|
"""
|
|
super(SubWorkflowTask, self).__init__(wf_spec, name, **kwargs)
|
|
self.spec = subworkflow_spec
|
|
self.transaction = transaction
|
|
|
|
@property
|
|
def spec_type(self):
|
|
return 'Subprocess'
|
|
|
|
def test(self):
|
|
TaskSpec.test(self)
|
|
|
|
def _on_ready_before_hook(self, my_task):
|
|
subworkflow = my_task.workflow.create_subprocess(my_task, self.spec, self.name)
|
|
subworkflow.completed_event.connect(self._on_subworkflow_completed, my_task)
|
|
subworkflow.data = deepcopy(my_task.workflow.data)
|
|
|
|
def _on_ready_hook(self, my_task):
|
|
|
|
super()._on_ready_hook(my_task)
|
|
self.start_workflow(my_task)
|
|
|
|
def _on_subworkflow_completed(self, subworkflow, my_task):
|
|
|
|
# Shouldn't this always be true?
|
|
if isinstance(my_task.parent.task_spec, BpmnSpecMixin):
|
|
my_task.parent.task_spec._child_complete_hook(my_task)
|
|
|
|
if len(subworkflow.spec.data_outputs) == 0:
|
|
# Copy all workflow data if no outputs are specified
|
|
my_task.data = deepcopy(subworkflow.last_task.data)
|
|
else:
|
|
end = subworkflow.get_tasks_from_spec_name('End', workflow=subworkflow)
|
|
# Otherwise only copy data with the specified names
|
|
for var in subworkflow.spec.data_outputs:
|
|
var.copy(end[0], my_task, data_output=True)
|
|
|
|
my_task._set_state(TaskState.READY)
|
|
|
|
def _update_hook(self, my_task):
|
|
wf = my_task.workflow._get_outermost_workflow(my_task)
|
|
if my_task.id not in wf.subprocesses:
|
|
super()._update_hook(my_task)
|
|
|
|
def _predict_hook(self, my_task):
|
|
# The base Subworkflow task predict doesn't work with the loop reset task
|
|
BpmnSpecMixin._predict_hook(self, my_task)
|
|
|
|
def _on_complete_hook(self, my_task):
|
|
BpmnSpecMixin._on_complete_hook(self, my_task)
|
|
|
|
def _on_cancel(self, my_task):
|
|
subworkflow = my_task.workflow.get_subprocess(my_task)
|
|
if subworkflow is not None:
|
|
subworkflow.cancel()
|
|
|
|
def start_workflow(self, my_task):
|
|
|
|
subworkflow = my_task.workflow.get_subprocess(my_task)
|
|
start = subworkflow.get_tasks_from_spec_name('Start', workflow=subworkflow)
|
|
|
|
if len(subworkflow.spec.data_inputs) == 0:
|
|
# Copy all task data into start task if no inputs specified
|
|
start[0].set_data(**my_task.data)
|
|
else:
|
|
# Otherwise copy only task data with the specified names
|
|
for var in subworkflow.spec.data_inputs:
|
|
var.copy(my_task, start[0], data_input=True)
|
|
|
|
for child in subworkflow.task_tree.children:
|
|
child.task_spec._update(child)
|
|
|
|
my_task._set_state(TaskState.WAITING)
|
|
|
|
def task_will_set_children_future(self, my_task):
|
|
my_task.workflow.delete_subprocess(my_task)
|
|
|
|
|
|
class CallActivity(SubWorkflowTask):
|
|
|
|
def __init__(self, wf_spec, name, subworkflow_spec, **kwargs):
|
|
super(CallActivity, self).__init__(wf_spec, name, subworkflow_spec, False, **kwargs)
|
|
|
|
@property
|
|
def spec_type(self):
|
|
return 'Call Activity'
|
|
|
|
|
|
class TransactionSubprocess(SubWorkflowTask):
|
|
|
|
def __init__(self, wf_spec, name, subworkflow_spec, **kwargs):
|
|
super(TransactionSubprocess, self).__init__(wf_spec, name, subworkflow_spec, True, **kwargs)
|
|
|
|
@property
|
|
def spec_type(self):
|
|
return 'Transactional Subprocess'
|
|
|