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

Add retry around writing and loading cache #125

Merged
merged 1 commit into from
Feb 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
14 changes: 11 additions & 3 deletions buildrunner/docker/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
from types import GeneratorType
from typing import Optional

from docker.utils import compare_version
from retry import retry
import docker.errors
import six
from docker.utils import compare_version
import timeout_decorator

from buildrunner.docker import (
Expand All @@ -36,6 +37,7 @@
tempfile,
)

CACHE_NUM_RETRIES = 2
CACHE_TIMEOUT_SECONDS = 240


Expand Down Expand Up @@ -329,7 +331,10 @@ def _get_cache_file_from_prefix(

return local_cache_archive_match

@timeout_decorator.timeout(CACHE_TIMEOUT_SECONDS, BuildRunnerCacheTimeout)
@retry(exceptions=BuildRunnerCacheTimeout, tries=CACHE_NUM_RETRIES)
@timeout_decorator.timeout(
seconds=CACHE_TIMEOUT_SECONDS, timeout_exception=BuildRunnerCacheTimeout
)
def _put_cache_in_container(self, docker_path: str, file_obj: io.IOBase) -> bool:
"""
Insert a file or folder in an existing container using a tar archive as
Expand Down Expand Up @@ -403,7 +408,10 @@ def restore_caches(self, logger: ContainerLogger, caches: OrderedDict) -> None:
release_flock(file_obj, logger)
logger.write("Cache was put into the container. Released file lock.")

@timeout_decorator.timeout(CACHE_TIMEOUT_SECONDS, BuildRunnerCacheTimeout)
@retry(exceptions=BuildRunnerCacheTimeout, tries=CACHE_NUM_RETRIES)
@timeout_decorator.timeout(
seconds=CACHE_TIMEOUT_SECONDS, timeout_exception=BuildRunnerCacheTimeout
)
def _write_cache(self, docker_path: str, file_obj: io.IOBase):
"""
Write cache locally from file or folder in a running container
Expand Down
Loading