33
44from django .core .management .base import BaseCommand
55from django .db import OperationalError as DjangoOperationalError
6- from elasticsearch6 .exceptions import ConnectionError as ElasticConnectionError
6+ from elasticsearch6 .exceptions import ConnectionError as Elastic6ConnectionError
7+ from elasticsearch8 .exceptions import ConnectionError as Elastic8ConnectionError
78from psycopg2 import OperationalError as PostgresOperationalError
89
910from framework .celery_tasks import app as celery_app
1011import framework .sentry
1112from osf .metrics .reporters import AllMonthlyReporters
13+ from osf .metrics .reports import MonthlyReport
1214from osf .metrics .utils import YearMonth
1315
1416
1719
1820_CONTINUE_AFTER_ERRORS = (
1921 DjangoOperationalError ,
20- ElasticConnectionError ,
22+ Elastic6ConnectionError ,
23+ Elastic8ConnectionError ,
2124 PostgresOperationalError ,
2225)
2326
@@ -70,11 +73,7 @@ def schedule_monthly_reporter(
7073
7174@celery_app .task (
7275 name = 'management.commands.monthly_reporter_do' ,
73- autoretry_for = (
74- DjangoOperationalError ,
75- ElasticConnectionError ,
76- PostgresOperationalError ,
77- ),
76+ autoretry_for = _CONTINUE_AFTER_ERRORS ,
7877 max_retries = 5 ,
7978 retry_backoff = True ,
8079)
@@ -87,7 +86,8 @@ def monthly_reporter_do(reporter_key: str, yearmonth: str, report_kwargs: dict):
8786
8887 _reports = _reporter .report (** report_kwargs )
8988 for _report in _reports :
90- _report .report_yearmonth = _reporter .yearmonth
89+ if isinstance (_report , MonthlyReport ) and (_report .report_yearmonth is None ):
90+ _report .report_yearmonth = _reporter .yearmonth
9191 _report .save ()
9292 _followup_task = _reporter .followup_task (_report )
9393 if _followup_task is not None :
0 commit comments