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))