From 70cbf00890fe186164d7273c171503277e9acbd3 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 14 Feb 2012 22:52:44 +0100 Subject: [PATCH] Refactor out an exists() and a for_key() method. --- rq/job.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rq/job.py b/rq/job.py index 11d45a4..4fb7355 100644 --- a/rq/job.py +++ b/rq/job.py @@ -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.