From 1a893e60cf46f8340a6a45e42c45e163172a07cd Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Tue, 15 Nov 2011 22:44:17 +0100 Subject: [PATCH] Have work() return whether work has been done, or not. And promote Worker to the rq namespace, so you can from rq import Worker --- rq/__init__.py | 3 ++- rq/worker.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rq/__init__.py b/rq/__init__.py index 42881a4..07f3a39 100644 --- a/rq/__init__.py +++ b/rq/__init__.py @@ -1,4 +1,5 @@ from .proxy import conn from .queue import Queue +from .worker import Worker -__all__ = ['conn', 'Queue'] +__all__ = ['conn', 'Queue', 'Worker'] diff --git a/rq/worker.py b/rq/worker.py index df4c74f..9055f70 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -80,17 +80,20 @@ class Worker(object): return (queue, msg) def _work(self, quit_when_done=False): + did_work = False while True: self.procline('Waiting on %s' % (', '.join(self.queue_names()),)) try: wait_for_job = not quit_when_done queue, msg = self.pop_next_job(wait_for_job) + did_work = True except NoMoreWorkError: break self.fork_and_perform_job(queue, msg) + return did_work def work_forever(self): - return self._work(False) + self._work(False) def work(self): return self._work(True)