-
Notifications
You must be signed in to change notification settings - Fork 310
/
ScriptTask.py
57 lines (49 loc) · 2.11 KB
/
ScriptTask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
from __future__ import division
# 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
import logging
from .BpmnSpecMixin import BpmnSpecMixin
from ...task import Task
from ...specs.Simple import Simple
from ...exceptions import WorkflowTaskExecException
LOG = logging.getLogger(__name__)
class ScriptTask(Simple, BpmnSpecMixin):
"""
Task Spec for a bpmn:scriptTask node.
"""
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
def _on_complete_hook(self, task):
if task.workflow._is_busy_with_restore():
return
assert not task.workflow.read_only
try:
task.workflow.script_engine.execute(task, self.script)
except Exception:
LOG.error('Error executing ScriptTask; task=%r', task, exc_info=True)
# set state to WAITING (because it is definitely not COMPLETED)
# and raise WorkflowException pointing to this task because
# maybe upstream someone will be able to handle this situation
task._setstate(Task.WAITING, force=True)
raise WorkflowTaskExecException(task, 'Error during script execution')
super(ScriptTask, self)._on_complete_hook(task)