Skip to content

Commit

Permalink
feat: Skip Retry Celery Tasks on known exceptions (#117)
Browse files Browse the repository at this point in the history
To avoid retrying celery task when event does not have corresponding transformer or backend enabled we have defined custom exceptions. These exceptions are raised from event-routing-backends.

Co-authored-by: RehanAziz <rehanaziz@A006-00394.local>
  • Loading branch information
rehanedly and RehanAziz committed Sep 7, 2021
1 parent 0e74542 commit 5597e24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions eventtracking/processors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,17 @@ class EventEmissionExit(Exception):
This should only be raised by processors.
"""


class NoTransformerImplemented(Exception):
"""
Raise this exception when there is no transformer implemented
for an event.
"""


class NoBackendEnabled(Exception):
"""
Raise this exception when there is no backend enabled
for an event.
"""
9 changes: 9 additions & 0 deletions eventtracking/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from celery.utils.log import get_task_logger
from celery import shared_task
from eventtracking.tracker import get_tracker
from eventtracking.processors.exceptions import NoTransformerImplemented
from eventtracking.processors.exceptions import NoBackendEnabled

logger = get_task_logger(__name__)
# Maximum number of retries before giving up on rounting event
Expand Down Expand Up @@ -34,6 +36,13 @@ def send_event(self, backend_name, processed_event):
tracker = get_tracker()
backend = tracker.backends[backend_name]
backend.send_to_backends(processed_event.copy())

except (NoTransformerImplemented, NoBackendEnabled) as exc:
logger.exception(
'[send_event] Failed to send event [%s] with backend [%s], [%s]',
processed_event['name'], backend_name, exc
)

except Exception as exc:
logger.exception(
'[send_event] Failed to send event [%s] with backend [%s], [%s]',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def load_requirements(*requirements_paths):

setup(
name='event-tracking',
version='1.1.0',
version='1.1.1',
packages=find_packages(),
include_package_data=True,
license='AGPLv3 License',
Expand Down

0 comments on commit 5597e24

Please sign in to comment.