mirror of https://github.com/peter4431/rq.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
import argparse
|
|
import logbook
|
|
from logbook import handlers
|
|
from rq import use_redis, Queue, Worker
|
|
|
|
|
|
def format_colors(record, handler):
|
|
from rq.utils import make_colorizer
|
|
if record.level == logbook.WARNING:
|
|
colorize = make_colorizer('darkyellow')
|
|
elif record.level >= logbook.ERROR:
|
|
colorize = make_colorizer('darkred')
|
|
else:
|
|
colorize = lambda x: x
|
|
return '%s: %s' % (record.time.strftime('%H:%M:%S'), colorize(record.msg))
|
|
|
|
def setup_loghandlers(args):
|
|
if args.verbose:
|
|
loglevel = logbook.DEBUG
|
|
formatter = None
|
|
else:
|
|
loglevel = logbook.INFO
|
|
formatter = format_colors
|
|
|
|
import sys
|
|
handlers.NullHandler(bubble=False).push_application()
|
|
handler = handlers.StreamHandler(sys.stdout, level=loglevel, bubble=False)
|
|
if formatter:
|
|
handler.formatter = formatter
|
|
handler.push_application()
|
|
handler = handlers.StderrHandler(level=logbook.WARNING, bubble=False)
|
|
if formatter:
|
|
handler.formatter = formatter
|
|
handler.push_application()
|
|
|
|
|
|
def parse_args():
|
|
parser = argparse.ArgumentParser(description='Starts an RQ worker.')
|
|
parser.add_argument('--host', '-H', default='localhost', help='The Redis hostname (default: localhost)')
|
|
parser.add_argument('--port', '-p', type=int, default=6379, help='The Redis portnumber (default: 6379)')
|
|
|
|
parser.add_argument('--burst', '-b', action='store_true', default=False, help='Run in burst mode (quit after all work is done)')
|
|
parser.add_argument('--name', '-n', default=None, help='Specify a different name')
|
|
parser.add_argument('--verbose', '-v', action='store_true', default=False, help='Show more output')
|
|
parser.add_argument('queues', nargs='*', default=['default'], help='The queues to listen on (default: \'default\')')
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
use_redis()
|
|
setup_loghandlers(args)
|
|
|
|
queues = map(Queue, args.queues)
|
|
w = Worker(queues, name=args.name)
|
|
w.work(burst=args.burst)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|