Skip to content

Commit 40a3fe4

Browse files
committed
chore(index_and_notify): use exc_info and logger_context with logger.error
1 parent 8d99e16 commit 40a3fe4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

api/management/commands/index_and_notify.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
from deployments.models import ERU, Personnel, PersonnelDeployment
2626
from main.sentry import SentryMonitor
27+
from main.utils import logger_context
2728
from notifications.hello import get_hello
2829
from notifications.models import RecordType, Subscription, SubscriptionType, SurgeAlert
2930
from notifications.notification import send_notification
@@ -922,12 +923,16 @@ def index_records(self, records, to_create=True):
922923
def bulk(self, actions):
923924
try:
924925
created, errors = bulk(client=ES_CLIENT, actions=actions)
925-
if len(errors):
926-
logger.error("Produced the following errors:")
927-
logger.error("[%s]" % ", ".join(map(str, errors)))
928-
except Exception as e:
929-
logger.error("Could not index records")
930-
logger.error("%s..." % str(e)[:512])
926+
if errors:
927+
logger.error(
928+
"(index_and_notify:bulk): produced errors:",
929+
extra=logger_context(dict(errors=errors)),
930+
)
931+
except Exception:
932+
logger.error(
933+
"(index_and_notify:bulk): could not index records",
934+
exc_info=True,
935+
)
931936

932937
# Remove items in a queryset where updated_at == created_at.
933938
# This leaves us with only ones that have been modified.

0 commit comments

Comments
 (0)