Changeset - 7a73baa4c66c
[Not reviewed]
default
0 3 0
Mads Kiilerich (mads) - 5 years ago 2021-01-01 20:38:33
mads@kiilerich.com
Grafted from: 4299b38fdf59
celery: don't rely on CELERY_APP only being set (from app_cfg) when use_celery

We would rather always have CELERY_APP set.

Kind of backing out 894a662b12b3.
3 files changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_celery.py
Show inline comments
 
@@ -14,12 +14,13 @@
 

	
 
import celery.bin.worker
 
import click
 

	
 
import kallithea
 
import kallithea.bin.kallithea_cli_base as cli_base
 
from kallithea.lib.utils2 import asbool
 

	
 

	
 
@cli_base.register_command(config_file_initialize_app=True)
 
@click.argument('celery_args', nargs=-1)
 
def celery_run(celery_args):
 
    """Start Celery worker(s) for asynchronous tasks.
 
@@ -29,12 +30,12 @@ def celery_run(celery_args):
 

	
 
    Any extra arguments you pass to this command will be passed through to
 
    Celery. Use '--' before such extra arguments to avoid options to be parsed
 
    by this CLI command.
 
    """
 

	
 
    if not kallithea.CELERY_APP:
 
    if not asbool(kallithea.CONFIG.get('use_celery')):
 
        raise Exception('Please set use_celery = true in .ini config '
 
                        'file before running this command')
 

	
 
    cmd = celery.bin.worker.worker(kallithea.CELERY_APP)
 
    return cmd.run_from_argv(None, command='celery-run -c CONFIG_FILE --', argv=list(celery_args))
kallithea/lib/celerylib/__init__.py
Show inline comments
 
@@ -32,24 +32,24 @@ from hashlib import sha1
 

	
 
from decorator import decorator
 
from tg import config
 

	
 
import kallithea
 
from kallithea.lib.pidlock import DaemonLock, LockHeld
 
from kallithea.lib.utils2 import safe_bytes
 
from kallithea.lib.utils2 import asbool, safe_bytes
 
from kallithea.model import meta
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
def task(f_org):
 
    """Wrapper of celery.task.task, running async if CELERY_APP
 
    """
 

	
 
    if kallithea.CELERY_APP:
 
    if asbool(kallithea.CONFIG.get('use_celery')):
 
        def f_async(*args, **kwargs):
 
            log.info('executing %s task', f_org.__name__)
 
            try:
 
                f_org(*args, **kwargs)
 
            finally:
 
                meta.Session.remove()  # prevent reuse of auto created db sessions
kallithea/model/async_tasks.py
Show inline comments
 
@@ -216,13 +216,13 @@ def get_commits_stats(repo_name, ts_min_
 
            return
 

	
 
        # final release
 
        lock.release()
 

	
 
        # execute another task if celery is enabled
 
        if len(scm_repo.revisions) > 1 and kallithea.CELERY_APP and recurse_limit > 0:
 
        if len(scm_repo.revisions) > 1 and asbool(kallithea.CONFIG.get('use_celery')) and recurse_limit > 0:
 
            get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit - 1)
 
        elif recurse_limit <= 0:
 
            log.debug('Not recursing - limit has been reached')
 
        else:
 
            log.debug('Not recursing')
 
    except celerylib.LockHeld:
0 comments (0 inline, 0 general)