class DisApp(tornado.web.Application): def __init__(self): self.redis = redis.Redis(REDIS_HOST, REDIS_PORT, db=1) self.task_handler = TaskHandler(self) return def task_loop(self): """ every 20ms check task notification """ key = REDIS_DISPATCHER_NOTIFICATION_KEY while True: noti = self.redis.lpop(key) if noti == None: # no message return body = json.loads(noti) self.task_handler.task(body) return
class DispatcherDelegate(): def __init__(self, app): self.redis = app.redis self.task_handler = TaskHandler(self) return def run_periodic(self): # every 20ms check dispatcher task tornado.ioloop.PeriodicCallback(self.task_loop, 20).start() return def task_loop(self): """ every 20ms check task notification """ key = REDIS_DISPATCHER_NOTIFICATION_KEY while True: noti = self.redis.lpop(key) if noti == None: # no message return body = json.loads(noti) self.task_handler.task(body) return
def __init__(self): self.redis = redis.Redis(REDIS_HOST, REDIS_PORT, db=1) self.task_handler = TaskHandler(self) return
def __init__(self, app): self.redis = app.redis self.task_handler = TaskHandler(self) return