--- a/poll-hgweb-queue.py Fri Jul 22 20:34:44 2016 +0800
+++ b/poll-hgweb-queue.py Fri Jul 22 22:03:25 2016 +0800
from tornado.gen import coroutine
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop, PeriodicCallback
-from tornado.options import define, options
from tornado.web import Application
from candolint.utils import lookup_option, timestamp
-define('listen', metavar='IP', default='127.0.0.1')
-define('port', metavar='PORT', default=8035, type=int)
-define('xheaders', metavar='True|False', default=False, type=bool)
class CandolintPoller(Application):
def __init__(self, rconn, targets, interval, debug):
self.rconn.rpush('candolint:queue:changes', data)
logging.info('Pushed a change for %s', item['repo'])
- def listen(self, port, address='', **kwargs):
- name = self.__class__.__name__
- logging.info('%s is serving on %s:%d', name, address, port)
- super(CandolintPoller, self).listen(port, address, **kwargs)
parser = ArgumentParser(argument_default=SUPPRESS)
group.add_argument('--redis-password')
group.add_argument('--interval', type=int, help='(default: 8 hours)')
- args, extra = parser.parse_known_args()
- options.parse_command_line([None] + extra) # 1st argument is ignored
+ args = parser.parse_args()
config = yaml.safe_load(args.config) if hasattr(args, 'config') else {}
rhost = lookup_option('redis-host', args, config, default='127.0.0.1')
rconn = redis.StrictRedis(host=rhost, port=rport, password=rpass, db=0)
logging.info('Connected to Redis server')
- application = CandolintPoller(rconn, targets, interval, args.debug)
- application.listen(options.port, options.listen, xheaders=options.xheaders)
+ CandolintPoller(rconn, targets, interval, args.debug)
IOLoop.instance().start()