def test_bad_ini(): from pyramid_celery import celery_app from pyramid_celery.loaders import INILoader from pyramid.exceptions import ConfigurationError ini_path = os.path.join(here, 'tests/configs/bad.ini') loader = INILoader(celery_app, ini_file=ini_path) with pytest.raises(ConfigurationError) as e: loader.read_configuration() msg = 'schedule type sundial in section celerybeat:task1 is invalid' assert str(e.value) == msg
def test_bad_json(): from pyramid_celery import celery_app from pyramid_celery.loaders import INILoader from pyramid.exceptions import ConfigurationError ini_path = os.path.join(here, 'tests/configs/bad_json.ini') loader = INILoader(celery_app, ini_file=ini_path) with pytest.raises(ConfigurationError) as e: loader.read_configuration() msg = ('The schedule={"seconds": 60*60*60} is not valid json in section ' 'celerybeat:task1') assert str(e.value) == msg
def test_bad_json(): from pyramid_celery import celery_app from pyramid_celery.loaders import INILoader from pyramid.exceptions import ConfigurationError ini_path = os.path.join(here, 'tests/configs/bad_json.ini') loader = INILoader(celery_app, ini_file=ini_path) with pytest.raises(ConfigurationError) as e: loader.read_configuration() msg = ( 'The schedule={"seconds": 60*60*60} is not valid json in section ' 'celerybeat:task1' ) assert str(e.value) == msg
def setup_app(app, root, request, registry, closer, ini_location): loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() #: TODO: There might be other variables requiring special handling boolify( celery_config, 'task_always_eager', 'enable_utc', 'result_persistent', ) if asbool(celery_config.get('use_celeryconfig', False)) is True: config_path = 'celeryconfig' celery_app.config_from_object(config_path) else: hijack_key = 'worker_hijack_root_logger' # TODO: Couldn't find a way with celery to do this hijack_logger = asbool(celery_config.get(hijack_key, False)) celery_config[hijack_key] = hijack_logger if hijack_logger is False: global ini_file ini_file = ini_location signals.setup_logging.connect(configure_logging) celery_app.config_from_object(celery_config) celery_app.conf.update({'PYRAMID_APP': app}) celery_app.conf.update({'PYRAMID_ROOT': root}) celery_app.conf.update({'PYRAMID_REQUEST': request}) celery_app.conf.update({'PYRAMID_REGISTRY': registry}) celery_app.conf.update({'PYRAMID_CLOSER': closer})
def setup_app(registry, ini_location): loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() #: TODO: There might be other variables requiring special handling boolify(celery_config, 'CELERY_ALWAYS_EAGER', 'CELERY_ENABLE_UTC', 'CELERY_RESULT_PERSISTENT') if asbool(celery_config.get('USE_CELERYCONFIG', False)) is True: config_path = 'celeryconfig' celery_app.config_from_object(config_path) else: # TODO: Couldn't find a way with celery to do this hijack_logger = asbool( celery_config.get('CELERYD_HIJACK_ROOT_LOGGER', False) ) celery_config['CELERYD_HIJACK_ROOT_LOGGER'] = hijack_logger if hijack_logger is False: global ini_file ini_file = ini_location signals.setup_logging.connect(configure_logging) celery_app.config_from_object(celery_config) celery_app.conf.update({'PYRAMID_REGISTRY': registry})
def setup_app(app, root, request, registry, closer, ini_location): loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() #: TODO: There might be other variables requiring special handling boolify(celery_config, 'CELERY_ALWAYS_EAGER', 'CELERY_ENABLE_UTC', 'CELERY_RESULT_PERSISTENT') if asbool(celery_config.get('USE_CELERYCONFIG', False)) is True: config_path = 'celeryconfig' celery_app.config_from_object(config_path) else: # TODO: Couldn't find a way with celery to do this hijack_logger = asbool( celery_config.get('CELERYD_HIJACK_ROOT_LOGGER', False)) celery_config['CELERYD_HIJACK_ROOT_LOGGER'] = hijack_logger if hijack_logger is False: global ini_file ini_file = ini_location signals.setup_logging.connect(configure_logging) celery_app.config_from_object(celery_config) celery_app.conf.update({'PYRAMID_APP': app}) celery_app.conf.update({'PYRAMID_ROOT': root}) celery_app.conf.update({'PYRAMID_REQUEST': request}) celery_app.conf.update({'PYRAMID_REGISTRY': registry}) celery_app.conf.update({'PYRAMID_CLOSER': closer})
def test_celery_routing(): from pyramid_celery import celery_app from pyramid_celery.loaders import INILoader ini_path = os.path.join(here, 'tests/configs/routing.ini') loader = INILoader(celery_app, ini_file=ini_path) result = loader.read_configuration() routes = result['CELERY_ROUTES'] assert result['BROKER_URL'] == 'redis://localhost:1337/0' assert routes['myapp.tasks.Task1']['queue'] == 'fast_tasks' assert routes['otherapp.tasks.Task3']['queue'] == 'slow_tasks'
def setup_app(registry, ini_location): celery_app = test_celery_app loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() if asbool(celery_config.get('USE_CELERYCONFIG', False)) is True: config_path = 'celeryconfig' celery_app.config_from_object(config_path) else: celery_app.config_from_object(celery_config) celery_app.conf.update({'PYRAMID_REGISTRY': registry}) return celery_app
def setup_app(ini_location): loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() if get_any(celery_config, ('use_celeryconfig', 'USE_CELERYCONFIG')): celery_app.config_from_object('celeryconfig') else: # TODO: Couldn't find a way with celery to do this hijack_logger = get_any( celery_config, ('worker_hijack_root_logger', 'CELERYD_HIJACK_ROOT_LOGGER'), False) if hijack_logger is False: global ini_file ini_file = ini_location signals.setup_logging.connect(configure_logging) celery_app.config_from_object(celery_config)
def test_basic_ini(): from pyramid_celery import celery_app from pyramid_celery.loaders import INILoader from celery.schedules import crontab import datetime ini_path = os.path.join(here, 'tests/configs/dev.ini') loader = INILoader(celery_app, ini_file=ini_path) result = loader.read_configuration() schedule = result['CELERYBEAT_SCHEDULE'] assert result['BROKER_URL'] == 'redis://localhost:1337/0' assert schedule['task1']['task'] == 'myapp.tasks.Task1' assert schedule['task2']['task'] == 'myapp.tasks.Task2' assert schedule['task3']['task'] == 'otherapp.tasks.Task3' assert schedule['task4']['task'] == 'myapp.tasks.Task4' assert isinstance(schedule['task1']['schedule'], crontab) assert isinstance(schedule['task2']['schedule'], datetime.timedelta) assert isinstance(schedule['task4']['schedule'], int) assert schedule['task2']['args'] == [16, 16] assert schedule['task3']['kwargs'] == {"boom": "shaka"}
def setup_app(registry, ini_location): loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() if asbool(celery_config.get('USE_CELERYCONFIG', False)) is True: config_path = 'celeryconfig' celery_app.config_from_object(config_path) else: # TODO: Couldn't find a way with celery to do this hijack_logger = asbool( celery_config.get('CELERYD_HIJACK_ROOT_LOGGER', False)) celery_config['CELERYD_HIJACK_ROOT_LOGGER'] = hijack_logger if hijack_logger is False: global ini_file ini_file = ini_location signals.setup_logging.connect(configure_logging) celery_app.config_from_object(celery_config) celery_app.conf.update({'PYRAMID_REGISTRY': registry})
def setup_app(registry, ini_location): loader = INILoader(celery_app, ini_file=ini_location) celery_config = loader.read_configuration() if asbool(celery_config.get('USE_CELERYCONFIG', False)) is True: config_path = 'celeryconfig' celery_app.config_from_object(config_path) else: # TODO: Couldn't find a way with celery to do this hijack_logger = asbool( celery_config.get('CELERYD_HIJACK_ROOT_LOGGER', False) ) celery_config['CELERYD_HIJACK_ROOT_LOGGER'] = hijack_logger if hijack_logger is False: global ini_file ini_file = ini_location signals.setup_logging.connect(configure_logging) celery_app.config_from_object(celery_config) celery_app.conf.update({'PYRAMID_REGISTRY': registry})
def test_basic_ini(): from pyramid_celery import celery_app from pyramid_celery.loaders import INILoader from celery.schedules import crontab import datetime ini_path = os.path.join(here, 'tests/configs/dev.ini') loader = INILoader(celery_app, ini_file=ini_path) result = loader.read_configuration() schedule = result['beat_schedule'] assert result['broker_url'] == 'redis://*****:*****@initrode.example'), ('exceptions', '*****@*****.**')] assert schedule['task1']['task'] == 'myapp.tasks.Task1' assert schedule['task2']['task'] == 'myapp.tasks.Task2' assert schedule['task3']['task'] == 'otherapp.tasks.Task3' assert schedule['task4']['task'] == 'myapp.tasks.Task4' assert isinstance(schedule['task1']['schedule'], crontab) assert isinstance(schedule['task2']['schedule'], datetime.timedelta) assert isinstance(schedule['task4']['schedule'], int) assert schedule['task2']['args'] == [16, 16] assert schedule['task3']['kwargs'] == {"boom": "shaka"}