Skip to content

Commit

Permalink
Merge pull request #74 from sanger/Y24-016-fix-rapid-reconnects-when-…
Browse files Browse the repository at this point in the history
…traction-unavailable

Y24-016: Raise TransientRabbitError if the Traction API requests fail
  • Loading branch information
sdjmchattie authored Mar 18, 2024
2 parents cc2ae5a + 75d167f commit c8b1edb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion tol_lab_share/messages/traction/qc_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from requests import codes, post

from lab_share_lib.exceptions import TransientRabbitError
from tol_lab_share import error_codes
from tol_lab_share.constants import OUTPUT_TRACTION_MESSAGE_SOURCE
from tol_lab_share.error_codes import ErrorCode
Expand Down Expand Up @@ -202,7 +203,13 @@ def send(self, url: str) -> bool:
"""
headers = {"Content-type": "application/vnd.api+json", "Accept": "application/vnd.api+json"}

r = post(url, headers=headers, data=dumps(self.payload(), default=str), verify=self._validate_certificates)
try:
r = post(url, headers=headers, data=dumps(self.payload(), default=str), verify=self._validate_certificates)
except Exception as ex:
logger.critical(f"Error submitting {self.__class__.__name__} to the Traction API.")
logger.exception(ex)

raise TransientRabbitError(f"There was an error POSTing the {self.__class__.__name__} to the Traction API.")

self._sent = r.status_code == codes.created
if not self._sent:
Expand Down
12 changes: 11 additions & 1 deletion tol_lab_share/messages/traction/reception_message.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from functools import singledispatchmethod
import itertools
import logging
from typing import Callable, Any
from json import dumps
from datetime import datetime
from requests import post, codes
from lab_share_lib.exceptions import TransientRabbitError
from tol_lab_share.messages.properties import MessageProperty
from tol_lab_share.messages.properties.simple import Value
from tol_lab_share.constants import (
Expand All @@ -15,6 +17,8 @@
from tol_lab_share.helpers import get_config
from tol_lab_share.messages.rabbit.published import CreateLabwareFeedbackMessage

logger = logging.getLogger(__name__)


class TractionReceptionMessageRequest:
"""Class that manages the information of a single Traction request instance as part of the Traction message."""
Expand Down Expand Up @@ -317,7 +321,13 @@ def send(self, url: str) -> bool:
"""
headers = {"Content-type": "application/vnd.api+json", "Accept": "application/vnd.api+json"}

r = post(url, headers=headers, data=dumps(self.payload()), verify=self._validate_certificates)
try:
r = post(url, headers=headers, data=dumps(self.payload()), verify=self._validate_certificates)
except Exception as ex:
logger.critical(f"Error submitting {self.__class__.__name__} to the Traction API.")
logger.exception(ex)

raise TransientRabbitError(f"There was an error POSTing the {self.__class__.__name__} to the Traction API.")

self._sent = r.status_code == codes.created
if not self._sent:
Expand Down

0 comments on commit c8b1edb

Please sign in to comment.