def test_conf(self): with patch( "opulence.common.configuration.Celery") as mock_celery, patch( "opulence.common.configuration.register") as mock_register: celery_obj = Mock() celery_obj.return_value = "celery mock" celery_obj.conf.update = MagicMock() mock_celery.return_value = celery_obj app = configuration.configure_celery({}, custom_encoder=False) mock_register.assert_not_called()
def test_empty_conf(self): with patch("opulence.common.configuration.Celery") as mock_celery: celery_obj = Mock() celery_obj.return_value = "celery mock" celery_obj.conf.update = MagicMock() mock_celery.return_value = celery_obj base_return = { "task_routes": ("opulence.common.celery.taskRouter.TaskRouter", ), "accept_content": ["customEncoder", "application/json"], "task_serializer": "customEncoder", "result_serializer": "customEncoder", } app = configuration.configure_celery({}) celery_obj.conf.update.assert_called_with(base_return)
def test_conf(self): with patch( "opulence.common.configuration.Celery") as mock_celery, patch( "opulence.common.configuration.register") as mock_register: celery_obj = Mock() celery_obj.return_value = "celery mock" celery_obj.conf.update = MagicMock() mock_celery.return_value = celery_obj base_return = { "task_routes": ("opulence.common.celery.taskRouter.TaskRouter", ), "accept_content": ["customEncoder", "application/json"], "task_serializer": "customEncoder", "result_serializer": "customEncoder", } additional_return = {"a": "bb", "c": 42} base_return.update(additional_return) app = configuration.configure_celery(additional_return) celery_obj.conf.update.assert_called_with(base_return) mock_register.assert_called_once()
from dynaconf import settings from opulence.common.configuration import configure_celery App = configure_celery(settings.CELERY_BROKER)
def setup(self, **kwargs): self.engine_app = configure_celery(settings.REDIS, **kwargs) self.remote_collectors = configure_celery( settings.REMOTE_COLLECTOR.redis, **kwargs)
import multiprocessing from celery.utils.log import get_task_logger from dynaconf import settings from opulence.collectors import services from opulence.common.configuration import configure_celery from opulence.common.job import StatusCode from opulence.common.plugins import PluginManager logger = get_task_logger(__name__) app = configure_celery(settings.CELERY_WORKER) manager = multiprocessing.Manager() available_collectors = manager.dict() @app.task(name="collectors:reload_collectors", ignore_result=True) def reload_collectors(flush=False): global available_collectors logger.info("Reload collectors") if flush: available_collectors.clear() for path in settings.COLLECTORS_PATHS: PluginManager().discover(path) for plugin in PluginManager().get_plugins(path): if plugin.plugin_name not in available_collectors: available_collectors[plugin.plugin_name] = plugin