Skip to content
代码片段 群组 项目
提交 81c5e0e4 编辑于 作者: David Dieulivol's avatar David Dieulivol 提交者: Rémy Coutable
浏览文件

Introduce Exponential retry for review-apps commands

上级 29174511
No related branches found
No related tags found
无相关合并请求
...@@ -130,7 +130,7 @@ function disable_sign_ups() { ...@@ -130,7 +130,7 @@ function disable_sign_ups() {
# Create the root token + Disable sign-ups # Create the root token + Disable sign-ups
local disable_signup_rb="token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups'); token.set_token('${REVIEW_APPS_ROOT_TOKEN}'); begin; token.save!; rescue(ActiveRecord::RecordNotUnique); end; Gitlab::CurrentSettings.current_application_settings.update!(signup_enabled: false)" local disable_signup_rb="token = User.find_by_username('root').personal_access_tokens.create(scopes: [:api], name: 'Token to disable sign-ups'); token.set_token('${REVIEW_APPS_ROOT_TOKEN}'); begin; token.save!; rescue(ActiveRecord::RecordNotUnique); end; Gitlab::CurrentSettings.current_application_settings.update!(signup_enabled: false)"
if (retry "run_task \"${disable_signup_rb}\""); then if (retry_exponential "run_task \"${disable_signup_rb}\""); then
echoinfo "Sign-ups have been disabled successfully." echoinfo "Sign-ups have been disabled successfully."
else else
echoerr "Sign-ups are still enabled!" echoerr "Sign-ups are still enabled!"
......
...@@ -10,6 +10,28 @@ function retry() { ...@@ -10,6 +10,28 @@ function retry() {
return 0 return 0
fi fi
done done
return 1
}
# Retry after 2s, 4s, 8s, 16s, 32, 64s, 128s
function retry_exponential() {
if eval "$@"; then
return 0
fi
local sleep_time=0
# The last try will be after 2**7 = 128 seconds (2min8s)
for i in 1 2 3 4 5 6 7; do
sleep_time=$((2 ** i))
echo "Sleep for $sleep_time seconds..."
sleep $sleep_time
echo "[$(date '+%H:%M:%S')] Attempt #$i..."
if eval "$@"; then
return 0
fi
done
return 1 return 1
} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册