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
|
|
|
import eventlet |
19
|
|
|
import traceback |
20
|
|
|
|
21
|
|
|
from st2actions.workflows import workflows |
22
|
|
|
from st2common.models.db import workflow as wf_ex_db |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
__all__ = [ |
26
|
|
|
'MockWorkflowExecutionPublisher' |
27
|
|
|
] |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class MockWorkflowExecutionPublisher(object): |
31
|
|
|
|
32
|
|
|
@classmethod |
33
|
|
|
def publish_create(cls, payload): |
34
|
|
|
try: |
35
|
|
|
if isinstance(payload, wf_ex_db.WorkflowExecutionDB): |
36
|
|
|
workflows.get_engine().process(payload) |
37
|
|
|
except Exception: |
38
|
|
|
traceback.print_exc() |
39
|
|
|
print(payload) |
40
|
|
|
|
41
|
|
|
@classmethod |
42
|
|
|
def publish_state(cls, payload, state): |
43
|
|
|
try: |
44
|
|
|
if isinstance(payload, wf_ex_db.WorkflowExecutionDB): |
45
|
|
|
workflows.get_engine().process(payload) |
46
|
|
|
except Exception: |
47
|
|
|
traceback.print_exc() |
48
|
|
|
print(payload) |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
class MockWorkflowExecutionPublisherNonBlocking(object): |
52
|
|
|
threads = [] |
53
|
|
|
|
54
|
|
|
@classmethod |
55
|
|
|
def publish_create(cls, payload): |
56
|
|
|
try: |
57
|
|
|
if isinstance(payload, wf_ex_db.WorkflowExecutionDB): |
58
|
|
|
thread = eventlet.spawn(workflows.get_engine().process, payload) |
59
|
|
|
cls.threads.append(thread) |
60
|
|
|
except Exception: |
61
|
|
|
traceback.print_exc() |
62
|
|
|
print(payload) |
63
|
|
|
|
64
|
|
|
@classmethod |
65
|
|
|
def publish_state(cls, payload, state): |
66
|
|
|
try: |
67
|
|
|
if isinstance(payload, wf_ex_db.WorkflowExecutionDB): |
68
|
|
|
thread = eventlet.spawn(workflows.get_engine().process, payload) |
69
|
|
|
cls.threads.append(thread) |
70
|
|
|
except Exception: |
71
|
|
|
traceback.print_exc() |
72
|
|
|
print(payload) |
73
|
|
|
|
74
|
|
|
@classmethod |
75
|
|
|
def wait_all(cls): |
76
|
|
|
for thread in cls.threads: |
77
|
|
|
try: |
78
|
|
|
thread.wait() |
79
|
|
|
except Exception as e: |
80
|
|
|
print(str(e)) |
81
|
|
|
finally: |
82
|
|
|
cls.threads.remove(thread) |
83
|
|
|
|