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 with timeout #76

Merged
merged 1 commit into from
Nov 2, 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
27 changes: 23 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ FORCE_UPDATE="${INPUT_FORCE_UPDATE}"
DELAY_EXIT=false

TIME_OUT="${INPUT_TIMEOUT}"
RETRY_TIMES=3

function err_exit {
echo -e "\033[31m $1 \033[0m"
Expand Down Expand Up @@ -81,6 +82,24 @@ else
err_exit "Unknown src args, the `src` should be `[github|gittee]/account`"
fi

function retry {
local retries=$RETRY_TIMES
local count=0
until timeout $TIME_OUT "$@"; do
exit=$?
wait=$((2 ** $count))
count=$(($count + 1))
if [ $count -lt $retries ]; then
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
sleep $wait
else
echo "Retry $count/$retries exited $exit, no more retries left."
return $exit
fi
done
return 0
}

function get_all_repo_names
{
PAGE_NUM=100
Expand Down Expand Up @@ -128,7 +147,7 @@ function clone_repo
{
echo -e "\033[31m(0/3)\033[0m" "Downloading..."
if [ ! -d "$1" ]; then
timeout $TIME_OUT git clone $SRC_REPO_BASE_URL$SRC_ACCOUNT/$1.git
retry git clone $SRC_REPO_BASE_URL$SRC_ACCOUNT/$1.git
fi
cd $1
}
Expand All @@ -151,17 +170,17 @@ function create_repo
function update_repo
{
echo -e "\033[31m(1/3)\033[0m" "Updating..."
timeout $TIME_OUT git pull -p
retry git pull -p
}

function import_repo
{
echo -e "\033[31m(2/3)\033[0m" "Importing..."
git remote set-head origin -d
if [[ "$FORCE_UPDATE" == "true" ]]; then
timeout $TIME_OUT git push -f $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
retry git push -f $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
else
timeout $TIME_OUT git push $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
retry git push $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
fi
}

Expand Down