diff options
| author | Joshua Harlow <harlowja@gmail.com> | 2015-02-17 21:39:48 -0800 |
|---|---|---|
| committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2015-02-19 17:07:03 -0800 |
| commit | 37b72ec7b5333b580d842b4e4dc6f1dacdc351b5 (patch) | |
| tree | 5cbfe49fd501991403aa62ddfa22a4ae999b5493 /taskflow/utils | |
| parent | f874b396b7e32c22421e94c51c13002b65341e48 (diff) | |
| download | taskflow-37b72ec7b5333b580d842b4e4dc6f1dacdc351b5.tar.gz | |
Use the enum library for the retry strategy enumerations
Instead of having a set of string constants that are the
retry strategy/decision result have it instead be an enumerator
that can be more clearly associated in docs and in code that
these values are explicitly the strategies that the retry
code can use (making it more obvious to users of these constants
what they are for).
This also updates the retry docs to use this new linkable
class when describing the various strategies that can be
used/returned.
Change-Id: I944e521562be26f5315d7553da8d5820fc284c49
Diffstat (limited to 'taskflow/utils')
| -rw-r--r-- | taskflow/utils/misc.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/taskflow/utils/misc.py b/taskflow/utils/misc.py index b2e967d..daac385 100644 --- a/taskflow/utils/misc.py +++ b/taskflow/utils/misc.py @@ -26,6 +26,7 @@ import threading import time import types +import enum from oslo_serialization import jsonutils from oslo_utils import importutils from oslo_utils import netutils @@ -57,6 +58,17 @@ _MONOTONIC_LOCATIONS = tuple([ ]) +class StrEnum(str, enum.Enum): + """An enumeration that is also a string and can be compared to strings.""" + + def __new__(cls, *args, **kwargs): + for a in args: + if not isinstance(a, str): + raise TypeError("Enumeration '%s' (%s) is not" + " a string" % (a, type(a).__name__)) + return super(StrEnum, cls).__new__(cls, *args, **kwargs) + + def find_monotonic(allow_time_time=False): """Tries to find a monotonic time providing function (and returns it).""" for import_str in _MONOTONIC_LOCATIONS: |
