Skip to content

Commit

Permalink
Celery: Log exceptions into log
Browse files Browse the repository at this point in the history
Apparently we can not expect everybody to setup error collection and log
should indicate the problems. Celery does swallow the exceptions
(actually it stores them as result, but Weblate doesn't care for results
for most of the operations), see https://stackoverflow.com/q/16658371/225718

Issue #2813
Issue #2850

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jul 5, 2019
1 parent 308dd1f commit 4170919
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changes.rst
Expand Up @@ -8,6 +8,7 @@ Not yet released.

* Added support for simplified creating of similar components.
* Added support for parsing translation flags from the XML based file formats.
* Log exceptions into Celery log.

weblate 3.7.1
-------------
Expand Down
16 changes: 12 additions & 4 deletions weblate/celery.py
Expand Up @@ -55,6 +55,18 @@
app.autodiscover_tasks()


@task_failure.connect
def handle_task_failure(exception=None, **kwargs):
from weblate.utils.errors import report_error
report_error(
exception,
extra_data=kwargs,
prefix='Failure while executing task',
skip_raven=True,
print_tb=True
)


@app.on_after_configure.connect
def configure_error_handling(sender, **kargs):
"""Rollbar and Sentry integration
Expand All @@ -74,10 +86,6 @@ def celery_base_data_hook(request, data):

rollbar.BASE_DATA_HOOK = celery_base_data_hook

@task_failure.connect
def handle_task_failure(**kw):
rollbar.report_exc_info(extra_data=kw)

if HAS_RAVEN and hasattr(settings, 'RAVEN_CONFIG'):
client = Client(
settings.RAVEN_CONFIG['dsn'],
Expand Down
6 changes: 4 additions & 2 deletions weblate/utils/errors.py
Expand Up @@ -38,7 +38,7 @@


def report_error(error, request=None, extra_data=None, level='warning',
prefix='Handled exception'):
prefix='Handled exception', skip_raven=False, print_tb=False):
"""Wrapper for error reporting
This can be used for store exceptions in error reporting solutions as
Expand All @@ -49,7 +49,7 @@ def report_error(error, request=None, extra_data=None, level='warning',
request=request, extra_data=extra_data, level=level
)

if HAS_RAVEN and hasattr(settings, 'RAVEN_CONFIG'):
if not skip_raven and HAS_RAVEN and hasattr(settings, 'RAVEN_CONFIG'):
raven_client.captureException(
request=request, extra=extra_data, level=level
)
Expand All @@ -60,3 +60,5 @@ def report_error(error, request=None, extra_data=None, level='warning',
error.__class__.__name__,
force_text(error)
)
if print_tb:
LOGGER.exception(prefix)

0 comments on commit 4170919

Please sign in to comment.