Skip to content

Commit

Permalink
Don't expose the Job class at the top-level.
Browse files Browse the repository at this point in the history
This partially fixes rq#37.
  • Loading branch information
nvie committed Mar 21, 2012
1 parent 0b837b4 commit 98ea29b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
7 changes: 5 additions & 2 deletions rq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from redis import Redis
from .proxy import conn
from .queue import Queue, FailedQueue
from .job import cancel_job, requeue_job
from .worker import Worker
from .job import Job
from .version import VERSION


Expand All @@ -20,5 +20,8 @@ def use_redis(redis=None):
raise TypeError('Argument redis should be a Redis instance.')
conn.push(redis)

__all__ = ['conn', 'Queue', 'FailedQueue', 'Worker', 'Job', 'use_redis']
__all__ = [
'conn', 'use_redis',
'Queue', 'FailedQueue', 'Worker',
'cancel_job', 'requeue_job']
__version__ = VERSION
15 changes: 15 additions & 0 deletions rq/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ def unpickle(pickled_string):
return obj


def cancel_job(job_id):
"""Cancels the job with the given job ID, preventing execution. Discards
any job info (i.e. it can't be requeued later).
"""
Job(job_id).cancel()


def requeue_job(job_id):
"""Requeues the job with the given job ID. The job ID should refer to
a failed job (i.e. it should be on the failed queue). If no such (failed)
job exists, a NoSuchJobError is raised.
"""
raise NotImplementedError('Go implement this')


class Job(object):
"""A Job is just a convenient datastructure to pass around job (meta) data.
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.fixtures import some_calculation, say_hello
from tests.helpers import strip_milliseconds
from cPickle import loads
from rq import Job
from rq.job import Job
from rq.exceptions import NoSuchJobError, UnpickleError


Expand Down
3 changes: 2 additions & 1 deletion tests/test_queue.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tests import RQTestCase
from tests.fixtures import say_hello, div_by_zero
from rq import Queue, FailedQueue, Job
from rq import Queue, FailedQueue
from rq.job import Job
from rq.exceptions import InvalidJobOperationError


Expand Down
3 changes: 2 additions & 1 deletion tests/test_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from tests.fixtures import say_hello, div_by_zero, do_nothing, create_file, \
create_file_after_timeout
from tests.helpers import strip_milliseconds
from rq import Queue, Worker, Job
from rq import Queue, Worker
from rq.job import Job


class TestWorker(RQTestCase):
Expand Down

0 comments on commit 98ea29b

Please sign in to comment.