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 to docker_run #6514

Merged
merged 1 commit into from
Apr 29, 2020
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
16 changes: 16 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from six import string_types
from six.moves.urllib.parse import urlparse
from tenacity import retry, stop_after_attempt, wait_fixed

from .conditions import CheckDockerLogs
from .env import environment_run, get_state, save_state
Expand Down Expand Up @@ -104,6 +105,8 @@ def docker_run(
conditions=None,
env_vars=None,
wrappers=None,
attempts=None,
attempts_wait=1,
):
"""This utility provides a convenient way to safely set up and tear down Docker environments.

Expand Down Expand Up @@ -136,6 +139,10 @@ def docker_run(
:param env_vars: A dictionary to update ``os.environ`` with during execution.
:type env_vars: ``dict``
:param wrappers: A list of context managers to use during execution.
:param attempts: Number attempts to run `up`
:type attempts: int
:param attempts_wait: Time wait between attempts
:type attempts_wait: int
"""
if compose_file and up:
raise TypeError('You must select either a compose file or a custom setup callable, not both.')
Expand All @@ -155,6 +162,15 @@ def docker_run(
set_up = up
tear_down = down

if attempts is not None:
saved_set_up = set_up

@retry(wait=wait_fixed(attempts_wait), stop=stop_after_attempt(attempts))
def set_up_with_retry():
return saved_set_up()

set_up = set_up_with_retry

docker_conditions = []

if log_patterns is not None:
Expand Down