1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
from __future__ import absolute_import |
17
|
|
|
|
18
|
|
|
from st2common import exceptions as st2_exc |
19
|
|
|
from st2common.exceptions import db as db_exc |
20
|
|
|
from st2common import log as logging |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
LOG = logging.getLogger(__name__) |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
def retry_on_exceptions(exc): |
27
|
|
|
LOG.warning('Determining if exception %s should be retried.', type(exc)) |
28
|
|
|
|
29
|
|
|
retrying = isinstance(exc, db_exc.StackStormDBObjectWriteConflictError) |
30
|
|
|
|
31
|
|
|
if retrying: |
32
|
|
|
LOG.warning('Retrying operation due to database write conflict.') |
33
|
|
|
|
34
|
|
|
return retrying |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class WorkflowDefinitionException(st2_exc.StackStormBaseException): |
38
|
|
|
pass |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
class WorkflowExecutionNotFoundException(st2_exc.StackStormBaseException): |
42
|
|
|
|
43
|
|
|
def __init__(self, ac_ex_id): |
|
|
|
|
44
|
|
|
Exception.__init__( |
|
|
|
|
45
|
|
|
self, |
46
|
|
|
'Unable to identify any workflow execution that is ' |
47
|
|
|
'associated to action execution "%s".' % ac_ex_id |
48
|
|
|
) |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
class AmbiguousWorkflowExecutionException(st2_exc.StackStormBaseException): |
52
|
|
|
|
53
|
|
|
def __init__(self, ac_ex_id): |
|
|
|
|
54
|
|
|
Exception.__init__( |
|
|
|
|
55
|
|
|
self, |
56
|
|
|
'More than one workflow execution is associated ' |
57
|
|
|
'to action execution "%s".' % ac_ex_id |
58
|
|
|
) |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
class WorkflowExecutionIsCompletedException(st2_exc.StackStormBaseException): |
62
|
|
|
|
63
|
|
|
def __init__(self, wf_ex_id): |
|
|
|
|
64
|
|
|
Exception.__init__(self, 'Workflow execution "%s" is already completed.' % wf_ex_id) |
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
class WorkflowExecutionIsRunningException(st2_exc.StackStormBaseException): |
68
|
|
|
|
69
|
|
|
def __init__(self, wf_ex_id): |
|
|
|
|
70
|
|
|
Exception.__init__(self, 'Workflow execution "%s" is already active.' % wf_ex_id) |
|
|
|
|
71
|
|
|
|
It is generally advisable to initialize the super-class by calling its
__init__
method: