diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py --- a/rhodecode/lib/celerylib/tasks.py +++ b/rhodecode/lib/celerylib/tasks.py @@ -330,7 +330,7 @@ def create_repo_fork(form_data, cur_user return True -@async_task(ignore_result=True) +@async_task(ignore_result=True, base=RequestContextTask) def repo_maintenance(repoid): from rhodecode.lib import repo_maintenance as repo_maintenance_lib log = get_logger(repo_maintenance) @@ -345,7 +345,7 @@ def repo_maintenance(repoid): log.debug('Repo `%s` not found or without a clone_url', repoid) -@async_task(ignore_result=True) +@async_task(ignore_result=True, base=RequestContextTask) def check_for_update(send_email_notification=True, email_recipients=None): from rhodecode.model.update import UpdateModel from rhodecode.model.notification import EmailNotificationModel @@ -380,14 +380,8 @@ def check_for_update(send_email_notifica email_body_plaintext, email_body) except Exception: - pass - - -@async_task(ignore_result=False) -def beat_check(*args, **kwargs): - log = get_logger(beat_check) - log.info('%r: Got args: %r and kwargs %r', beat_check, args, kwargs) - return time.time() + log.exception('Failed to check for update') + raise def sync_last_update_for_objects(*args, **kwargs): @@ -409,6 +403,13 @@ def sync_last_update_for_objects(*args, repo_gr.update_commit_cache() -@async_task(ignore_result=True) +@async_task(ignore_result=True, base=RequestContextTask) def sync_last_update(*args, **kwargs): sync_last_update_for_objects(*args, **kwargs) + + +@async_task(ignore_result=False) +def beat_check(*args, **kwargs): + log = get_logger(beat_check) + log.info('%r: Got args: %r and kwargs %r', beat_check, args, kwargs) + return time.time() diff --git a/rhodecode/lib/request.py b/rhodecode/lib/request.py --- a/rhodecode/lib/request.py +++ b/rhodecode/lib/request.py @@ -21,6 +21,7 @@ from uuid import uuid4 from pyramid.decorator import reify from pyramid.request import Request as _Request +from rhodecode.translation import _ as tsf class Request(_Request): @@ -36,3 +37,14 @@ class Request(_Request): def req_id_records_init(self): self._req_id_bucket = list() + + def plularize(self, *args, **kwargs): + return self.localizer.pluralize(*args, **kwargs) + + def translate(self, *args, **kwargs): + localizer = self.localizer + + def auto_translate(*_args, **_kwargs): + return localizer.translate(tsf(*_args, **_kwargs)) + + return auto_translate(*args, **kwargs) diff --git a/rhodecode/model/notification.py b/rhodecode/model/notification.py --- a/rhodecode/model/notification.py +++ b/rhodecode/model/notification.py @@ -427,11 +427,11 @@ class EmailNotificationModel(BaseModel): renders template for email, and returns a tuple of (subject, email_headers, email_html_body, email_plaintext_body) """ + request = get_current_request() + # translator and helpers inject _kwargs = self._update_kwargs_for_render(kwargs) - request = get_current_request() email_template = self.get_renderer(type_, request=request) - subject = email_template.render('subject', **_kwargs) try: diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py --- a/rhodecode/subscribers.py +++ b/rhodecode/subscribers.py @@ -36,9 +36,7 @@ from pyramid.settings import asbool from pyramid.path import AssetResolver from threading import Thread -from rhodecode.translation import _ as tsf from rhodecode.config.jsroutes import generate_jsroutes_content -from rhodecode.lib import auth from rhodecode.lib.base import get_auth_user import rhodecode @@ -60,17 +58,6 @@ def add_renderer_globals(event): event['h'] = helpers -def add_localizer(event): - request = event.request - localizer = request.localizer - - def auto_translate(*args, **kwargs): - return localizer.translate(tsf(*args, **kwargs)) - - request.translate = auto_translate - request.plularize = localizer.pluralize - - def set_user_lang(event): request = event.request cur_user = getattr(request, 'user', None) diff --git a/rhodecode/tweens.py b/rhodecode/tweens.py --- a/rhodecode/tweens.py +++ b/rhodecode/tweens.py @@ -110,8 +110,6 @@ def includeme(config): 'pyramid.events.BeforeRender') config.add_subscriber('rhodecode.subscribers.set_user_lang', 'pyramid.events.NewRequest') - config.add_subscriber('rhodecode.subscribers.add_localizer', - 'pyramid.events.NewRequest') config.add_subscriber('rhodecode.subscribers.reset_log_bucket', 'pyramid.events.NewRequest') config.add_subscriber('rhodecode.subscribers.add_request_user_context',