Change semantics of work(). Add work_burst().

work() will now start the worker run loop, and work_burst() now leads to
the burst-then-quit behaviour.
main
Vincent Driessen 13 years ago
parent d761dd0280
commit d780c929c0

@ -51,7 +51,7 @@ with the following content:
from rq import Queue, Worker
q = Queue()
Worker(q).work_forever()
Worker(q).work()
After that, start a worker instance:
@ -66,12 +66,12 @@ them:
from rq import Queue, Worker
queues = map(Queue, ['high', 'normal', 'low'])
Worker(queues).work()
Worker(queues).work_burst()
Which will keep popping jobs from the given queues, giving precedence to the
`high` queue, then `normal`, etc. It will return when there are no more jobs
left (contrast this to the previous example using `Worker.work_forever()`,
which will never return since it keeps waiting for new work to arrive).
left (contrast this to the previous example using `Worker.work()`, which will
never return since it keeps waiting for new work to arrive).
# Installation

@ -7,4 +7,4 @@ conn.push(Redis())
if __name__ == '__main__':
q = Queue()
Worker(q).work_forever()
Worker(q).work()

@ -68,10 +68,10 @@ class Worker(object):
self.fork_and_perform_job(job)
return did_work
def work_forever(self):
def work(self):
self._work(False)
def work(self):
def work_burst(self):
return self._work(True)
def fork_and_perform_job(self, job):

@ -143,10 +143,10 @@ class TestWorker(RQTestCase):
"""Worker processes work, then quits."""
fooq, barq = Queue('foo'), Queue('bar')
w = Worker([fooq, barq])
self.assertEquals(w.work(), False, 'Did not expect any work on the queue.')
self.assertEquals(w.work_burst(), False, 'Did not expect any work on the queue.')
fooq.enqueue(testjob, name='Frank')
self.assertEquals(w.work(), True, 'Expected at least some work done.')
self.assertEquals(w.work_burst(), True, 'Expected at least some work done.')
if __name__ == '__main__':

Loading…
Cancel
Save