Merge "Make currently implemented jobs use @functools.total_ordering"

This commit is contained in:
Jenkins
2015-07-24 06:38:02 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 3 deletions

View File

@@ -16,6 +16,7 @@
import contextlib
import datetime
import functools
import string
import threading
import time
@@ -58,6 +59,7 @@ def _translate_failures():
" internal error")
@functools.total_ordering
class RedisJob(base.Job):
"""A redis job."""
@@ -126,10 +128,24 @@ class RedisJob(base.Job):
prior_version=self._redis_version)
def __lt__(self, other):
if self.created_on == other.created_on:
return self.sequence < other.sequence
if not isinstance(other, RedisJob):
return NotImplemented
if self.board.listings_key == other.board.listings_key:
if self.created_on == other.created_on:
return self.sequence < other.sequence
else:
return self.created_on < other.created_on
else:
return self.created_on < other.created_on
return self.board.listings_key < other.board.listings_key
def __eq__(self, other):
if not isinstance(other, RedisJob):
return NotImplemented
return ((self.board.listings_key, self.created_on, self.sequence) ==
(other.board.listings_key, other.created_on, other.sequence))
def __hash__(self):
return hash((self.board.listings_key, self.created_on, self.sequence))
@property
def created_on(self):

View File

@@ -40,6 +40,7 @@ from taskflow.utils import misc
LOG = logging.getLogger(__name__)
@functools.total_ordering
class ZookeeperJob(base.Job):
"""A zookeeper job."""
@@ -170,11 +171,19 @@ class ZookeeperJob(base.Job):
return states.CLAIMED
def __lt__(self, other):
if not isinstance(other, ZookeeperJob):
return NotImplemented
if self.root == other.root:
return self.sequence < other.sequence
else:
return self.root < other.root
def __eq__(self, other):
if not isinstance(other, ZookeeperJob):
return NotImplemented
return ((self.root, self.sequence) ==
(other.root, other.sequence))
def __hash__(self):
return hash(self.path)