Merge "Make currently implemented jobs use @functools.total_ordering"
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user