Merge pull request #701 from jlopex/javi/fix_issue_700

Fixes issue #700
main
Selwin Ong 9 years ago
commit 8b7b0e5584

@ -58,7 +58,7 @@ def cancel_job(job_id, connection=None):
"""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, connection=connection).cancel()
Job.fetch(job_id, connection=connection).cancel()
def requeue_job(job_id, connection=None):

@ -10,7 +10,7 @@ from tests.helpers import strip_microseconds
from rq.compat import PY2, as_text
from rq.exceptions import NoSuchJobError, UnpickleError
from rq.job import Job, get_current_job, JobStatus
from rq.job import Job, get_current_job, JobStatus, cancel_job
from rq.queue import Queue
from rq.registry import DeferredJobRegistry
from rq.utils import utcformat
@ -427,3 +427,11 @@ class TestJob(RQTestCase):
queue.enqueue(fixtures.say_hello, job_id="1234", ttl=1)
time.sleep(1)
self.assertEqual(0, len(queue.get_jobs()))
def test_create_and_cancel_job(self):
"""test creating and using cancel_job deletes job properly"""
queue = Queue(connection=self.testconn)
job = queue.enqueue(fixtures.say_hello)
self.assertEqual(1, len(queue.get_jobs()))
cancel_job(job.id)
self.assertEqual(0, len(queue.get_jobs()))

Loading…
Cancel
Save