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