def parse_args(args=None): parser = argparse.ArgumentParser( description="Lightbus management command.") parser.add_argument( "--service-name", "-s", help="Name of service in which this process resides. YOU SHOULD " "LIKELY SET THIS IN PRODUCTION. Can also be set using the " "LIGHTBUS_SERVICE_NAME environment. Will default to a random string.", ) parser.add_argument( "--process-name", "-p", help= "A unique name of this process within the service. Can also be set using the " "LIGHTBUS_PROCESS_NAME environment. Will default to a random string.", ) parser.add_argument("--config", dest="config_file", help="Config file to load, JSON or YAML", metavar="FILE") parser.add_argument( "--log-level", help="Set the log level. Overrides any value set in config. " "One of debug, info, warning, critical, exception.", metavar="LOG_LEVEL", ) subparsers = parser.add_subparsers(help="Commands", dest="subcommand") subparsers.required = True lightbus.commands.run.Command().setup(parser, subparsers) lightbus.commands.shell.Command().setup(parser, subparsers) lightbus.commands.dump_schema.Command().setup(parser, subparsers) lightbus.commands.dump_schema.Command().setup(parser, subparsers) lightbus.commands.dump_config_schema.Command().setup(parser, subparsers) autoload_plugins(config=Config.load_dict({})) loop = get_event_loop() block(plugin_hook("before_parse_args", parser=parser, subparsers=subparsers), loop, timeout=5) args = parser.parse_args(sys.argv[1:] if args is None else args) # Note that we don't have an after_parse_args plugin hook. Instead we use the receive_args # hook which is called once we have instantiated our plugins return args
def create(*args, **kwargs) -> BusPath: """ Create a new bus instance which can be used to access the bus. Typically this will be used as follows: import lightbus bus = lightbus.create() See Also: This function is a wrapper around `create_async()`, see `create_async()` for a list of arguments """ loop = kwargs.get("loop") or get_event_loop() return block(create_async(*args, **kwargs), loop=loop, timeout=5)
def loop(self): return get_event_loop()
def __exit__(self, exc_type, exc_val, exc_tb): loop = self.loop or get_event_loop() block(self.__aexit__(exc_type, exc_val, exc_tb), loop, timeout=5)
def __enter__(self): loop = self.loop or get_event_loop() block(self.__aenter__(), loop, timeout=5)
def loop(self): if self._loop: return self._loop else: return get_event_loop()