From e6c32edad9da044b66deb9d9a612f4acb02e2090 Mon Sep 17 00:00:00 2001 From: Mark LaPerriere Date: Fri, 19 Dec 2014 14:17:17 -0500 Subject: [PATCH] add birth_date and death_date properties to Worker --- rq/worker.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rq/worker.py b/rq/worker.py index 7283d56..73347c7 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -21,7 +21,7 @@ from .job import Job, Status from .logutils import setup_loghandlers from .queue import get_failed_queue, Queue from .timeouts import UnixSignalDeathPenalty -from .utils import import_attribute, make_colorizer, utcformat, utcnow +from .utils import import_attribute, make_colorizer, utcformat, utcnow, utcparse from .version import VERSION from .registry import FinishedJobRegistry, StartedJobRegistry @@ -235,6 +235,21 @@ class Worker(object): p.expire(self.key, 60) p.execute() + @property + def birth_date(self): + """Fetches birth date from Redis.""" + birth_timestamp = self.connection.hget(self.key, 'birth') + if birth_timestamp: + return utcparse(birth_timestamp) + + @property + def death_date(self): + """Fetches death date from Redis.""" + death_timestamp = self.connection.hget(self.key, 'death') + if death_timestamp: + return utcparse(death_timestamp) + + def set_state(self, state, pipeline=None): self._state = state connection = pipeline if pipeline is not None else self.connection