Skip to content

Commit

Permalink
chore: quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Mar 21, 2024
1 parent d64d1da commit f8a1415
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.core.management.base import BaseCommand
from eventtracking.backends.event_bus import EventBusRoutingBackend
from eventtracking.tracker import get_tracker

from event_routing_backends.processors.transformer_utils.exceptions import EventNotDispatched

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -67,16 +68,20 @@ def handle(self, *args, **options):
logger.info("Skipping backend: {}".format(name))
continue
for backend_name, backend in engine.backends.items():
while failed_events:=backend.get_failed_events(batch_size):
logger.info("Recovering {} failed events for backend {}".format(len(failed_events), backend_name))
while failed_events := backend.get_failed_events(batch_size):
logger.info(
"Recovering {} failed events for backend {}".format(
len(failed_events), backend_name
)
)
for event in failed_events:
try:
backend.send(event)
success += 1
except EventNotDispatched as e:
except EventNotDispatched:
logger.error("Malformed event: {}".format(event["name"]))
malformed += 1
except Exception as e:
except Exception as e: # pylint: disable=broad-except
# Backend can still be in a bad state, so we need to catch all exceptions
logger.error("Failed to send event: {}".format(e))
failed += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.test import TestCase
from django.test.utils import override_settings
from eventtracking.django.django_tracker import DjangoTracker

from event_routing_backends.processors.transformer_utils.exceptions import EventNotDispatched

XAPI_PROCESSOR = {
Expand Down Expand Up @@ -81,7 +82,9 @@ def test_send_tracking_log_to_backends(self, mock_get_tracker):
"event_routing_backends.management.commands.recover_failed_events.get_tracker"
)
@patch("event_routing_backends.management.commands.recover_failed_events.logger")
def test_send_tracking_log_to_backends_with_exception(self, mock_logger, mock_get_tracker):
def test_send_tracking_log_to_backends_with_exception(
self, mock_logger, mock_get_tracker
):
"""
Test for send_tracking_log_to_backends
"""
Expand All @@ -94,7 +97,6 @@ def test_send_tracking_log_to_backends_with_exception(self, mock_logger, mock_ge

call_command("recover_failed_events", transformer_type="all")

#mock_logger.error.assert_called_once_with("Malformed event: {}".format("test"))
mock_logger.error.assert_called_once_with("Failed to send event: Error")

@override_settings(
Expand All @@ -111,7 +113,9 @@ def test_send_tracking_log_to_backends_with_exception(self, mock_logger, mock_ge
"event_routing_backends.management.commands.recover_failed_events.get_tracker"
)
@patch("event_routing_backends.management.commands.recover_failed_events.logger")
def test_send_tracking_log_to_backends_with_event_exception(self, mock_logger, mock_get_tracker):
def test_send_tracking_log_to_backends_with_event_exception(
self, mock_logger, mock_get_tracker
):
"""
Test for send_tracking_log_to_backends
"""
Expand Down

0 comments on commit f8a1415

Please sign in to comment.