From c6a83eaa824bc8cd4459356afd1569b2ef7f95f7 Mon Sep 17 00:00:00 2001 From: glaslos Date: Mon, 1 Dec 2014 11:37:54 +0100 Subject: [PATCH] calling self.cleanup to set job expiration --- rq/job.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/rq/job.py b/rq/job.py index 865ca30..8067a01 100644 --- a/rq/job.py +++ b/rq/job.py @@ -457,8 +457,7 @@ class Job(object): connection = pipeline if pipeline is not None else self.connection connection.hmset(key, self.to_dict()) - if self.ttl: - connection.expire(key, self.ttl) + self.cleanup(self.ttl) def cancel(self): """Cancels the given job, which will prevent the job from ever being @@ -524,14 +523,16 @@ class Job(object): def cleanup(self, ttl=None, pipeline=None): """Prepare job for eventual deletion (if needed). This method is usually called after successful execution. How long we persist the job and its - result depends on the value of result_ttl: - - If result_ttl is 0, cleanup the job immediately. + result depends on the value of ttl: + - If ttl is 0, cleanup the job immediately. - If it's a positive number, set the job to expire in X seconds. - - If result_ttl is negative, don't set an expiry to it (persist + - If ttl is negative, don't set an expiry to it (persist forever) """ if ttl == 0: self.cancel() + elif not ttl: + return elif ttl > 0: connection = pipeline if pipeline is not None else self.connection connection.expire(self.key, ttl)