From c301369c2eb45a0969aa32384ddc7115458f5da1 Mon Sep 17 00:00:00 2001 From: Travis Johnson Date: Mon, 8 Dec 2014 18:17:55 -0500 Subject: [PATCH] implement __eq__ and __hash__ for workers --- rq/worker.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rq/worker.py b/rq/worker.py index bf40a65..d14bf88 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -580,6 +580,14 @@ class Worker(object): """Pops the latest exception handler off of the exc handler stack.""" return self._exc_handlers.pop() + def __eq__(self, other): + if not isinstance(other, self.__class__): + raise TypeError('Cannot compare workers to other types (of workers)') + return self.name == other.name + + def __hash__(self): + return hash(self.name) + class SimpleWorker(Worker): def _install_signal_handlers(self, *args, **kwargs):