|
1 | 1 | #!/usr/bin/env python
|
| 2 | + |
| 3 | +import logging |
| 4 | + |
| 5 | +from optparse import OptionParser |
2 | 6 | from pyres.worker import Worker
|
| 7 | + |
| 8 | +LOG_LEVELS = { |
| 9 | + 'debug': logging.DEBUG, |
| 10 | + 'info': logging.INFO, |
| 11 | + 'warning': logging.WARNING, |
| 12 | + 'error': logging.ERROR, |
| 13 | + 'critical': logging.CRITICAL |
| 14 | +} |
| 15 | + |
3 | 16 | def main():
|
4 |
| - from optparse import OptionParser |
| 17 | + |
5 | 18 | usage = "usage: %prog [options] arg1"
|
6 | 19 | parser = OptionParser(usage=usage)
|
7 | 20 | #parser.add_option("-q", dest="queue_list")
|
8 | 21 | parser.add_option("--host", dest="host", default="localhost")
|
9 | 22 | parser.add_option("--port",dest="port",type="int", default=6379)
|
10 | 23 | parser.add_option("-i", '--interval', dest='interval', default=None, help='the default time interval to sleep between runs')
|
| 24 | + parser.add_option('-l', '--log-level', dest='log_level', default=LOG_LEVELS['info'], help='log level. Valid values are "debug", "info", "warning", "error", "critical", in decreasing order of verbosity. Defaults to "info" if parameter not specified.') |
11 | 25 | (options,args) = parser.parse_args()
|
| 26 | + |
12 | 27 | if len(args) != 1:
|
13 | 28 | parser.print_help()
|
14 | 29 | parser.error("Argument must be a comma seperated list of queues")
|
| 30 | + |
| 31 | + if options.log_level not in LOG_LEVELS.keys(): |
| 32 | + parser.print_help() |
| 33 | + parser.error("invalid log level specified") |
| 34 | + else: |
| 35 | + log_level = LOG_LEVELS[options.log_level] |
| 36 | + |
| 37 | + logging.basicConfig(level=log_level, format="%(asctime)s: %(levelname)s: %(message)s") |
| 38 | + |
15 | 39 | queues = args[0].split(',')
|
16 | 40 | server = '%s:%s' % (options.host,options.port)
|
17 | 41 | Worker.run(queues, server, options.interval)
|
|
0 commit comments