diff options
author | Vincent Driessen <vincent@3rdcloud.com> | 2011-11-17 22:39:53 +0100 |
---|---|---|
committer | Vincent Driessen <vincent@3rdcloud.com> | 2011-11-17 22:39:53 +0100 |
commit | d780c929c0fee5557ebffc3a0b46c236c2f2872f (patch) | |
tree | 201531e7caa8e07effa8219d8feeec725f5db220 | |
parent | d761dd0280dcb60fa26eebe6ab171db10c607727 (diff) | |
download | rq-d780c929c0fee5557ebffc3a0b46c236c2f2872f.tar.gz |
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.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | examples/run_worker.py | 2 | ||||
-rw-r--r-- | rq/worker.py | 4 | ||||
-rw-r--r-- | tests/test_rq.py | 4 |
4 files changed, 9 insertions, 9 deletions
@@ -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 diff --git a/examples/run_worker.py b/examples/run_worker.py index e87ec89..4853788 100644 --- a/examples/run_worker.py +++ b/examples/run_worker.py @@ -7,4 +7,4 @@ conn.push(Redis()) if __name__ == '__main__': q = Queue() - Worker(q).work_forever() + Worker(q).work() diff --git a/rq/worker.py b/rq/worker.py index e1bd1a7..c2ccef3 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -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): diff --git a/tests/test_rq.py b/tests/test_rq.py index 1701537..91d7926 100644 --- a/tests/test_rq.py +++ b/tests/test_rq.py @@ -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__': |