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
def init_selinon(app=None): """Init Selinon configuration. :param app: celery application, if omitted Selinon flow handling tasks will not be registered """ if app is not None: Config.set_celery_app(app) nodes_config, flows_config = get_dispatcher_config_files() Config.set_config_yaml(nodes_config, flows_config)
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 """ # Avoid exception on CLI run. from celery import Celery conf = {'broker_url': os.environ['BROKER_URL']} if with_result_backend: conf['result_backend'] = os.environ['RESULT_BACKEND_URL'] app = Celery('app') app.config_from_object(conf) # Set Selinon configuration. Config.set_config_yaml(*get_config_files()) # Prepare Celery Config.set_celery_app(app) return app
def init_celery(app=None, result_backend=True): """ Init Celery configuration :param app: celery configuration, if omitted, application will be instantiated :param result_backend: True if Celery should connect to result backend """ # Keep this for debugging purposes for now _logger.debug(">>> Selinon version is %s" % selinon_version) _logger.debug(">>> Selinonlib version is %s" % selinonlib_version) _logger.debug(">>> Celery version is %s" % celery_version) if not result_backend: CelerySettings.disable_result_backend() if app is None: app = Celery('tasks') app.config_from_object(CelerySettings) else: app.config_from_object(CelerySettings) Config.set_celery_app(app) nodes_config, flows_config = get_dispatcher_config_files() Config.set_config_yaml(nodes_config, flows_config)
from __future__ import absolute_import, unicode_literals import os from selinon import Config, run_flow from celery import Celery from django.conf import settings os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'selinon_demo.settings') app = Celery('selinon_demo') app.config_from_object('django.conf:settings', namespace='CELERY') # Config.set_pickel_config_object(MyDBConfig()) Config.set_celery_app(app) app.autodiscover_tasks() app.conf.task_routes = {'*': {'queue': 'hello_task'}} # node_dict = { # 'tasks': [{'name': 'CheckMessage', 'queue': 'hello_task', 'import': 'tasks', 'max_retry':0, 'storage': 'Redis'}, # {'name': 'MessageLength', 'queue': 'hello_task', 'import': 'tasks', 'max_retry':0, 'storage': 'Redis'}, # {'name': 'SuccessAction', 'queue': 'hello_task', 'import': 'tasks', 'max_retry':0, 'storage': 'Redis'}, # {'name': 'FailureAction', 'queue': 'hello_task', 'import': 'tasks', 'max_retry':0, 'storage': 'Redis'}], # 'flows': ['my_new_flow'], # 'storages': [{'name': 'Redis', 'import': 'selinon.storages.redis', 'configuration': {'host': 'localhost', 'port':6379, 'db':1, 'charset': 'utf-8'}}], # 'global': {'trace': {'json': True}}, # 'migration_dir': 'migration_dir'} # flow_definition = [{'flow-definitions': [{'name': 'my_new_flow',