Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bskjon committed Nov 6, 2024
1 parent 3712ebb commit 717350e
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions apps/pyMetadata/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def run(self) -> None:
else:
logging.debug("A successful connection has been made!")

event: MediaEvent | None = None
try:
rows = self.getEventsAvailable(connection=self.connection)
if (len(rows) == 0):
Expand All @@ -183,7 +184,7 @@ def run(self) -> None:
============================================================================\n"""
logger.info(logMessage)

event: MediaEvent = json_to_media_event(row["data"])
event = json_to_media_event(row["data"])
producedEvent = asyncio.run(MetadataEventHandler(event).run())

producedMessage = f"""
Expand All @@ -201,20 +202,23 @@ def run(self) -> None:
except Exception as e:
"""Produce failure here"""
logger.exception(e)
producedEvent = MediaEvent(
metadata = EventMetadata(
referenceId=event.metadata.referenceId,
eventId=str(uuid.uuid4()),
derivedFromEventId=event.metadata.eventId,
status= "Failed",
created= datetime.now().isoformat(),
source="metadataApp"
),
data=None,
eventType="EventMediaMetadataSearchPerformed"
)
self.storeProducedEvent(connection=self.connection, event=producedEvent)

try:
producedEvent = MediaEvent(
metadata = EventMetadata(
referenceId=event.metadata.referenceId,
eventId=str(uuid.uuid4()),
derivedFromEventId=event.metadata.eventId,
status= "Failed",
created= datetime.now().isoformat(),
source="metadataApp"
),
data=None,
eventType="EventMediaMetadataSearchPerformed"
)
self.storeProducedEvent(connection=self.connection, event=producedEvent)
except Exception as iex:
logger.error("Failed to push error to database..")

except mysql.connector.Error as err:
logger.error("Database error: %s", err)

Expand Down

0 comments on commit 717350e

Please sign in to comment.