configuration.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:demo 作者: selinon 项目源码 文件源码
def init(with_result_backend=False):
    """ Init Celery and Selinon

    :param with_result_backend: true if the application should connect to the result backend
    :return: Celery application instance
    """
    conf = {
        'broker_url': os.environ.get('BROKER_URL', 'amqp://broker:5672'),
    }

    if with_result_backend:
        conf['result_backend'] = os.environ.get('RESULT_BACKEND_URL', 'redis://redis:6379/0')

    app = Celery('myapp')
    app.config_from_object(conf)

    flow_definition_files = []
    # Add all config files for flows
    for conf_file in os.listdir(os.path.join(_BASE_NAME, 'flows')):
        if conf_file.endswith('.yaml') and not conf_file.startswith('.'):
            flow_definition_files.append(os.path.join(_BASE_NAME, 'flows', conf_file))

    # Set Selinon configuration
    Config.set_config_yaml(os.path.join(_BASE_NAME, 'nodes.yaml'), flow_definition_files)
    # Prepare Celery
    Config.set_celery_app(app)

    return app
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号