def install_event_hooks(self): from config import EVENT_HOOKS for hook_cls in EVENT_HOOKS: hook = utils.module_resolver(hook_cls) if hook: hook.install() else: app_log.error("Event Hook %s cannot be resolved" % hook_cls)
def install_middleware(self): from config import MIDDLEWARE_CLASSES context["middleware"] = set() for name in MIDDLEWARE_CLASSES: module = utils.module_resolver(name) if module: context["middleware"].add(module()) app_log.debug("Middleware [%s] register ok" % name) else: app_log.error("Middleware [%s] cannot be resolved" % name)
def install_message_backend(self): def shutdown_message_backend(): context.get("message_backend").close() del context["message_backend"] app_log.debug("message backend closed!") try: import config backend_cls = utils.module_resolver(config.MESSAGE_BACKEND) context["message_backend"] = backend_cls(config) connection_future = context.get("message_backend").create_connection() IOLoop.instance().add_future(connection_future, lambda future: future.result()) self._shutdown_callback.append(shutdown_message_backend) app_log.debug("%s install ok" % config.MESSAGE_BACKEND) except: pass