|
|
@ -1,44 +1,42 @@
|
|
|
|
#!/usr/bin/env python
|
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import logbook
|
|
|
|
import logging.config
|
|
|
|
from logbook import handlers
|
|
|
|
|
|
|
|
|
|
|
|
from rq import Queue, Worker
|
|
|
|
from rq import Queue, Worker
|
|
|
|
from redis.exceptions import ConnectionError
|
|
|
|
from redis.exceptions import ConnectionError
|
|
|
|
from rq.scripts import add_standard_arguments
|
|
|
|
from rq.scripts import add_standard_arguments
|
|
|
|
from rq.scripts import setup_redis
|
|
|
|
from rq.scripts import setup_redis
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
def setup_loghandlers(args):
|
|
|
|
logging.config.dictConfig({
|
|
|
|
if args.verbose:
|
|
|
|
"version": 1,
|
|
|
|
loglevel = logbook.DEBUG
|
|
|
|
"disable_existing_loggers": False,
|
|
|
|
formatter = None
|
|
|
|
|
|
|
|
else:
|
|
|
|
"formatters": {
|
|
|
|
loglevel = logbook.INFO
|
|
|
|
"console": {
|
|
|
|
formatter = format_colors
|
|
|
|
"format": "%(asctime)s %(message)s",
|
|
|
|
|
|
|
|
"datefmt": "%H:%M:%S",
|
|
|
|
handlers.NullHandler(bubble=False).push_application()
|
|
|
|
},
|
|
|
|
handler = handlers.StreamHandler(sys.stdout, level=loglevel, bubble=False)
|
|
|
|
},
|
|
|
|
if formatter:
|
|
|
|
|
|
|
|
handler.formatter = formatter
|
|
|
|
"handlers": {
|
|
|
|
handler.push_application()
|
|
|
|
"console": {
|
|
|
|
handler = handlers.StderrHandler(level=logbook.WARNING, bubble=False)
|
|
|
|
"level": "DEBUG",
|
|
|
|
if formatter:
|
|
|
|
#"class": "logging.StreamHandler",
|
|
|
|
handler.formatter = formatter
|
|
|
|
"class": "rq.utils.ColorizingStreamHandler",
|
|
|
|
handler.push_application()
|
|
|
|
"formatter": "console",
|
|
|
|
|
|
|
|
"exclude": ["%(asctime)s"],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"root": {
|
|
|
|
|
|
|
|
"handlers": ["console"],
|
|
|
|
|
|
|
|
"level": "DEBUG" if args.verbose else "INFO"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
def parse_args():
|
|
|
@ -83,7 +81,6 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
setup_loghandlers(args)
|
|
|
|
setup_loghandlers(args)
|
|
|
|
setup_redis(args)
|
|
|
|
setup_redis(args)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
queues = map(Queue, args.queues)
|
|
|
|
queues = map(Queue, args.queues)
|
|
|
|
w = Worker(queues, name=args.name)
|
|
|
|
w = Worker(queues, name=args.name)
|
|
|
|