From 8aa577164676dff8f218d6be84e29d6d2a8e4714 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Mon, 23 Sep 2013 17:34:43 +0700 Subject: [PATCH 1/2] job.cancel() now deletes dependents_key --- rq/job.py | 2 +- tests/test_job.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rq/job.py b/rq/job.py index a50d24a..5979255 100644 --- a/rq/job.py +++ b/rq/job.py @@ -371,12 +371,12 @@ class Job(object): deleting the job hash. """ self.delete() + self.connection.delete(self.dependents_key) def delete(self): """Deletes the job hash from Redis.""" self.connection.delete(self.key) - # Job execution def perform(self): # noqa """Invokes the job function with the job arguments.""" diff --git a/tests/test_job.py b/tests/test_job.py index 6b01d30..e3bdd21 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -290,3 +290,14 @@ class TestJob(RQTestCase): job.save() job.register_dependency() self.assertEqual(as_text(self.testconn.spop('rq:job:id:dependents')), job.id) + + def test_cancel(self): + """job.cancel() deletes itself & dependents mapping from Redis.""" + job = Job.create(func=say_hello) + job_key = job.key + dependents_key = job.dependents_key + job2 = Job.create(func=say_hello, depends_on=job) + job2.register_dependency() + job.cancel() + self.assertFalse(self.testconn.exists(job.key)) + self.assertFalse(self.testconn.exists(job.dependents_key)) From b997fb45bf3b690b3ea018e68710a311800b11ea Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Mon, 23 Sep 2013 17:35:59 +0700 Subject: [PATCH 2/2] Removed unnecessary lines from test_job.py. --- tests/test_job.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_job.py b/tests/test_job.py index e3bdd21..ac7f85d 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -294,8 +294,6 @@ class TestJob(RQTestCase): def test_cancel(self): """job.cancel() deletes itself & dependents mapping from Redis.""" job = Job.create(func=say_hello) - job_key = job.key - dependents_key = job.dependents_key job2 = Job.create(func=say_hello, depends_on=job) job2.register_dependency() job.cancel()