2022-10-12 10:19:53 -04:00
|
|
|
from copy import deepcopy
|
|
|
|
|
2023-01-19 10:47:07 -05:00
|
|
|
from SpiffWorkflow.exceptions import SpiffWorkflowException
|
2022-10-12 10:19:53 -04:00
|
|
|
from SpiffWorkflow.task import TaskState
|
|
|
|
from SpiffWorkflow.bpmn.specs .BpmnSpecMixin import BpmnSpecMixin
|
|
|
|
|
|
|
|
class SpiffBpmnTask(BpmnSpecMixin):
|
|
|
|
|
|
|
|
def __init__(self, wf_spec, name, prescript=None, postscript=None, **kwargs):
|
|
|
|
|
|
|
|
# WHy am I doing this instead of just calling super?
|
|
|
|
# Because I need to deal with multiple inheritance and the kwargs nightmare created by our parser design
|
|
|
|
BpmnSpecMixin.__init__(self, wf_spec, name, **kwargs)
|
|
|
|
self.prescript = prescript
|
|
|
|
self.postscript = postscript
|
|
|
|
|
|
|
|
@property
|
|
|
|
def spec_type(self):
|
|
|
|
return 'Spiff BPMN Task'
|
|
|
|
|
|
|
|
def execute_script(self, my_task, script):
|
|
|
|
try:
|
|
|
|
my_task.workflow.script_engine.execute(my_task, script)
|
|
|
|
except Exception as exc:
|
|
|
|
my_task._set_state(TaskState.WAITING)
|
|
|
|
raise exc
|
|
|
|
|
|
|
|
def get_payload(self, my_task, script, expr):
|
|
|
|
try:
|
|
|
|
data = deepcopy(my_task.data)
|
|
|
|
my_task.worklflow.script_engine.execute(my_task, script, data)
|
|
|
|
return my_task.workflow.script_engine._evaluate(expr, data)
|
|
|
|
except Exception as exc:
|
|
|
|
my_task._set_state(TaskState.WAITING)
|
|
|
|
raise exc
|
|
|
|
|
2023-02-23 10:42:56 -05:00
|
|
|
def _update_hook(self, my_task):
|
|
|
|
super()._update_hook(my_task)
|
2022-10-12 10:19:53 -04:00
|
|
|
if self.prescript is not None:
|
2023-01-19 10:47:07 -05:00
|
|
|
try:
|
|
|
|
self.execute_script(my_task, self.prescript)
|
|
|
|
except SpiffWorkflowException as se:
|
|
|
|
se.add_note("Error occurred in the Pre-Script")
|
|
|
|
raise se
|
2023-02-23 10:42:56 -05:00
|
|
|
return True
|
2022-10-12 10:19:53 -04:00
|
|
|
|
|
|
|
def _on_complete_hook(self, my_task):
|
|
|
|
if self.postscript is not None:
|
2023-01-19 10:47:07 -05:00
|
|
|
try:
|
|
|
|
self.execute_script(my_task, self.postscript)
|
|
|
|
except SpiffWorkflowException as se:
|
|
|
|
se.add_note("Error occurred in the Post-Script")
|
|
|
|
raise se
|
|
|
|
super()._on_complete_hook(my_task)
|