Skip to content

Commit

Permalink
log database/connection errors when rescheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Nov 25, 2024
1 parent 9fa7e10 commit 2ea9f01
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions osf/management/commands/monthly_reporters_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from psycopg2 import OperationalError as PostgresOperationalError

from framework.celery_tasks import app as celery_app
import framework.sentry
from osf.metrics.reporters import AllMonthlyReporters
from osf.metrics.utils import YearMonth


logger = logging.getLogger(__name__)


_RETRY_ERRORS = (
_CONTINUE_AFTER_ERRORS = (
DjangoOperationalError,
ElasticConnectionError,
PostgresOperationalError,
Expand Down Expand Up @@ -47,7 +48,6 @@ def schedule_monthly_reporter(
):
_reporter = _get_reporter(reporter_key, yearmonth)
_last_kwargs = None
_done = False
try:
for _kwargs in _reporter.iter_report_kwargs(continue_after=continue_after):
monthly_reporter_do.apply_async(kwargs={
Expand All @@ -56,9 +56,11 @@ def schedule_monthly_reporter(
'report_kwargs': _kwargs,
})
_last_kwargs = _kwargs
_done = True
except _RETRY_ERRORS:
if not _done and (_last_kwargs is not None):
except _CONTINUE_AFTER_ERRORS as _error:
# let the celery task succeed but log the error
framework.sentry.log_exception(_error)
# schedule another task to continue scheduling
if _last_kwargs is not None:
schedule_monthly_reporter.apply_async(kwargs={
'yearmonth': yearmonth,
'reporter_key': reporter_key,
Expand Down

0 comments on commit 2ea9f01

Please sign in to comment.