Have work() return whether work has been done, or not.

And promote Worker to the rq namespace, so you can
    from rq import Worker
main
Vincent Driessen 13 years ago
parent 1c9fa66bc1
commit 1a893e60cf

@ -1,4 +1,5 @@
from .proxy import conn from .proxy import conn
from .queue import Queue from .queue import Queue
from .worker import Worker
__all__ = ['conn', 'Queue'] __all__ = ['conn', 'Queue', 'Worker']

@ -80,17 +80,20 @@ class Worker(object):
return (queue, msg) return (queue, msg)
def _work(self, quit_when_done=False): def _work(self, quit_when_done=False):
did_work = False
while True: while True:
self.procline('Waiting on %s' % (', '.join(self.queue_names()),)) self.procline('Waiting on %s' % (', '.join(self.queue_names()),))
try: try:
wait_for_job = not quit_when_done wait_for_job = not quit_when_done
queue, msg = self.pop_next_job(wait_for_job) queue, msg = self.pop_next_job(wait_for_job)
did_work = True
except NoMoreWorkError: except NoMoreWorkError:
break break
self.fork_and_perform_job(queue, msg) self.fork_and_perform_job(queue, msg)
return did_work
def work_forever(self): def work_forever(self):
return self._work(False) self._work(False)
def work(self): def work(self):
return self._work(True) return self._work(True)

Loading…
Cancel
Save