def mongo(options): from wolverine import MicroApp loop = asyncio.get_event_loop() config_file = os.path.join(__path__[0], 'settings.ini') app = MicroApp(loop=loop, config_file=config_file) mongo_db = MicroMongoDB() app.register_module(mongo_db) controller = ZMQMicroController() app.register_module(controller) service_def = MongoService(app) controller.register_service(service_def) app.run()
def web(): log_level = logging.INFO usage = "usage: %prog [options] arg" parser = OptionParser(usage) parser.add_option("-l", "--log-level", dest="log_level", help="log level one of " "(DEBUG, INFO, WARNING, ERROR, Critical)", default="ERROR") (options, args) = parser.parse_args() if options.log_level: log_level = getattr(logging, options.log_level.upper()) logging.basicConfig(level=log_level, format=LOG_FORMAT) loop = asyncio.get_event_loop() app = MicroApp(loop=loop) gateway = GatewayModule() app.register_module(gateway) web_console = WebModule() app.register_module(web_console) app.run() def shutdown(sig_name): if sig_name in MicroApp.SIG_NAMES: app.web.stop_server() tasks = asyncio.Task.all_tasks(loop) for task in tasks: try: task.cancel() except Exception: pass loop.stop() app.add_shutdown_handler(shutdown) app.web.create_server() loop.run_forever()