Exemplo n.º 1
0
def main(source, sink, topics, group_id, client_id, tables, config, executor,
         name, repo, tag):
    if source not in MQS and sink not in MQS:
        click.echo('source 或者 sink 必须有一个为 MQS 类型')
        return

    configure_logging()

    try:
        tables = import_string(tables)
    except ImportError:
        print(
            f'can not import values from tables argument, then use the value')

    config_kwargs = import_string(config)

    if executor == 'local':
        from executors.local_executor import LocalExecutor

        executor = LocalExecutor(source, sink, tables, topics, group_id,
                                 client_id, config_kwargs)
    elif executor == 'celery':
        from executors.celery_executor import CeleryExecutor

        executor = CeleryExecutor(source, sink, tables, topics, group_id,
                                  client_id, config_kwargs, name)
    elif executor == 'docker':
        from executors.docker_executor import DockerExecutor

        cmd = build_cmd(source=source,
                        sink=sink,
                        topics=topics,
                        group_id=group_id,
                        client_id=client_id,
                        tables=tables,
                        config=config)
        print(f'docker container cmd={cmd}')
        executor = DockerExecutor(repo, tag, name, cmd)

    executor.run()
Exemplo n.º 2
0
def load_extensions(bot, ext_list):
    'Load the startup extensions'
    logger = get_logger(__name__)
    logger.info('Loading core extensions')
    bot.load_extension('core')
    logger.info('Successfully loaded core extensions')

    loaded_extensions = ext_list

    for ext in loaded_extensions.copy():
        ext_mod = 'ext.{}'.format(ext)
        if ext_mod not in bot.extensions:
            try:
                bot.load_extension(ext_mod)
                logger.info('Successfully loaded extension: %s', ext)
            except Exception as error:
                if ext_mod in sys.modules:
                    del sys.modules[ext_mod]
                loaded_extensions.remove(ext)
                logger.exception('Failed to load extension: %s', ext)
        else:
            logger.warning('Extension with same name already loaded: %s', ext)


if __name__ == '__main__':
    configure_logging()
    config = get_config()
    ext_config = get_ext_config()
    start_bot(config, ext_config)