From a29661907484a638ac56ffc71b30c6a4e9ccc146 Mon Sep 17 00:00:00 2001 From: Sylvain Zimmer Date: Fri, 30 Aug 2013 01:44:46 +0200 Subject: [PATCH] Split Job.dump() and Job.save() --- rq/job.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rq/job.py b/rq/job.py index fdc4b57..274b631 100644 --- a/rq/job.py +++ b/rq/job.py @@ -291,11 +291,8 @@ class Job(object): self._status = as_text(obj.get('status') if obj.get('status') else None) self.meta = unpickle(obj.get('meta')) if obj.get('meta') else {} - def save(self, pipeline=None): - """Persists the current job instance to its corresponding Redis key.""" - key = self.key - connection = pipeline if pipeline is not None else self.connection - + def dump(self): + """Returns a serialization of the current job instance""" obj = {} obj['created_at'] = times.format(self.created_at or times.now(), 'UTC') @@ -322,7 +319,14 @@ class Job(object): if self.meta: obj['meta'] = dumps(self.meta) - connection.hmset(key, obj) + return obj + + def save(self, pipeline=None): + """Persists the current job instance to its corresponding Redis key.""" + key = self.key + connection = pipeline if pipeline is not None else self.connection + + connection.hmset(key, self.dump()) def cancel(self): """Cancels the given job, which will prevent the job from ever being @@ -379,13 +383,13 @@ class Job(object): - 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 forever) - """ + """ if ttl == 0: self.cancel() elif ttl > 0: connection = pipeline if pipeline is not None else self.connection connection.expire(self.key, ttl) - + def __str__(self): return '' % (self.id, self.description)