From ec0e04727bb79ace3894ab084fa7293206fe98d7 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Wed, 3 Jun 2015 10:13:38 +0200 Subject: [PATCH] Rename `maintenance_date` -> `last_cleaned_at` --- rq/worker.py | 8 ++++---- tests/test_worker.py | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rq/worker.py b/rq/worker.py index dc9ce00..3221da2 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -149,7 +149,7 @@ class Worker(object): self._stopped = False self.log = logger self.failed_queue = get_failed_queue(connection=self.connection) - self.maintenance_date = None + self.last_cleaned_at = None # By default, push the "move-to-failed-queue" exception handler onto # the stack @@ -653,14 +653,14 @@ class Worker(object): """Runs maintenance jobs on each Queue's registries.""" for queue in self.queues: clean_registries(queue) - self.maintenance_date = utcnow() + self.last_cleaned_at = utcnow() @property def should_run_maintenance_tasks(self): """Maintenance tasks should run on first startup or every hour.""" - if self.maintenance_date is None: + if self.last_cleaned_at is None: return True - if (utcnow() - self.maintenance_date) > timedelta(seconds=3600): + if (utcnow() - self.last_cleaned_at) > timedelta(hours=1): return True return False diff --git a/tests/test_worker.py b/tests/test_worker.py index 016f83c..02dacb7 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -430,7 +430,7 @@ class TestWorker(RQTestCase): self.assertEquals(type(death_date).__name__, 'datetime') def test_clean_queue_registries(self): - """worker.clean_registries sets maintenance_date and cleans registries.""" + """worker.clean_registries sets last_cleaned_at and cleans registries.""" foo_queue = Queue('foo', connection=self.testconn) foo_registry = StartedJobRegistry('foo', connection=self.testconn) self.testconn.zadd(foo_registry.key, 1, 'foo') @@ -442,9 +442,9 @@ class TestWorker(RQTestCase): self.assertEqual(self.testconn.zcard(bar_registry.key), 1) worker = Worker([foo_queue, bar_queue]) - self.assertEqual(worker.maintenance_date, None) + self.assertEqual(worker.last_cleaned_at, None) worker.clean_registries() - self.assertNotEqual(worker.maintenance_date, None) + self.assertNotEqual(worker.last_cleaned_at, None) self.assertEqual(self.testconn.zcard(foo_registry.key), 0) self.assertEqual(self.testconn.zcard(bar_registry.key), 0) @@ -454,9 +454,9 @@ class TestWorker(RQTestCase): worker = Worker(queue) self.assertTrue(worker.should_run_maintenance_tasks) - worker.maintenance_date = utcnow() + worker.last_cleaned_at = utcnow() self.assertFalse(worker.should_run_maintenance_tasks) - worker.maintenance_date = utcnow() - timedelta(seconds=3700) + worker.last_cleaned_at = utcnow() - timedelta(seconds=3700) self.assertTrue(worker.should_run_maintenance_tasks) def test_worker_calls_clean_registries(self):