Debian Codegraph @

taskflow/engines/action_engine/actions/base.py

raw
1 # Copyright (C) 2015 Yahoo! Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import abc
16
17 from taskflow import states
18
19
20 class Action(metaclass=abc.ABCMeta):
21 """An action that handles executing, state changes, ... of atoms."""
22
23 NO_RESULT = object()
24 """
25 Sentinel use to represent lack of any result (none can be a valid result)
26 """
27
28 #: States that are expected to have a result to save...
29 SAVE_RESULT_STATES = (states.SUCCESS, states.FAILURE,
30 states.REVERTED, states.REVERT_FAILURE)
31
32 def __init__(self, storage, notifier):
33 self._storage = storage
34 self._notifier = notifier
35
36 @abc.abstractmethod
37 def schedule_execution(self, atom):
38 """Schedules atom execution."""
39
40 @abc.abstractmethod
41 def schedule_reversion(self, atom):
42 """Schedules atom reversion."""
43
44 @abc.abstractmethod
45 def complete_reversion(self, atom, result):
46 """Completes atom reversion."""
47
48 @abc.abstractmethod
49 def complete_execution(self, atom, result):
50 """Completes atom execution."""