mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-02-05 05:45:17 -05:00
refactor: Standardize error logging by using logger.error in state machine callbacks and capture_and_log in management commands.
This commit is contained in:
@@ -16,6 +16,7 @@ from django.utils import timezone
|
||||
|
||||
from apps.parks.models import Park
|
||||
from apps.rides.models import Ride
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -90,7 +91,7 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f" {item['name']} ({item['park']}) - opened: {item['date_opened']}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calculating new content: {e}", exc_info=True)
|
||||
capture_and_log(e, 'Calculate new content', source='management', severity='high')
|
||||
raise CommandError(f"Failed to calculate new content: {e}") from None
|
||||
|
||||
def _get_new_parks(self, cutoff_date: datetime, limit: int) -> list[dict[str, Any]]:
|
||||
|
||||
@@ -16,6 +16,7 @@ from django.utils import timezone
|
||||
from apps.core.analytics import PageView
|
||||
from apps.parks.models import Park
|
||||
from apps.rides.models import Ride
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -99,7 +100,7 @@ class Command(BaseCommand):
|
||||
self.stdout.write(f" {item['name']} (score: {item.get('views_change', 'N/A')})")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calculating trending content: {e}", exc_info=True)
|
||||
capture_and_log(e, 'Calculate trending content', source='management', severity='high')
|
||||
raise CommandError(f"Failed to calculate trending content: {e}") from None
|
||||
|
||||
def _calculate_trending_parks(
|
||||
@@ -199,7 +200,7 @@ class Command(BaseCommand):
|
||||
return final_score
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error calculating score for {content_type} {content_obj.id}: {e}")
|
||||
capture_and_log(e, f'Calculate score for {content_type} {content_obj.id}', source='management', severity='medium')
|
||||
return 0.0
|
||||
|
||||
def _calculate_view_growth_score(
|
||||
|
||||
@@ -75,8 +75,6 @@ from typing import Any, Optional
|
||||
|
||||
from django.db import models
|
||||
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -499,11 +497,9 @@ class TransitionCallbackRegistry:
|
||||
overall_success = False
|
||||
|
||||
if not callback.continue_on_error:
|
||||
capture_and_log(
|
||||
RuntimeError(f'Callback {callback.name} returned False'),
|
||||
f'Aborting callback chain - continue_on_error=False',
|
||||
source='state_machine',
|
||||
severity='medium',
|
||||
logger.error(
|
||||
f"Aborting callback chain - {callback.name} failed "
|
||||
f"and continue_on_error=False"
|
||||
)
|
||||
break
|
||||
|
||||
@@ -513,11 +509,9 @@ class TransitionCallbackRegistry:
|
||||
overall_success = False
|
||||
|
||||
if not callback.continue_on_error:
|
||||
capture_and_log(
|
||||
e,
|
||||
f'Aborting callback chain - {callback.name} raised exception',
|
||||
source='state_machine',
|
||||
severity='high',
|
||||
logger.error(
|
||||
f"Aborting callback chain - {callback.name} raised exception "
|
||||
f"and continue_on_error=False"
|
||||
)
|
||||
break
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ from .signals import (
|
||||
pre_state_transition,
|
||||
state_transition_failed,
|
||||
)
|
||||
from apps.core.utils import capture_and_log
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -85,12 +84,8 @@ def with_callbacks(
|
||||
if not pre_success and pre_failures:
|
||||
for callback, exc in pre_failures:
|
||||
if not callback.continue_on_error:
|
||||
capture_and_log(
|
||||
exc or RuntimeError(f'Pre-transition callback {callback.name} failed'),
|
||||
f'Aborting transition - pre-callback failed',
|
||||
source='state_machine',
|
||||
severity='high',
|
||||
)
|
||||
logger.error(f"Pre-transition callback {callback.name} failed, "
|
||||
f"aborting transition")
|
||||
if exc:
|
||||
raise exc
|
||||
raise RuntimeError(f"Pre-transition callback {callback.name} failed")
|
||||
|
||||
Reference in New Issue
Block a user