Changeset - aa5cd5e44621
[Not reviewed]
default
0 3 0
Mads Kiilerich (mads) - 5 years ago 2021-01-01 18:04:16
mads@kiilerich.com
Grafted from: e2421a84e1f4
celery: always set kallithea.CELERY_APP to a Celery app - it is lazy until it actually is used
3 files changed with 4 insertions and 13 deletions:
0 comments (0 inline, 0 general)
kallithea/__init__.py
Show inline comments
 
@@ -21,35 +21,37 @@ Versioning implementation: http://www.py
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Apr 9, 2010
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, (C) 2014 Bradley M. Kuhn, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import platform
 
import sys
 

	
 
import celery
 

	
 

	
 
if sys.version_info < (3, 6):
 
    raise Exception('Kallithea requires python 3.6 or later')
 

	
 
VERSION = (0, 6, 99)
 
BACKENDS = {
 
    'hg': 'Mercurial repository',
 
    'git': 'Git repository',
 
}
 

	
 
CELERY_APP = None  # set to Celery app instance if using Celery
 
CELERY_APP = celery.Celery()  # needed at import time but is lazy and can be configured later
 

	
 
CONFIG = {}  # set to tg.config when TG app is initialized and calls app_cfg
 

	
 
# URL prefix for non repository related links - must start with `/`
 
ADMIN_PREFIX = '/_admin'
 
URL_SEP = '/'
 

	
 
# Linked module for extensions
 
EXTENSIONS = {}
 

	
 
__version__ = '.'.join(str(each) for each in VERSION)
 
__platform__ = platform.system()
kallithea/config/app_cfg.py
Show inline comments
 
@@ -127,25 +127,25 @@ def setup_configuration(app):
 
                      'The database version does not match the Kallithea version.\n'
 
                      'Please read the documentation on how to upgrade or downgrade the database.\n'
 
                      'Current database version id(s): %s\n'
 
                      'Expected database version id(s): %s\n'
 
                      'If you are a developer and you know what you are doing, you can add `ignore_alembic_revision = True` '
 
                      'to your .ini file to skip the check.\n' % (' '.join(current_heads), ' '.join(available_heads)))
 
            sys.exit(1)
 

	
 
    # store some globals into kallithea
 
    kallithea.DEFAULT_USER_ID = db.User.get_default_user().user_id
 

	
 
    if asbool(config.get('use_celery')):
 
        kallithea.CELERY_APP = celery_app.make_app()
 
        kallithea.CELERY_APP.config_from_object(celery_app.make_celery_config(config))
 
    kallithea.CONFIG = config
 

	
 
    load_extensions(root_path=config['here'])
 

	
 
    set_app_settings(config)
 

	
 
    instance_id = kallithea.CONFIG.get('instance_id', '*')
 
    if instance_id == '*':
 
        instance_id = '%s-%s' % (platform.uname()[1], os.getpid())
 
        kallithea.CONFIG['instance_id'] = instance_id
 

	
 
    # update kallithea.CONFIG with the meanwhile changed 'config'
kallithea/lib/celery_app.py
Show inline comments
 
@@ -7,27 +7,24 @@ The Celery configuration is in the Kalli
 
entirely different format before Celery can use it.
 

	
 
We read the configuration from tg.config at module import time. This module can
 
thus not be imported in global scope but must be imported on demand in function
 
scope after tg.config has been initialized.
 

	
 
To make sure that the config really has been initialized, we check one of the
 
mandatory settings.
 
"""
 

	
 
import logging
 

	
 
import celery
 
import tg
 

	
 

	
 
class CeleryConfig(object):
 
    imports = ['kallithea.model.async_tasks']
 
    task_always_eager = False
 

	
 
list_config_names = {'imports', 'accept_content'}
 

	
 

	
 
desupported = set([
 
    'broker.url',
 
    'celery.accept.content',
 
    'celery.always.eager',
 
@@ -63,20 +60,12 @@ def make_celery_config(config):
 
        if not isinstance(config_value, str):
 
            continue
 
        if celery_key in list_config_names:
 
            celery_value = config_value.split()
 
        elif config_value.isdigit():
 
            celery_value = int(config_value)
 
        elif config_value.lower() in ['true', 'false']:
 
            celery_value = config_value.lower() == 'true'
 
        else:
 
            celery_value = config_value
 
        setattr(celery_config, celery_key, celery_value)
 
    return celery_config
 

	
 

	
 
def make_app():
 
    """Create celery app from the TurboGears configuration file"""
 
    app = celery.Celery()
 
    celery_config = make_celery_config(tg.config)
 
    app.config_from_object(celery_config)
 
    return app
0 comments (0 inline, 0 general)