From 5a3bebf85b9196d7fcf6cce656aa4dcc1728a953 Mon Sep 17 00:00:00 2001 From: glaslos Date: Fri, 6 Nov 2015 11:08:13 +0100 Subject: [PATCH 1/3] only remove from queue on job.cancel --- rq/job.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rq/job.py b/rq/job.py index e8080f8..f975d9a 100644 --- a/rq/job.py +++ b/rq/job.py @@ -467,9 +467,6 @@ class Job(object): """ from .queue import Queue pipeline = self.connection._pipeline() - self.delete(pipeline=pipeline) - pipeline.delete(self.dependents_key) - if self.origin: queue = Queue(name=self.origin, connection=self.connection) queue.remove(self, pipeline=pipeline) From d2eeb3b3db3dcb93f3a6108dbe1bc07e68c78d34 Mon Sep 17 00:00:00 2001 From: glaslos Date: Fri, 6 Nov 2015 11:20:41 +0100 Subject: [PATCH 2/3] job.cancel before delete and doc string fixes --- rq/job.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rq/job.py b/rq/job.py index e5e7038..d083185 100644 --- a/rq/job.py +++ b/rq/job.py @@ -467,8 +467,7 @@ class Job(object): This method merely exists as a high-level API call to cancel jobs without worrying about the internals required to implement job - cancellation. Technically, this call is (currently) the same as just - deleting the job hash. + cancellation. """ from .queue import Queue pipeline = self.connection._pipeline() @@ -478,7 +477,8 @@ class Job(object): pipeline.execute() def delete(self, pipeline=None): - """Deletes the job hash from Redis.""" + """Cancels the job and deletes the job hash from Redis.""" + self.cancel() connection = pipeline if pipeline is not None else self.connection connection.delete(self.key) From 0a6df13d9d39940df7b99292e45c46c5eae45f29 Mon Sep 17 00:00:00 2001 From: glaslos Date: Fri, 6 Nov 2015 11:32:43 +0100 Subject: [PATCH 3/3] delete dependents and delete in cleanup. Fixed tests. --- rq/job.py | 3 ++- tests/test_job.py | 6 +++--- tests/test_queue.py | 4 +--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/rq/job.py b/rq/job.py index d083185..b45ed28 100644 --- a/rq/job.py +++ b/rq/job.py @@ -481,6 +481,7 @@ class Job(object): self.cancel() connection = pipeline if pipeline is not None else self.connection connection.delete(self.key) + connection.delete(self.dependents_key) # Job execution def perform(self): # noqa @@ -535,7 +536,7 @@ class Job(object): forever) """ if ttl == 0: - self.cancel() + self.delete() elif not ttl: return elif ttl > 0: diff --git a/tests/test_job.py b/tests/test_job.py index 4a57e6e..fd714f1 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -378,13 +378,13 @@ class TestJob(RQTestCase): self.assertEqual(as_text(self.testconn.spop('rq:job:id:dependents')), job.id) self.assertEqual(registry.get_job_ids(), [job.id]) - def test_cancel(self): - """job.cancel() deletes itself & dependents mapping from Redis.""" + def test_delete(self): + """job.delete() deletes itself & dependents mapping from Redis.""" queue = Queue(connection=self.testconn) job = queue.enqueue(fixtures.say_hello) job2 = Job.create(func=fixtures.say_hello, depends_on=job) job2.register_dependency() - job.cancel() + job.delete() self.assertFalse(self.testconn.exists(job.key)) self.assertFalse(self.testconn.exists(job.dependents_key)) diff --git a/tests/test_queue.py b/tests/test_queue.py index 5d87ddf..f764849 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -88,10 +88,8 @@ class TestQueue(RQTestCase): job = q.enqueue(say_hello) self.assertEqual(q.jobs, [job]) - # Fetching a deleted removes it from queue + # Deleting job removes it from queue job.delete() - self.assertEqual(q.job_ids, [job.id]) - q.jobs self.assertEqual(q.job_ids, []) def test_compact(self):