summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-02-07 06:17:22 +0000
committerGerrit Code Review <review@openstack.org>2015-02-07 06:17:22 +0000
commiteed0ef03580331d311f09dc871a71500d52d21c3 (patch)
tree06505c25ddaae1e5fb261ccb03160fd878b9f440
parentc1623d3dd333ffb65f264b6be947c4a4f5b41b22 (diff)
parentd0d112ddc9ba2aed4b81e6caaa3c713dc1eba76b (diff)
downloadtaskflow-eed0ef03580331d311f09dc871a71500d52d21c3.tar.gz
Merge "Add + use a staticmethod to fetch the immediate callables"
-rw-r--r--taskflow/types/periodic.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/taskflow/types/periodic.py b/taskflow/types/periodic.py
index 2717be0..f00d97e 100644
--- a/taskflow/types/periodic.py
+++ b/taskflow/types/periodic.py
@@ -108,20 +108,28 @@ class PeriodicWorker(object):
self._callables = tuple((cb, reflection.get_callable_name(cb))
for cb in almost_callables)
self._schedule = []
- self._immediates = []
now = _now()
for i, (cb, cb_name) in enumerate(self._callables):
spacing = cb._periodic_spacing
next_run = now + spacing
heapq.heappush(self._schedule, (next_run, i))
- for (cb, cb_name) in reversed(self._callables):
- if cb._periodic_run_immediately:
- self._immediates.append((cb, cb_name))
+ self._immediates = self._fetch_immediates(self._callables)
def __len__(self):
return len(self._callables)
@staticmethod
+ def _fetch_immediates(callables):
+ immediates = []
+ # Reverse order is used since these are later popped off (and to
+ # ensure the popping order is first -> last we need to append them
+ # in the opposite ordering last -> first).
+ for (cb, cb_name) in reversed(callables):
+ if cb._periodic_run_immediately:
+ immediates.append((cb, cb_name))
+ return immediates
+
+ @staticmethod
def _safe_call(cb, cb_name, kind='periodic'):
try:
cb()
@@ -173,7 +181,4 @@ class PeriodicWorker(object):
def reset(self):
"""Resets the tombstone and re-queues up any immediate executions."""
self._tombstone.clear()
- self._immediates = []
- for (cb, cb_name) in reversed(self._callables):
- if cb._periodic_run_immediately:
- self._immediates.append((cb, cb_name))
+ self._immediates = self._fetch_immediates(self._callables)