# HG changeset patch # User RhodeCode Admin # Date 2024-06-14 06:58:18 # Node ID cd13bacdfa7b7e765ea16d31643afc258550398c # Parent 6da054fbd0e00e52bcb3c95928d1f1834b951886 celery: added test view to test celery exception handling diff --git a/rhodecode/apps/ops/__init__.py b/rhodecode/apps/ops/__init__.py --- a/rhodecode/apps/ops/__init__.py +++ b/rhodecode/apps/ops/__init__.py @@ -41,6 +41,15 @@ def admin_routes(config): renderer='json_ext') config.add_route( + name='ops_celery_error_test', + pattern='/error-celery') + config.add_view( + OpsView, + attr='ops_celery_error_test', + route_name='ops_celery_error_test', request_method='GET', + renderer='json_ext') + + config.add_route( name='ops_redirect_test', pattern='/redirect') config.add_view( diff --git a/rhodecode/apps/ops/views.py b/rhodecode/apps/ops/views.py --- a/rhodecode/apps/ops/views.py +++ b/rhodecode/apps/ops/views.py @@ -66,6 +66,20 @@ class OpsView(BaseAppView): 'Client:{}. Generation time: {}.'.format(self.request.user, time.time())) raise TestException(msg) + def ops_celery_error_test(self): + """ + Test exception handling and emails on errors + """ + from rhodecode.lib.celerylib import tasks, run_task + + # add timeout so we add some sort of rate limiter + time.sleep(2) + + msg = ('RhodeCode Enterprise test exception. ' + 'Client:{}. Generation time: {}.'.format(self.request.user, time.time())) + celery_task = run_task(tasks.test_celery_exception, msg) + return {'task': str(celery_task)} + def ops_redirect_test(self): """ Test redirect handling 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 @@ -403,6 +403,11 @@ def sync_last_update_for_objects(*args, @async_task(ignore_result=True, base=RequestContextTask) +def test_celery_exception(msg): + raise Exception(f'Test exception: {msg}') + + +@async_task(ignore_result=True, base=RequestContextTask) def sync_last_update(*args, **kwargs): sync_last_update_for_objects(*args, **kwargs)