Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the post timeout for uploading #1165

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions openhtf/output/callbacks/mfg_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
import time
import zlib

from google.auth import credentials as credentials_lib
from google.auth.transport import requests
from google.oauth2 import service_account

from openhtf.output import callbacks
from openhtf.output.proto import guzzle_pb2
from openhtf.output.proto import test_runs_converter

from openhtf.output.proto import guzzle_pb2


_MFG_INSPECTOR_UPLOAD_TIMEOUT = 60 * 5


class UploadFailedError(Exception):
"""Raised when an upload to mfg-inspector fails."""
Expand All @@ -34,20 +38,29 @@ class InvalidTestRunError(Exception):
"""Raised if test run is invalid."""


def _send_mfg_inspector_request(envelope_data, credentials, destination_url):
def _send_mfg_inspector_request(
envelope_data: bytes,
credentials: credentials_lib.Credentials,
destination_url: str,
):
"""Send upload http request. Intended to be run in retry loop."""
logging.info('Uploading result...')

with requests.AuthorizedSession(credentials) as authed_session:
response = authed_session.request(
'POST', destination_url, data=envelope_data)
'POST',
destination_url,
data=envelope_data,
timeout=_MFG_INSPECTOR_UPLOAD_TIMEOUT,
)

try:
result = response.json()
except Exception:
logging.warning('Upload failed with response %s: %s', response,
response.text)
raise UploadFailedError(response, response.text)
except Exception as e:
logging.exception(
'Upload failed with response %s: %s', response, response.text
)
raise UploadFailedError(response, response.text) from e

if response.status_code == 200:
return result
Expand Down
Loading