Skip to content

Commit

Permalink
ScriptTask should allow for handling script execution errors
Browse files Browse the repository at this point in the history
* caught exceptions are turned into WorkflowTaskExecException pointing to failed task
* task state is set to WAITING - we do not want it to stay marked as COMPLETED
  • Loading branch information
demostenes authored and Krzysztof Boguś committed Jun 18, 2017
1 parent 015a0ef commit 740998c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion SpiffWorkflow/bpmn/specs/ScriptTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
# 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):
Expand All @@ -40,5 +45,13 @@ def _on_complete_hook(self, task):
if task.workflow._is_busy_with_restore():
return
assert not task.workflow.read_only
task.workflow.script_engine.execute(task, self.script)
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)

0 comments on commit 740998c

Please sign in to comment.