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

cli: add retry-loop when uploading files failed #447

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
44 changes: 31 additions & 13 deletions reana_client/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import os
import traceback
from functools import partial
import time
import click

import requests
from bravado.exception import HTTPError
from reana_client.config import ERROR_MESSAGES, WORKFLOW_ENGINES
from reana_client.errors import FileDeletionError, FileUploadError
from reana_client.utils import _validate_reana_yaml, is_uuid_v4
from reana_commons.api_client import get_current_api_client
from reana_commons.config import REANA_API_RETRY_NUMBER
from reana_commons.errors import REANASecretAlreadyExists, REANASecretDoesNotExist
from werkzeug.local import LocalProxy

Expand Down Expand Up @@ -550,19 +553,34 @@ def upload_to_server(workflow, paths, access_token):
"'{}' is an absolute filepath.".format(os.path.basename(fname))
)
logging.info("Uploading '{}' ...".format(fname))
try:
upload_file(workflow, f, save_path, access_token)
logging.info("File '{}' was successfully uploaded.".format(fname))
if symlink:
save_path = "symlink:{}".format(save_path)
return [save_path]
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
logging.info(
"Something went wrong while uploading {}".format(fname)
)
raise e
for retry in range(REANA_API_RETRY_NUMBER + 1):
if retry == REANA_API_RETRY_NUMBER:
raise Exception(
"Failed to upload {}. Number of retries exceeded {}".format(
fname, REANA_API_RETRY_NUMBER
)
)
try:
upload_file(workflow, f, save_path, access_token)
logging.info(
"File '{}' was successfully uploaded.".format(fname)
)
if symlink:
save_path = "symlink:{}".format(save_path)
return [save_path]
except Exception as e:
logging.debug(traceback.format_exc())
logging.debug(str(e))
logging.info(
"Something went wrong while uploading {}".format(fname)
)
if str(e) == "60 per 1 minute":
time.sleep(61)
continue
if str(e) == "1000 per 1 hour":
time.sleep(3601)
continue
raise e


def get_workflow_parameters(workflow, access_token):
Expand Down