Merge pull request #707 from jlopex/javi/cancel_on_failed_queue

Fix Job.cancel() method on failed queue
main
Selwin Ong 9 years ago
commit cc5b3c1e64

@ -473,11 +473,13 @@ class Job(object):
without worrying about the internals required to implement job without worrying about the internals required to implement job
cancellation. cancellation.
""" """
from .queue import Queue from .queue import Queue, get_failed_queue
pipeline = self.connection._pipeline() pipeline = self.connection._pipeline()
if self.origin: if self.origin:
queue = Queue(name=self.origin, connection=self.connection) q = (get_failed_queue(connection=self.connection)
queue.remove(self, pipeline=pipeline) if self.is_failed
else Queue(name=self.origin, connection=self.connection))
q.remove(self, pipeline=pipeline)
pipeline.execute() pipeline.execute()
def delete(self, pipeline=None, remove_from_queue=True): def delete(self, pipeline=None, remove_from_queue=True):

@ -11,7 +11,7 @@ from tests.helpers import strip_microseconds
from rq.compat import PY2, as_text from rq.compat import PY2, as_text
from rq.exceptions import NoSuchJobError, UnpickleError from rq.exceptions import NoSuchJobError, UnpickleError
from rq.job import Job, get_current_job, JobStatus, cancel_job from rq.job import Job, get_current_job, JobStatus, cancel_job
from rq.queue import Queue from rq.queue import Queue, get_failed_queue
from rq.registry import DeferredJobRegistry from rq.registry import DeferredJobRegistry
from rq.utils import utcformat from rq.utils import utcformat
from rq.worker import Worker from rq.worker import Worker
@ -435,3 +435,12 @@ class TestJob(RQTestCase):
self.assertEqual(1, len(queue.get_jobs())) self.assertEqual(1, len(queue.get_jobs()))
cancel_job(job.id) cancel_job(job.id)
self.assertEqual(0, len(queue.get_jobs())) self.assertEqual(0, len(queue.get_jobs()))
def test_create_failed_and_cancel_job(self):
"""test creating and using cancel_job deletes job properly"""
failed = get_failed_queue(connection=self.testconn)
job = failed.enqueue(fixtures.say_hello)
job.set_status(JobStatus.FAILED)
self.assertEqual(1, len(failed.get_jobs()))
cancel_job(job.id)
self.assertEqual(0, len(failed.get_jobs()))

Loading…
Cancel
Save