2022-10-12 10:19:53 -04:00
|
|
|
# -*- 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 .BpmnSpecMixin import BpmnSpecMixin
|
|
|
|
from ...task import TaskState
|
|
|
|
from ...specs.Simple import Simple
|
|
|
|
|
|
|
|
|
|
|
|
class ScriptEngineTask(Simple, BpmnSpecMixin):
|
|
|
|
"""Task Spec for a bpmn:scriptTask node"""
|
|
|
|
|
|
|
|
def _execute(self, task):
|
|
|
|
"""Please override for specific Implementations, see ScriptTask below for an example"""
|
|
|
|
pass
|
|
|
|
|
2023-04-07 11:46:14 -04:00
|
|
|
def _run_hook(self, task):
|
2022-10-12 10:19:53 -04:00
|
|
|
try:
|
|
|
|
self._execute(task)
|
2023-04-07 11:46:14 -04:00
|
|
|
super(ScriptEngineTask, self)._run_hook(task)
|
2022-10-12 10:19:53 -04:00
|
|
|
except Exception as exc:
|
|
|
|
task._set_state(TaskState.WAITING)
|
|
|
|
raise exc
|
2023-04-07 11:46:14 -04:00
|
|
|
return True
|
2022-10-12 10:19:53 -04:00
|
|
|
|
|
|
|
class ScriptTask(ScriptEngineTask):
|
|
|
|
|
|
|
|
def __init__(self, wf_spec, name, script, **kwargs):
|
|
|
|
"""
|
|
|
|
Constructor.
|
|
|
|
|
|
|
|
:param script: the script that must be executed by the script engine.
|
|
|
|
"""
|
|
|
|
super(ScriptTask, self).__init__(wf_spec, name, **kwargs)
|
|
|
|
self.script = script
|
|
|
|
|
|
|
|
@property
|
|
|
|
def spec_type(self):
|
|
|
|
return 'Script Task'
|
|
|
|
|
|
|
|
def _execute(self, task):
|
|
|
|
task.workflow.script_engine.execute(task, self.script)
|
|
|
|
|