# HG changeset patch # User Mads Kiilerich # Date 1473115878 -7200 # Node ID 54545cc34c3628627759c534b333252670cec5b8 # Parent 82662f9faaf4d1317f8643bea54b55ea99f49b96 celery: import the whole celerylib - no cherry picking in tasks No big deal, but arguably(?!) slightly prettier. The database session handling should probably also be cleaned up - that is not touched here but left as an exercise. diff -r 82662f9faaf4 -r 54545cc34c36 kallithea/lib/celerylib/__init__.py --- a/kallithea/lib/celerylib/__init__.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/celerylib/__init__.py Tue Sep 06 00:51:18 2016 +0200 @@ -35,7 +35,7 @@ from decorator import decorator from kallithea import CELERY_ON, CELERY_EAGER -from kallithea.lib.utils2 import str2bool, safe_str +from kallithea.lib.utils2 import safe_str from kallithea.lib.pidlock import DaemonLock, LockHeld from kallithea.model import init_model from kallithea.model import meta diff -r 82662f9faaf4 -r 54545cc34c36 kallithea/lib/celerylib/tasks.py --- a/kallithea/lib/celerylib/tasks.py Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/lib/celerylib/tasks.py Tue Sep 06 00:51:18 2016 +0200 @@ -39,11 +39,10 @@ from kallithea import CELERY_ON from kallithea.lib import celerylib -from kallithea.lib.celerylib import locked_task, dbsession, \ - str2bool, __get_lockkey, LockHeld, DaemonLock, get_session from kallithea.lib.helpers import person from kallithea.lib.rcmail.smtp_mailer import SmtpMailer from kallithea.lib.utils import setup_cache_regions, action_logger +from kallithea.lib.utils2 import str2bool from kallithea.lib.vcs.utils import author_email from kallithea.lib.compat import json, OrderedDict from kallithea.lib.hooks import log_create_repository @@ -60,11 +59,11 @@ @celerylib.task -@locked_task -@dbsession +@celerylib.locked_task +@celerylib.dbsession def whoosh_index(repo_location, full_index): from kallithea.lib.indexers.daemon import WhooshIndexingDaemon - DBS = get_session() + DBS = celerylib.get_session() index_location = config['index_dir'] WhooshIndexingDaemon(index_location=index_location, @@ -73,17 +72,17 @@ @celerylib.task -@dbsession +@celerylib.dbsession def get_commits_stats(repo_name, ts_min_y, ts_max_y, recurse_limit=100): - DBS = get_session() - lockkey = __get_lockkey('get_commits_stats', repo_name, ts_min_y, + DBS = celerylib.get_session() + lockkey = celerylib.__get_lockkey('get_commits_stats', repo_name, ts_min_y, ts_max_y) lockkey_path = config['app_conf']['cache_dir'] log.info('running task with lockkey %s', lockkey) try: - lock = l = DaemonLock(file_=os.path.join(lockkey_path, lockkey)) + lock = l = celerylib.DaemonLock(file_=os.path.join(lockkey_path, lockkey)) # for js data compatibility cleans the key for person from ' akc = lambda k: person(k).replace('"', "") @@ -232,13 +231,13 @@ log.debug('Not recursing - limit has been reached') else: log.debug('Not recursing') - except LockHeld: + except celerylib.LockHeld: log.info('Task with key %s already running', lockkey) return 'Task with key %s already running' % lockkey @celerylib.task -@dbsession +@celerylib.dbsession def send_email(recipients, subject, body='', html_body='', headers=None, author=None): """ Sends an email with defined parameters from the .ini files. @@ -325,13 +324,13 @@ return True @celerylib.task -@dbsession +@celerylib.dbsession def create_repo(form_data, cur_user): from kallithea.model.repo import RepoModel from kallithea.model.user import UserModel from kallithea.model.db import Setting - DBS = get_session() + DBS = celerylib.get_session() cur_user = UserModel(DBS)._get_user(cur_user) @@ -409,7 +408,7 @@ @celerylib.task -@dbsession +@celerylib.dbsession def create_repo_fork(form_data, cur_user): """ Creates a fork of repository using interval VCS methods @@ -420,7 +419,7 @@ from kallithea.model.repo import RepoModel from kallithea.model.user import UserModel - DBS = get_session() + DBS = celerylib.get_session() base_path = Repository.base_path() cur_user = UserModel(DBS)._get_user(cur_user)