Skip to content

Commit

Permalink
Merge pull request #202 from lsst/tickets/DM-43522
Browse files Browse the repository at this point in the history
DM-43522:Remove too large alert packet write to disk
  • Loading branch information
bsmartradio committed Mar 27, 2024
2 parents 0542d4b + 1731013 commit adfb4da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions python/lsst/ap/association/packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class PackageAlertsConfig(pexConfig.Config):
default=False,
)

doWriteFailedAlerts = pexConfig.Field(
dtype=bool,
doc="If an alert cannot be sent when doProduceAlerts is set, "
"write it to disk for debugging purposes.",
default=False,
)


class PackageAlertsTask(pipeBase.Task):
"""Tasks for packaging Dia and Pipelines data into Avro alert packages.
Expand Down Expand Up @@ -320,9 +327,11 @@ def produceAlerts(self, alerts, ccdVisitId):

except KafkaException as e:
self.log.warning('Kafka error: {}, message was {} bytes'.format(e, sys.getsizeof(alertBytes)))
with open(os.path.join(self.config.alertWriteLocation,
f"{ccdVisitId}_{alert['alertId']}.avro"), "wb") as f:
f.write(alertBytes)

if self.config.doWriteFailedAlerts:
with open(os.path.join(self.config.alertWriteLocation,
f"{ccdVisitId}_{alert['alertId']}.avro"), "wb") as f:
f.write(alertBytes)

self.producer.flush()

Expand Down
2 changes: 1 addition & 1 deletion tests/test_packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def mock_produce(*args, **kwargs):
else:
return

packConfig = PackageAlertsConfig(doProduceAlerts=True)
packConfig = PackageAlertsConfig(doProduceAlerts=True, doWriteFailedAlerts=True)
packageAlerts = PackageAlertsTask(config=packConfig)

patcher = patch("builtins.open")
Expand Down

0 comments on commit adfb4da

Please sign in to comment.