Changed retry logic on buildah build
- Enable logging of retries as warnings
- Increase number of retries to 5 and switched delay from 1s
to exponential, capping at 60s
Example:
WARNING...:Finished call to '__main__.foo' after 9.201(s), this was the 6th time calling it.
Change-Id: If13571b9e21251ced9a43fc1cc7f7d69fad06f0a
Tested-By: https://review.rdoproject.org/r/#/c/29917/
(cherry picked from commit a584a5bd4c
)
This commit is contained in:
parent
bb47fae445
commit
4fd72262b0
|
@ -126,13 +126,16 @@ class BuildahBuilder(base.BaseBuilder):
|
|||
if self.push_containers:
|
||||
self.push(self._get_destination(container_name))
|
||||
except Exception as e:
|
||||
self.log.exception(e)
|
||||
LOG.exception(e)
|
||||
raise
|
||||
|
||||
@tenacity.retry( # Retry up to 3 times with 1 second delay
|
||||
@tenacity.retry(
|
||||
# Retry up to 5 times: 0, 1, 5, 21, 85
|
||||
# http://exponentialbackoffcalculator.com/
|
||||
reraise=True,
|
||||
wait=tenacity.wait_fixed(1),
|
||||
stop=tenacity.stop_after_attempt(3)
|
||||
wait=tenacity.wait_random_exponential(multiplier=4, max=60),
|
||||
stop=tenacity.stop_after_attempt(5),
|
||||
before_sleep=tenacity.after_log(LOG, logging.WARNING)
|
||||
)
|
||||
def build(self, container_name, container_build_path):
|
||||
"""Build an image from a given directory.
|
||||
|
@ -157,7 +160,8 @@ class BuildahBuilder(base.BaseBuilder):
|
|||
self._get_destination(container_name),
|
||||
container_build_path])
|
||||
args = self.buildah_cmd + bud_args
|
||||
print("Building %s image with: %s" % (container_name, ' '.join(args)))
|
||||
LOG.info("Building %s image with: %s" %
|
||||
(container_name, ' '.join(args)))
|
||||
process.execute(
|
||||
*args,
|
||||
check_exit_code=True,
|
||||
|
@ -168,7 +172,8 @@ class BuildahBuilder(base.BaseBuilder):
|
|||
@tenacity.retry( # Retry up to 10 times with jittered exponential backoff
|
||||
reraise=True,
|
||||
wait=tenacity.wait_random_exponential(multiplier=1, max=15),
|
||||
stop=tenacity.stop_after_attempt(10)
|
||||
stop=tenacity.stop_after_attempt(10),
|
||||
before_sleep=tenacity.after_log(LOG, logging.WARNING)
|
||||
)
|
||||
def push(self, destination):
|
||||
"""Push an image to a container registry.
|
||||
|
@ -183,7 +188,8 @@ class BuildahBuilder(base.BaseBuilder):
|
|||
# else than a Docker registry.
|
||||
args = self.buildah_cmd + ['push', '--tls-verify=False', destination,
|
||||
'docker://' + destination]
|
||||
print("Pushing %s image with: %s" % (destination, ' '.join(args)))
|
||||
LOG.info("Pushing %s image with: %s" %
|
||||
(destination, ' '.join(args)))
|
||||
process.execute(*args, run_as_root=False, use_standard_locale=True)
|
||||
|
||||
def build_all(self, deps=None):
|
||||
|
|
Loading…
Reference in New Issue