summaryrefslogtreecommitdiff
path: root/taskflow/persistence
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-06-11 14:38:34 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-06-19 14:01:04 -0700
commit23a62fef9fb7f67467aaa714257be7fa451364c4 (patch)
tree2c6b21ec828549630fa760d31ca97ba716a2876a /taskflow/persistence
parent4c36d389997606c1c5d38dcff42302fd6b9dd479 (diff)
downloadtaskflow-23a62fef9fb7f67467aaa714257be7fa451364c4.tar.gz
Perform a few optimizations to decrease persistence interactions
To reduce the amount of *unneeded* persistence backend interactions we can optimize a few cases to avoid saving anything when nothing has changed; this should help in a few cases, and is easy low hanging fruit. Part of blueprint make-things-speedy Change-Id: I4fe958c94ef308919395345fd5c0d85f181446fb
Diffstat (limited to 'taskflow/persistence')
-rw-r--r--taskflow/persistence/logbook.py40
1 files changed, 29 insertions, 11 deletions
diff --git a/taskflow/persistence/logbook.py b/taskflow/persistence/logbook.py
index be254ea1..c7a6eae 100644
--- a/taskflow/persistence/logbook.py
+++ b/taskflow/persistence/logbook.py
@@ -52,10 +52,6 @@ def _safe_unmarshal_time(when):
return timeutils.unmarshall_time(when)
-def _was_failure(state, result):
- return state == states.FAILURE and isinstance(result, ft.Failure)
-
-
def _fix_meta(data):
# Handle the case where older schemas allowed this to be non-dict by
# correcting this case by replacing it with a dictionary when a non-dict
@@ -434,6 +430,11 @@ class AtomDetail(object):
self.meta = {}
self.version = None
+ @staticmethod
+ def _was_failure(state, result):
+ # Internal helper method...
+ return state == states.FAILURE and isinstance(result, ft.Failure)
+
@property
def last_results(self):
"""Gets the atoms last result.
@@ -601,13 +602,29 @@ class TaskDetail(AtomDetail):
will be set to ``None``). In either case the ``state``
attribute will be set to the provided state.
"""
- self.state = state
- if _was_failure(state, result):
- self.failure = result
- self.results = None
+ was_altered = False
+ if self.state != state:
+ self.state = state
+ was_altered = True
+ if self._was_failure(state, result):
+ if self.failure != result:
+ self.failure = result
+ was_altered = True
+ if self.results is not None:
+ self.results = None
+ was_altered = True
else:
- self.results = result
- self.failure = None
+ # We don't really have the ability to determine equality of
+ # task (user) results at the current time, without making
+ # potentially bad guesses, so assume the task detail always needs
+ # to be saved if they are not exactly equivalent...
+ if self.results is not result:
+ self.results = result
+ was_altered = True
+ if self.failure is not None:
+ self.failure = None
+ was_altered = True
+ return was_altered
def merge(self, other, deep_copy=False):
"""Merges the current task detail with the given one.
@@ -763,11 +780,12 @@ class RetryDetail(AtomDetail):
"""
# Do not clean retry history (only on reset does this happen).
self.state = state
- if _was_failure(state, result):
+ if self._was_failure(state, result):
self.failure = result
else:
self.results.append((result, {}))
self.failure = None
+ return True
@classmethod
def from_dict(cls, data):