Refactor out an exists() and a for_key() method.

This commit is contained in:
Vincent Driessen 2012-02-14 22:52:44 +01:00
parent c49e564d3c
commit 70cbf00890
1 changed files with 13 additions and 2 deletions

View File

@ -49,6 +49,11 @@ class Job(object):
def kwargs(self):
return self._kwargs
@classmethod
def exists(cls, job_id):
"""Returns whether a job hash exists for the given job ID."""
return conn.exists(cls.key_for(job_id))
@classmethod
def fetch(cls, id):
"""Fetches a persisted job from its corresponding Redis key and
@ -87,10 +92,15 @@ class Job(object):
id = property(get_id, set_id)
@classmethod
def key_for(cls, job_id):
"""The Redis key that is used to store job hash under."""
return 'rq:job:%s' % (job_id,)
@property
def key(self):
"""The Redis key that is used to store job data under."""
return 'rq:job:%s' % (self.id,)
"""The Redis key that is used to store job hash under."""
return self.key_for(self.id)
@property # noqa
@ -194,6 +204,7 @@ class Job(object):
"""Deletes the job hash from Redis."""
conn.delete(self.key)
# Job execution
def perform(self): # noqa
"""Invokes the job function with the job arguments.