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 logging |
19
|
|
|
|
20
|
|
|
from st2common.models.db.executionstate import ActionExecutionStateDB |
21
|
|
|
from st2common.persistence.executionstate import ActionExecutionState |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
LOG = logging.getLogger(__name__) |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
def setup_query(liveaction_id, runnertype_db, query_context): |
28
|
|
|
if not getattr(runnertype_db, 'query_module', None): |
29
|
|
|
raise Exception('The runner "%s" does not have a query module.' % runnertype_db.name) |
30
|
|
|
|
31
|
|
|
state_db = ActionExecutionStateDB( |
32
|
|
|
execution_id=liveaction_id, |
33
|
|
|
query_module=runnertype_db.query_module, |
34
|
|
|
query_context=query_context |
35
|
|
|
) |
36
|
|
|
|
37
|
|
|
ActionExecutionState.add_or_update(state_db) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
def remove_query(liveaction_id): |
41
|
|
|
state_db = ActionExecutionState.query(execution_id=liveaction_id) |
42
|
|
|
|
43
|
|
|
if not state_db: |
44
|
|
|
return False |
45
|
|
|
|
46
|
|
|
ActionExecutionState.delete(state_db, publish=False, dispatch_trigger=False) |
47
|
|
|
|
48
|
|
|
return True |
49
|
|
|
|