diff --git a/rq/__init__.py b/rq/__init__.py index 3748cd3..7256ee6 100644 --- a/rq/__init__.py +++ b/rq/__init__.py @@ -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 @@ -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 diff --git a/rq/job.py b/rq/job.py index 7e70fb6..83617e3 100644 --- a/rq/job.py +++ b/rq/job.py @@ -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. """ diff --git a/tests/test_job.py b/tests/test_job.py index 59ba922..140bf70 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -4,7 +4,7 @@ from tests import RQTestCase 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 diff --git a/tests/test_queue.py b/tests/test_queue.py index 6ea2d95..1cf6b82 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -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 diff --git a/tests/test_worker.py b/tests/test_worker.py index 8a46ae5..02d2fdc 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -3,7 +3,8 @@ from tests import RQTestCase, slow 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):