Skip to content

Commit

Permalink
Merge pull request #125 from shanejbrown/main
Browse files Browse the repository at this point in the history
Add retry around writing and loading cache
  • Loading branch information
shanejbrown authored Feb 22, 2024
2 parents 5d97c35 + 0d637b4 commit be434e6
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit be434e6

Please sign in to comment.