Skip to content

Commit

Permalink
Add retry to parts of the import script which were failing from time …
Browse files Browse the repository at this point in the history
…to time
  • Loading branch information
garbas committed Dec 7, 2020
1 parent bae5a92 commit b55a9f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 10 additions & 2 deletions import-scripts/import_scripts/channel.py
@@ -1,6 +1,8 @@
import backoff # type: ignore
import boto3 # type: ignore
import botocore # type: ignore
import botocore.client # type: ignore
import botocore.errorfactory # type: ignore
import click
import click_log # type: ignore
import dictdiffer # type: ignore
Expand All @@ -14,6 +16,7 @@
import pypandoc # type: ignore
import re
import requests
import requests.exceptions
import shlex
import subprocess
import sys
Expand Down Expand Up @@ -262,6 +265,7 @@ def parse_query(text):
return tokens


@backoff.on_exception(backoff.expo, botocore.errorfactory.NoSuchKey)
def get_last_evaluation(prefix):
logger.debug(f"Retrieving last evaluation for {prefix} prefix.")

Expand Down Expand Up @@ -302,6 +306,7 @@ def get_last_evaluation(prefix):
return evaluation


@backoff.on_exception(backoff.expo, requests.exceptions.RequestException)
def get_evaluation_builds(evaluation_id):
logger.debug(
f"get_evaluation_builds: Retrieving list of builds for {evaluation_id} evaluation id"
Expand Down Expand Up @@ -388,6 +393,7 @@ def remove_attr_set(name):
return name


@backoff.on_exception(backoff.expo, subprocess.CalledProcessError)
def get_packages_raw(evaluation):
logger.debug(
f"get_packages: Retrieving list of packages for '{evaluation['git_revision']}' revision"
Expand Down Expand Up @@ -497,9 +503,10 @@ def gen():
return len(packages), gen


@backoff.on_exception(backoff.expo, subprocess.CalledProcessError)
def get_options_raw(evaluation):
logger.debug(
f"get_packages: Retrieving list of options for '{evaluation['git_revision']}' revision"
f"get_options: Retrieving list of options for '{evaluation['git_revision']}' revision"
)
result = subprocess.run(
shlex.split(
Expand All @@ -521,10 +528,11 @@ def get_options(evaluation):
options = get_options_raw(evaluation)

@functools.lru_cache(maxsize=None)
@backoff.on_exception(backoff.expo, subprocess.CalledProcessError)
def jsonToNix(value):
result = subprocess.run(
shlex.split(
"nix-instantiate --eval --strict -E 'builtins.fromJSON (builtins.readFile /dev/stdin)'"
"nix-instantiate --eval --strict -E 'builtins.fromJSON (builtins.areadFile /dev/stdin)'"
),
input=value.encode(),
stdout=subprocess.PIPE,
Expand Down
14 changes: 13 additions & 1 deletion import-scripts/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions import-scripts/pyproject.toml
Expand Up @@ -21,6 +21,7 @@ boto3 = "^1.14.5"
tqdm = "^4.46.1"
pypandoc = "^1.5"
dictdiffer = "^0.8.1"
backoff = "^1.10.0"

[tool.poetry.dev-dependencies]
ipdb = "^0.13.2"
Expand Down

0 comments on commit b55a9f9

Please sign in to comment.