Skip to content

Commit

Permalink
Add error handling when updating non-existing record
Browse files Browse the repository at this point in the history
It can happen that a drone does not reach the AvailableState but only
the DownState. In this case, updating the record in Auditor does not
work, because no record has been created. In this case, Auditor returns
a 400 BAD REQUEST. This commit adds error handling for this specific
case. Other exceptions will not be handled.
  • Loading branch information
QuantumDancer committed Aug 1, 2023
1 parent 2bf9dcb commit 2b5a80a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tardis/plugins/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@

import logging
import pytz
import re
from tzlocal import get_localzone


REQWEST_ERROR = re.compile(r"Reqwest Error: HTTP status client error \((\d{3}).*\).*")


class Auditor(Plugin):
"""
The :py:class:`~tardis.plugins.auditor.Auditor` plugin is a collector for the
Expand Down Expand Up @@ -85,7 +89,21 @@ async def notify(self, state: State, resource_attributes: AttributeDict) -> None
.replace(tzinfo=self._local_timezone)
.astimezone(pytz.utc)
)
await self._client.update(record)
try:
await self._client.update(record)
except RuntimeError as e:
reqwest_error_match = REQWEST_ERROR.match(str(e))
if reqwest_error_match:
http_error_code = reqwest_error_match.group(1)
if http_error_code == "400":
self.logger.debug(
f"Could not update record {record.record_id}, "
"it probably does not exist in the database"
)
else:
raise
else:
raise

def construct_record(self, resource_attributes: AttributeDict):
"""
Expand Down

0 comments on commit 2b5a80a

Please sign in to comment.