def test_get_config_file_with_prod_config(self): with tempfile.NamedTemporaryFile() as temp_file: temp_file.write(bytes('Some data', 'UTF-8')) temp_file.flush() os.environ["CELERY_PROD_CONFIG"] = temp_file.name config = get_config_file() self.assertEqual(config, temp_file.name)
def get_broker_url(config=None): if config is None: config_file = get_config_file() if config_file is None: config = configparser.ConfigParser() config['app:main'] = {} else: config = read_ini(config_file) url = "memory://" try: celery_always_eager = config.getboolean(Config.EAGER_MODE, False) except: celery_always_eager = False if not celery_always_eager: try: url = config.get(Config.BROKER_URL, url) except: pass return url
from edmigrate.database.repmgr_connector import RepMgrDBConnection from edmigrate.utils.constants import Constants logger = logging.getLogger(Constants.WORKER_NAME) PREFIX = 'migrate.celery' def setup_celery(settings, prefix=PREFIX): ''' Setup celery based on parameters defined in setting (ini file). This calls by client application when dictionary of settings is given :param settings: dict of configurations :param prefix: prefix in configurations used for configuring celery ''' setup_for_worker(celery, settings, prefix) setup_settings(settings) # Create an instance of celery, check if it's for prod celeryd mode and configure it for prod mode if so celery, conf = configure_celeryd(PREFIX, prefix=PREFIX) prod_config = get_config_file() if prod_config: # We should only need to setup db connection in prod mode # setup_db_connection(conf) initialize_db(RepMgrDBConnection, conf) initialize_db(StatsDBConnection, conf) setup_settings(conf) logging.config.fileConfig(prod_config)
def setup_global_settings(settings): ''' Setup global settings for pdf tasks :param settings: dict of configurations ''' global TIMEOUT global MINIMUM_FILE_SIZE global MAX_RETRIES global RETRY_DELAY global PDFUNITE_TIMEOUT global JAVASCRIPT_DELAY TIMEOUT = int(settings.get('pdf.generate_timeout', TIMEOUT)) MINIMUM_FILE_SIZE = int( settings.get('pdf.minimum_file_size', MINIMUM_FILE_SIZE)) MAX_RETRIES = int(settings.get('pdf.retries_allowed', MAX_RETRIES)) RETRY_DELAY = int(settings.get('pdf.retry_delay', RETRY_DELAY)) PDFUNITE_TIMEOUT = int( settings.get('pdf.merge.pdfunite_timeout', PDFUNITE_TIMEOUT)) JAVASCRIPT_DELAY = int( settings.get('pdf.wkhtmltopdf.javascript_delay', JAVASCRIPT_DELAY)) # Create an instance of celery, check if it's for prod celeryd mode and configure it for prod mode if so celery, conf = configure_celeryd(PREFIX, prefix=PREFIX) prod_config = get_config_file() if prod_config: setup_global_settings(conf) initialize_hpz(conf)
def test_get_config_file(self): self.assertIsNone(get_config_file())