Fixed an issue where `birth` not present in Redis (#901)

* Fixed an issue where `birth` not present in Redis

Fixed an issue where worker.refresh() may fail if `birth` is not present in Redis

* added test coverage
main
vanife 7 years ago committed by Selwin Ong
parent e5de3dfbb5
commit ff36e0656e

@ -544,7 +544,10 @@ class Worker(object):
self.last_heartbeat = utcparse(as_text(last_heartbeat))
else:
self.last_heartbeat = None
self.birth_date = utcparse(as_text(birth))
if birth:
self.birth_date = utcparse(as_text(birth))
else:
self.birth_date = None
if failed_job_count:
self.failed_job_count = int(as_text(failed_job_count))
if successful_job_count:

@ -202,8 +202,9 @@ class TestWorker(RQTestCase):
q = Queue()
w = Worker([q])
w.register_birth()
birth = self.testconn.hget(w.key, 'birth')
last_heartbeat = self.testconn.hget(w.key, 'last_heartbeat')
self.assertTrue(birth is not None)
self.assertTrue(last_heartbeat is not None)
w = Worker.find_by_key(w.key)
self.assertIsInstance(w.last_heartbeat, datetime)
@ -212,6 +213,10 @@ class TestWorker(RQTestCase):
# for compatibility reasons
self.testconn.hdel(w.key, 'last_heartbeat')
w.refresh()
# worker.refresh() shouldn't fail if birth is None
# for compatibility reasons
self.testconn.hdel(w.key, 'birth')
w.refresh()
def test_work_fails(self):
"""Failing jobs are put on the failed queue."""

Loading…
Cancel
Save