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
 
@@ -116,7 +116,7 @@ class ReposController(base.BaseRepoContr
 
        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')
kallithea/controllers/api/api.py
Show inline comments
 
@@ -1265,7 +1265,7 @@ class ApiController(JSONRPCController):
 
                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,),
 
@@ -1437,7 +1437,7 @@ class ApiController(JSONRPCController):
 
                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,
kallithea/controllers/forks.py
Show inline comments
 
@@ -152,7 +152,7 @@ class ForksController(base.BaseRepoContr
 

	
 
            # 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'),
kallithea/lib/celerylib/__init__.py
Show inline comments
 
@@ -42,18 +42,6 @@ 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
 
    """
 
@@ -71,7 +59,6 @@ def task(f_org):
 
        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__)
 
@@ -79,8 +66,7 @@ def task(f_org):
 
                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
 

	
0 comments (0 inline, 0 general)