|
|
@ -1,5 +1,5 @@
|
|
|
|
from tests import RQTestCase
|
|
|
|
from tests import RQTestCase
|
|
|
|
from tests import testjob, failing_job
|
|
|
|
from tests.fixtures import say_hello, div_by_zero
|
|
|
|
from rq import Queue, FailedQueue, Job
|
|
|
|
from rq import Queue, FailedQueue, Job
|
|
|
|
from rq.exceptions import InvalidJobOperationError
|
|
|
|
from rq.exceptions import InvalidJobOperationError
|
|
|
|
|
|
|
|
|
|
|
@ -53,10 +53,10 @@ class TestQueue(RQTestCase):
|
|
|
|
"""Compacting queueus."""
|
|
|
|
"""Compacting queueus."""
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
|
|
|
|
|
|
|
|
q.enqueue(testjob, 'Alice')
|
|
|
|
q.enqueue(say_hello, 'Alice')
|
|
|
|
bob = q.enqueue(testjob, 'Bob')
|
|
|
|
bob = q.enqueue(say_hello, 'Bob')
|
|
|
|
q.enqueue(testjob, 'Charlie')
|
|
|
|
q.enqueue(say_hello, 'Charlie')
|
|
|
|
debrah = q.enqueue(testjob, 'Debrah')
|
|
|
|
debrah = q.enqueue(say_hello, 'Debrah')
|
|
|
|
|
|
|
|
|
|
|
|
bob.cancel()
|
|
|
|
bob.cancel()
|
|
|
|
debrah.cancel()
|
|
|
|
debrah.cancel()
|
|
|
@ -73,8 +73,8 @@ class TestQueue(RQTestCase):
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
self.assertEquals(q.is_empty(), True)
|
|
|
|
self.assertEquals(q.is_empty(), True)
|
|
|
|
|
|
|
|
|
|
|
|
# testjob spec holds which queue this is sent to
|
|
|
|
# say_hello spec holds which queue this is sent to
|
|
|
|
job = q.enqueue(testjob, 'Nick', foo='bar')
|
|
|
|
job = q.enqueue(say_hello, 'Nick', foo='bar')
|
|
|
|
job_id = job.id
|
|
|
|
job_id = job.id
|
|
|
|
|
|
|
|
|
|
|
|
# Inspect data inside Redis
|
|
|
|
# Inspect data inside Redis
|
|
|
@ -85,7 +85,7 @@ class TestQueue(RQTestCase):
|
|
|
|
def test_enqueue_sets_metadata(self):
|
|
|
|
def test_enqueue_sets_metadata(self):
|
|
|
|
"""Enqueueing job onto queues modifies meta data."""
|
|
|
|
"""Enqueueing job onto queues modifies meta data."""
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
job = Job.create(testjob, 'Nick', foo='bar')
|
|
|
|
job = Job.create(say_hello, 'Nick', foo='bar')
|
|
|
|
|
|
|
|
|
|
|
|
# Preconditions
|
|
|
|
# Preconditions
|
|
|
|
self.assertIsNone(job.origin)
|
|
|
|
self.assertIsNone(job.origin)
|
|
|
@ -117,13 +117,13 @@ class TestQueue(RQTestCase):
|
|
|
|
"""Dequeueing jobs from queues."""
|
|
|
|
"""Dequeueing jobs from queues."""
|
|
|
|
# Set up
|
|
|
|
# Set up
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
result = q.enqueue(testjob, 'Rick', foo='bar')
|
|
|
|
result = q.enqueue(say_hello, 'Rick', foo='bar')
|
|
|
|
|
|
|
|
|
|
|
|
# Dequeue a job (not a job ID) off the queue
|
|
|
|
# Dequeue a job (not a job ID) off the queue
|
|
|
|
self.assertEquals(q.count, 1)
|
|
|
|
self.assertEquals(q.count, 1)
|
|
|
|
job = q.dequeue()
|
|
|
|
job = q.dequeue()
|
|
|
|
self.assertEquals(job.id, result.id)
|
|
|
|
self.assertEquals(job.id, result.id)
|
|
|
|
self.assertEquals(job.func, testjob)
|
|
|
|
self.assertEquals(job.func, say_hello)
|
|
|
|
self.assertEquals(job.origin, q.name)
|
|
|
|
self.assertEquals(job.origin, q.name)
|
|
|
|
self.assertEquals(job.args[0], 'Rick')
|
|
|
|
self.assertEquals(job.args[0], 'Rick')
|
|
|
|
self.assertEquals(job.kwargs['foo'], 'bar')
|
|
|
|
self.assertEquals(job.kwargs['foo'], 'bar')
|
|
|
@ -138,7 +138,7 @@ class TestQueue(RQTestCase):
|
|
|
|
uuid = '49f205ab-8ea3-47dd-a1b5-bfa186870fc8'
|
|
|
|
uuid = '49f205ab-8ea3-47dd-a1b5-bfa186870fc8'
|
|
|
|
q.push_job_id(uuid)
|
|
|
|
q.push_job_id(uuid)
|
|
|
|
q.push_job_id(uuid)
|
|
|
|
q.push_job_id(uuid)
|
|
|
|
result = q.enqueue(testjob, 'Nick', foo='bar')
|
|
|
|
result = q.enqueue(say_hello, 'Nick', foo='bar')
|
|
|
|
q.push_job_id(uuid)
|
|
|
|
q.push_job_id(uuid)
|
|
|
|
|
|
|
|
|
|
|
|
# Dequeue simply ignores the missing job and returns None
|
|
|
|
# Dequeue simply ignores the missing job and returns None
|
|
|
@ -155,25 +155,25 @@ class TestQueue(RQTestCase):
|
|
|
|
self.assertEquals(Queue.dequeue_any([fooq, barq], False), None)
|
|
|
|
self.assertEquals(Queue.dequeue_any([fooq, barq], False), None)
|
|
|
|
|
|
|
|
|
|
|
|
# Enqueue a single item
|
|
|
|
# Enqueue a single item
|
|
|
|
barq.enqueue(testjob)
|
|
|
|
barq.enqueue(say_hello)
|
|
|
|
job, queue = Queue.dequeue_any([fooq, barq], False)
|
|
|
|
job, queue = Queue.dequeue_any([fooq, barq], False)
|
|
|
|
self.assertEquals(job.func, testjob)
|
|
|
|
self.assertEquals(job.func, say_hello)
|
|
|
|
self.assertEquals(queue, barq)
|
|
|
|
self.assertEquals(queue, barq)
|
|
|
|
|
|
|
|
|
|
|
|
# Enqueue items on both queues
|
|
|
|
# Enqueue items on both queues
|
|
|
|
barq.enqueue(testjob, 'for Bar')
|
|
|
|
barq.enqueue(say_hello, 'for Bar')
|
|
|
|
fooq.enqueue(testjob, 'for Foo')
|
|
|
|
fooq.enqueue(say_hello, 'for Foo')
|
|
|
|
|
|
|
|
|
|
|
|
job, queue = Queue.dequeue_any([fooq, barq], False)
|
|
|
|
job, queue = Queue.dequeue_any([fooq, barq], False)
|
|
|
|
self.assertEquals(queue, fooq)
|
|
|
|
self.assertEquals(queue, fooq)
|
|
|
|
self.assertEquals(job.func, testjob)
|
|
|
|
self.assertEquals(job.func, say_hello)
|
|
|
|
self.assertEquals(job.origin, fooq.name)
|
|
|
|
self.assertEquals(job.origin, fooq.name)
|
|
|
|
self.assertEquals(job.args[0], 'for Foo',
|
|
|
|
self.assertEquals(job.args[0], 'for Foo',
|
|
|
|
'Foo should be dequeued first.')
|
|
|
|
'Foo should be dequeued first.')
|
|
|
|
|
|
|
|
|
|
|
|
job, queue = Queue.dequeue_any([fooq, barq], False)
|
|
|
|
job, queue = Queue.dequeue_any([fooq, barq], False)
|
|
|
|
self.assertEquals(queue, barq)
|
|
|
|
self.assertEquals(queue, barq)
|
|
|
|
self.assertEquals(job.func, testjob)
|
|
|
|
self.assertEquals(job.func, say_hello)
|
|
|
|
self.assertEquals(job.origin, barq.name)
|
|
|
|
self.assertEquals(job.origin, barq.name)
|
|
|
|
self.assertEquals(job.args[0], 'for Bar',
|
|
|
|
self.assertEquals(job.args[0], 'for Bar',
|
|
|
|
'Bar should be dequeued second.')
|
|
|
|
'Bar should be dequeued second.')
|
|
|
@ -195,7 +195,7 @@ class TestQueue(RQTestCase):
|
|
|
|
class TestFailedQueue(RQTestCase):
|
|
|
|
class TestFailedQueue(RQTestCase):
|
|
|
|
def test_requeue_job(self):
|
|
|
|
def test_requeue_job(self):
|
|
|
|
"""Requeueing existing jobs."""
|
|
|
|
"""Requeueing existing jobs."""
|
|
|
|
job = Job.create(failing_job, 1, 2, 3)
|
|
|
|
job = Job.create(div_by_zero, 1, 2, 3)
|
|
|
|
job.origin = 'fake'
|
|
|
|
job.origin = 'fake'
|
|
|
|
job.save()
|
|
|
|
job.save()
|
|
|
|
FailedQueue().quarantine(job, Exception('Some fake error'))
|
|
|
|
FailedQueue().quarantine(job, Exception('Some fake error'))
|
|
|
@ -211,7 +211,7 @@ class TestFailedQueue(RQTestCase):
|
|
|
|
def test_requeue_nonfailed_job_fails(self):
|
|
|
|
def test_requeue_nonfailed_job_fails(self):
|
|
|
|
"""Requeueing non-failed jobs raises error."""
|
|
|
|
"""Requeueing non-failed jobs raises error."""
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
job = q.enqueue(testjob, 'Nick', foo='bar')
|
|
|
|
job = q.enqueue(say_hello, 'Nick', foo='bar')
|
|
|
|
|
|
|
|
|
|
|
|
# Assert that we cannot requeue a job that's not on the failed queue
|
|
|
|
# Assert that we cannot requeue a job that's not on the failed queue
|
|
|
|
with self.assertRaises(InvalidJobOperationError):
|
|
|
|
with self.assertRaises(InvalidJobOperationError):
|
|
|
|