diff --git a/bin/rqworker b/bin/rqworker index 2d0c712..b877815 100755 --- a/bin/rqworker +++ b/bin/rqworker @@ -64,10 +64,7 @@ def main(): queues = map(Queue, args) w = Worker(queues, name=opts.name) - if opts.burst: - w.work_burst() - else: - w.work() + w.work(burst=opts.burst) if __name__ == '__main__': main() diff --git a/rq/worker.py b/rq/worker.py index f9d67e7..dbc8943 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -219,8 +219,14 @@ class Worker(object): signal.signal(signal.SIGTERM, request_stop) - def _work(self, quit_when_done=False): - """This method starts the work loop. + def work(self, burst=False): + """Starts the work loop. + + Pops and performs all jobs on the current list of queues. When all + queues are empty, block and wait for new jobs to arrive on any of the + queues, unless `burst` is True. + + The return value indicates whether any jobs were processed. """ self._install_signal_handlers() @@ -236,7 +242,7 @@ class Worker(object): qnames = self.queue_names() self.procline('Listening on %s' % (','.join(qnames))) self.log.info('*** Listening for work on %s' % (', '.join(qnames))) - wait_for_job = not quit_when_done + wait_for_job = not burst job = Queue.dequeue_any(self.queues, wait_for_job) if job is None: break @@ -250,21 +256,6 @@ class Worker(object): self.register_death() return did_work - def work(self): - """Pop and perform all jobs on the current list of queues. When all - queues are empty, block and wait for new jobs to arrive on any of the - queues. - """ - self._work(False) - - def work_burst(self): - """Pop and perform all jobs on the current list of queues. When all - queues are empty, return. - - The return value indicates whether any jobs were processed. - """ - return self._work(True) - def fork_and_perform_job(self, job): child_pid = os.fork() if child_pid == 0: diff --git a/tests/test_rq.py b/tests/test_rq.py index 5463c9d..38abb70 100644 --- a/tests/test_rq.py +++ b/tests/test_rq.py @@ -139,10 +139,10 @@ class TestWorker(RQTestCase): """Worker processes work, then quits.""" fooq, barq = Queue('foo'), Queue('bar') w = Worker([fooq, barq]) - self.assertEquals(w.work_burst(), False, 'Did not expect any work on the queue.') + self.assertEquals(w.work(burst=True), False, 'Did not expect any work on the queue.') fooq.enqueue(testjob, name='Frank') - self.assertEquals(w.work_burst(), True, 'Expected at least some work done.') + self.assertEquals(w.work(burst=True), True, 'Expected at least some work done.') if __name__ == '__main__':