Changeset - e3d033042fca
[Not reviewed]
default
0 4 0
Mads Kiilerich (mads) - 5 years ago 2020-12-30 00:00:41
mads@kiilerich.com
Grafted from: 7a4bc12bc686
celery: drop task returns - we use ignore_result=True and will never get anything interesting back
4 files changed with 5 insertions and 19 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/repos.py
Show inline comments
 
@@ -113,13 +113,13 @@ class ReposController(base.BaseRepoContr
 
                force_defaults=False,
 
                encoding="UTF-8")
 

	
 
        try:
 
            # create is done sometimes async on celery, db transaction
 
            # management is handled there.
 
            task = RepoModel().create(form_result, request.authuser.user_id)
 
            RepoModel().create(form_result, request.authuser.user_id)
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            msg = (_('Error creating repository %s')
 
                   % form_result.get('repo_name'))
 
            webutils.flash(msg, category='error')
 
            raise HTTPFound(location=url('home'))
kallithea/controllers/api/api.py
Show inline comments
 
@@ -1262,13 +1262,13 @@ class ApiController(JSONRPCController):
 
                repo_landing_rev=landing_rev,
 
                enable_statistics=enable_statistics,
 
                enable_downloads=enable_downloads,
 
                repo_copy_permissions=copy_permissions,
 
            )
 

	
 
            task = RepoModel().create(form_data=data, cur_user=owner.username)
 
            RepoModel().create(form_data=data, cur_user=owner.username)
 
            # no commit, it's done in RepoModel, or async via celery
 
            return dict(
 
                msg="Created new repository `%s`" % (repo_name,),
 
                success=True,  # cannot return the repo data here since fork
 
                               # can be done async
 
            )
 
@@ -1434,13 +1434,13 @@ class ApiController(JSONRPCController):
 
                private=private,
 
                copy_permissions=copy_permissions,
 
                landing_rev=landing_rev,
 
                update_after_clone=False,
 
                fork_parent_id=repo.repo_id,
 
            )
 
            task = RepoModel().create_fork(form_data, cur_user=owner.username)
 
            RepoModel().create_fork(form_data, cur_user=owner.username)
 
            # no commit, it's done in RepoModel, or async via celery
 
            return dict(
 
                msg='Created fork of `%s` as `%s`' % (repo.repo_name,
 
                                                      fork_name),
 
                success=True,  # cannot return the repo data here since fork
 
                               # can be done async
kallithea/controllers/forks.py
Show inline comments
 
@@ -149,13 +149,13 @@ class ForksController(base.BaseRepoContr
 
            # an approximation that is better than nothing
 
            if not db.Ui.get_by_key('hooks', db.Ui.HOOK_UPDATE).ui_active:
 
                form_result['update_after_clone'] = False
 

	
 
            # create fork is done sometimes async on celery, db transaction
 
            # management is handled there.
 
            task = RepoModel().create_fork(form_result, request.authuser.user_id)
 
            RepoModel().create_fork(form_result, request.authuser.user_id)
 
        except formencode.Invalid as errors:
 
            return htmlfill.render(
 
                base.render('forks/fork.html'),
 
                defaults=errors.value,
 
                errors=errors.error_dict or {},
 
                prefix_error=False,
kallithea/lib/celerylib/__init__.py
Show inline comments
 
@@ -39,24 +39,12 @@ from kallithea.lib.utils2 import safe_by
 
from kallithea.model import meta
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class FakeTask(object):
 
    """Fake a sync result to make it look like a finished task"""
 

	
 
    def __init__(self, result):
 
        self.result = result
 

	
 
    def failed(self):
 
        return False
 

	
 
    traceback = None # if failed
 

	
 

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

	
 
    if kallithea.CELERY_APP:
 
        def f_async(*args, **kwargs):
 
@@ -68,22 +56,20 @@ def task(f_org):
 
                log.info('executed %s task', f_org.__name__)
 
        runner = kallithea.CELERY_APP.task(name=f_org.__name__, ignore_result=True)(f_async)
 

	
 
        def f_wrapped(*args, **kwargs):
 
            t = runner.apply_async(args=args, kwargs=kwargs)
 
            log.info('executing task %s in async mode - id %s', f_org, t.task_id)
 
            return t
 
    else:
 
        def f_wrapped(*args, **kwargs):
 
            log.info('executing task %s in sync', f_org.__name__)
 
            try:
 
                f_org(*args, **kwargs)
 
            except Exception as e:
 
                log.error('exception executing sync task %s in sync: %r', f_org.__name__, e)
 
                raise # TODO: return this in FakeTask as with async tasks?
 
            return FakeTask(None)
 
                raise # TODO: report errors differently ... and consistently between sync and async
 

	
 
    return f_wrapped
 

	
 

	
 
def __get_lockkey(func, *fargs, **fkwargs):
 
    params = list(fargs)
0 comments (0 inline, 0 general)