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
 
@@ -30,6 +30,8 @@ Original author and date, and relevant c
 
import platform
 
import sys
 

	
 
import celery
 

	
 

	
 
if sys.version_info < (3, 6):
 
    raise Exception('Kallithea requires python 3.6 or later')
 
@@ -40,7 +42,7 @@ BACKENDS = {
 
    '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
 

	
kallithea/config/app_cfg.py
Show inline comments
 
@@ -136,7 +136,7 @@ def setup_configuration(app):
 
    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'])
kallithea/lib/celery_app.py
Show inline comments
 
@@ -16,9 +16,6 @@ mandatory settings.
 

	
 
import logging
 

	
 
import celery
 
import tg
 

	
 

	
 
class CeleryConfig(object):
 
    imports = ['kallithea.model.async_tasks']
 
@@ -72,11 +69,3 @@ def make_celery_config(config):
 
            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)