burnettk f14b4acb86 Squashed 'SpiffWorkflow/' changes from 96ad2a2b0..73886584b
73886584b Merge pull request #315 from sartography/feature/new-task-states
a04fdd311 Merge remote-tracking branch 'origin/main' into feature/new-task-states
3d376bf9a documentation and comment updates
7e368ee4b copy edit
e7b9fe91c typo
eceef15a7 Called elements (#316)
5a0fd2774 add serialization migration
7211e67ee Merge pull request #314 from sartography/bugfix/data-object-references
403acc1f5 use same data objects & references in subprocesses after deserialization
c54091dee add two more states to spiff
fa04a14a7 clean up script engine a little bit
162a1c5f5 override create parser in spiff package to allow duplicate process names
98a1b37e0 Merge pull request #312 from sartography/bugfix/run-boundary-events-from-engine-steps
067d6a723 do not execute boundary events in catch
1c877dd76 send external events to top level workflow

git-subtree-dir: SpiffWorkflow
git-subtree-split: 73886584b17c7d11a9713d0c4526ed41e411fc45
2023-04-21 11:22:52 -04:00

47 lines
1.7 KiB
Python

import json
from copy import deepcopy
from SpiffWorkflow.bpmn.specs.ServiceTask import ServiceTask
from SpiffWorkflow.exceptions import WorkflowTaskException
from SpiffWorkflow.spiff.specs.spiff_task import SpiffBpmnTask
class ServiceTask(SpiffBpmnTask, ServiceTask):
def __init__(self, wf_spec, name, operation_name, operation_params, result_variable, **kwargs):
SpiffBpmnTask.__init__(self, wf_spec, name, **kwargs)
self.operation_name = operation_name
self.operation_params = operation_params
self.result_variable = result_variable
@property
def spec_type(self):
return 'Service Task'
def _result_variable(self, task):
if self.result_variable is not None and len(self.result_variable) > 0:
return self.result_variable
escaped_spec_name = task.task_spec.name.replace('-', '_')
return f'spiff__{escaped_spec_name}_result'
def _execute(self, task):
def evaluate(param):
param['value'] = task.workflow.script_engine.evaluate(task, param['value'])
return param
operation_params_copy = deepcopy(self.operation_params)
evaluated_params = {k: evaluate(v) for k, v in operation_params_copy.items()}
try:
result = task.workflow.script_engine.call_service(self.operation_name,
evaluated_params, task.data)
except Exception as e:
wte = WorkflowTaskException("Error executing Service Task",
task=task, exception=e)
wte.add_note(str(e))
raise wte
parsed_result = json.loads(result)
task.data[self._result_variable(task)] = parsed_result
return True