Skip to content

Commit

Permalink
Adding timeout to the http client (#54)
Browse files Browse the repository at this point in the history
* template updates

* dependency updates

* add timeout to http client

* version bump
  • Loading branch information
dontseyit authored Aug 9, 2024
1 parent 4353b14 commit f3532cf
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 40 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/ci_release.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .pyproject_generation/pyproject_custom.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "ghga_datasteward_kit"
version = "4.0.0"
version = "4.0.1"
description = "GHGA Data Steward Kit - A utils package for GHGA data stewards."
dependencies = [
"crypt4gh >=1.6, <2",
"hexkit[s3] >=3, <4",
"ghga-transpiler >=2.1.2, <3",
"metldata~=2.0.0",
"metldata~=2.1.1",
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions .template/mandatory_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lock/requirements-dev.txt
lock/requirements.txt

Dockerfile
Dockerfile.debian
config_schema.json
example_config.yaml
LICENSE
Expand Down
1 change: 1 addition & 0 deletions .template/static_files_ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.github/workflows/check_config_docs.yaml
.github/workflows/check_openapi_spec.yaml
.github/workflows/check_readme.yaml
.github/workflows/ci_release.yaml
.readme_generation/readme_template.md
.readme_generation/README.md
scripts/update_config_docs.py
Expand Down
48 changes: 48 additions & 0 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
# for the German Human Genome-Phenome Archive (GHGA)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

## creating building container
FROM python:3.12-slim-bookworm AS builder
# update and install dependencies
RUN apt update
RUN apt upgrade -y
RUN pip install build
# copy code
COPY . /service
WORKDIR /service
# build wheel
RUN python -m build

# creating running container
FROM python:3.12-slim-bookworm
# update and install dependencies
RUN apt update
RUN apt upgrade -y
# copy and install requirements and wheel
WORKDIR /service
COPY --from=builder /service/lock/requirements.txt /service
RUN pip install --no-deps -r requirements.txt
RUN rm requirements.txt
COPY --from=builder /service/dist/ /service
RUN pip install --no-deps *.whl
RUN rm *.whl
# create new user and execute as that user
RUN useradd --create-home appuser
WORKDIR /home/appuser
USER appuser
# set environment
ENV PYTHONUNBUFFERED=1
# Please adapt to package name:
ENTRYPOINT ["my-microservice"]
12 changes: 6 additions & 6 deletions lock/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ hbreader==0.9.1 \
# jsonasobj2
# linkml
# linkml-runtime
hexkit==3.4.0 \
--hash=sha256:3f87d76d746a9e506d458eb729374a8b2facc04f4b40307a2db3b970a8ee4713 \
--hash=sha256:a02f086de15858b8c72852d022c63ffcec555c24cd30b2f6628f0d41fd2fd88a
hexkit==3.5.0 \
--hash=sha256:30a82d170630a615836d6a42116f10a2052a9ae752137419f6abe1286a113a32 \
--hash=sha256:b27599809b94f24e87153667afd9a72f46c46d267c06cafc595d40cdc6c53f89
# via
# ghga-datasteward-kit (pyproject.toml)
# ghga-service-commons
Expand Down Expand Up @@ -760,9 +760,9 @@ mdurl==0.1.2 \
--hash=sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8 \
--hash=sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba
# via markdown-it-py
metldata==2.0.0 \
--hash=sha256:a89c4408681c8f798a4d252187569cc98abbe7e4104bf64092bfca4f5978217b \
--hash=sha256:b5bf87619ee2b7c9665c1852ad9f0190db5ac4daada97017c7b19ebad4501aa0
metldata==2.1.1 \
--hash=sha256:32e0f509186aee26fee0c5b6ee6c650e4affcae6224888457a8af4a2adbf495a \
--hash=sha256:e1dd6be9b589dc2289ae3f9d603738c42092e243ad108f1007f17441ff89e990
# via ghga-datasteward-kit (pyproject.toml)
motor==3.5.1 \
--hash=sha256:1622bd7b39c3e6375607c14736f6e1d498128eadf6f5f93f8786cf17d37062ac \
Expand Down
12 changes: 6 additions & 6 deletions lock/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ hbreader==0.9.1 \
# jsonasobj2
# linkml
# linkml-runtime
hexkit==3.4.0 \
--hash=sha256:3f87d76d746a9e506d458eb729374a8b2facc04f4b40307a2db3b970a8ee4713 \
--hash=sha256:a02f086de15858b8c72852d022c63ffcec555c24cd30b2f6628f0d41fd2fd88a
hexkit==3.5.0 \
--hash=sha256:30a82d170630a615836d6a42116f10a2052a9ae752137419f6abe1286a113a32 \
--hash=sha256:b27599809b94f24e87153667afd9a72f46c46d267c06cafc595d40cdc6c53f89
# via
# -c lock/requirements-dev.txt
# ghga-datasteward-kit (pyproject.toml)
Expand Down Expand Up @@ -771,9 +771,9 @@ mdurl==0.1.2 \
# via
# -c lock/requirements-dev.txt
# markdown-it-py
metldata==2.0.0 \
--hash=sha256:a89c4408681c8f798a4d252187569cc98abbe7e4104bf64092bfca4f5978217b \
--hash=sha256:b5bf87619ee2b7c9665c1852ad9f0190db5ac4daada97017c7b19ebad4501aa0
metldata==2.1.1 \
--hash=sha256:32e0f509186aee26fee0c5b6ee6c650e4affcae6224888457a8af4a2adbf495a \
--hash=sha256:e1dd6be9b589dc2289ae3f9d603738c42092e243ad108f1007f17441ff89e990
# via
# -c lock/requirements-dev.txt
# ghga-datasteward-kit (pyproject.toml)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ classifiers = [
"Intended Audience :: Developers",
]
name = "ghga_datasteward_kit"
version = "4.0.0"
version = "4.0.1"
description = "GHGA Data Steward Kit - A utils package for GHGA data stewards."
dependencies = [
"crypt4gh >=1.6, <2",
"hexkit[s3] >=3, <4",
"ghga-transpiler >=2.1.2, <3",
"metldata~=2.0.0",
"metldata~=2.1.1",
]

[project.license]
Expand Down
2 changes: 1 addition & 1 deletion src/ghga_datasteward_kit/s3_upload/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _download_parts(self, download_url):
LOG.debug("Downloading part number %i. %s", part_no, headers)
try:
with httpx_client() as client:
response = client.get(download_url, timeout=60, headers=headers)
response = client.get(download_url, headers=headers)
yield response.content
except (
Exception,
Expand Down
5 changes: 1 addition & 4 deletions src/ghga_datasteward_kit/s3_upload/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ async def exchange_secret_for_id(
with httpx_client() as client:
headers = {"Authorization": f"Bearer {token}"}
response = client.post(
url=endpoint_url,
json=encrypted_secret.model_dump(),
headers=headers,
timeout=60,
url=endpoint_url, json=encrypted_secret.model_dump(), headers=headers
)

if response.status_code != 200:
Expand Down
3 changes: 2 additions & 1 deletion src/ghga_datasteward_kit/s3_upload/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
LOG = logging.getLogger("s3_upload")
NUM_RETRIES = 5
PART_SIZE = 16 * 1024**2
TIMEOUT = 60


@contextmanager
def httpx_client():
"""Yields a context manager httpx client and closes it afterward"""
transport = httpx.HTTPTransport(retries=NUM_RETRIES)

with httpx.Client(transport=transport) as client:
with httpx.Client(transport=transport, timeout=TIMEOUT) as client:
yield client


Expand Down

0 comments on commit f3532cf

Please sign in to comment.