Skip to content

Commit

Permalink
catch all the Exceptions; log errors and warnings accordingly
Browse files Browse the repository at this point in the history
Lots can go wrong in
helpix_utils.create_localization_for_multiorder_fits
b/c it downloads and processes a fits file from GraceDB.
Uncaught exceptions were putting the Kafka client in a bad
state. So, we catch everything here to avoid that.
  • Loading branch information
phycodurus committed Mar 1, 2023
1 parent efcfa54 commit 0ccd944
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions tom_nonlocalizedevents/alertstream_handlers/gw_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,29 @@ def handle_message(message):
if nle_created:
logger.info(f"Ingested a new GW event with id {fields['TRIGGER_NUM']} from alertstream")
# Next attempt to ingest and build the localization of the event
localization = create_localization_for_multiorder_fits(
nonlocalizedevent=nonlocalizedevent,
multiorder_fits_url=get_moc_url_from_skymap_fits_url(fields['SKYMAP_FITS_URL'])
)
try:
localization = create_localization_for_multiorder_fits(
nonlocalizedevent=nonlocalizedevent,
multiorder_fits_url=get_moc_url_from_skymap_fits_url(fields['SKYMAP_FITS_URL'])
)
except Exception as e:
localization = None
logger.error(f'Could not create EventLocalization for messsage: {fields}. Exception: {e}')
logger.error(traceback.format_exc())

# Now ingest the sequence for that event
EventSequence.objects.update_or_create(
event_sequence, es_created = EventSequence.objects.update_or_create(
nonlocalizedevent=nonlocalizedevent,
localization=localization,
sequence_id=fields['SEQUENCE_NUM'],
defaults={
'event_subtype': fields['NOTICE_TYPE']
}
)
if es_created and localization is None:
warning_msg = (f'{"Creating" if es_created else "Updating"} EventSequence without EventLocalization:'
f'{event_sequence} for NonLocalizedEvent: {nonlocalizedevent}')
logger.warning(warning_msg)


def handle_retraction(message):
Expand Down

0 comments on commit 0ccd944

Please sign in to comment.