我在美国西部有一个Azure Storage帐户,启用了Geo-Replication以与美国东部同步,并且我希望使用bash脚本按需执行故障转移。
我定义了以下函数
_STORAGE_ACCOUNT_FAILOVER () {
echo "Storage account failover is initiated.."
az storage account failover --name $STORAGEACCOUNT --no-wait --yes
echo "Storage account failover is completed successfully.."
}在尝试执行上面的函数时,我得到了以下错误
ERROR: (ResourceCollectionRequestsThrottled) Operation 'Microsoft.Storage/storageAccounts/read' failed as server encountered too many requests.
Please try after '17' seconds. Tracking Id is ''.我想实现重试逻辑,以防出现任何问题?如何实现重试逻辑?
就像这样
_STORAGE_ACCOUNT_FAILOVER () {
echo "Storage account failover is initiated.."
performFailover:
az storage account failover --name $STORAGEACCOUNT --no-wait --yes
if [ "$?" -ne 0 ]; then
goto performFailover;
fi
echo "Storage account failover is completed successfully.."
}或者像这样的东西
_STORAGE_ACCOUNT_FAILOVER () {
echo "Storage account failover is initiated.."
while true; do
az storage account failover --name $STORAGEACCOUNT --no-wait --yes
if [ "$?" -eq 0 ]; then
break;
fi
sleep 30s
done
echo "Storage account failover is completed successfully.."
}发布于 2021-02-24 18:30:39
人类可读的错误消息有些问题;您能否以机器可读的形式获得所请求的重试等待?
假设az在超时时设置了一个非零的退出代码,下面是一个简单的草图。(如果幸运的话,对于这个特定的错误,它会有一个唯一的退出代码。)
_STORAGE_ACCOUNT_FAILOVER () {
echo "$0: Storage account failover initiated" >&2
while true; do
if result=$(az storage account failover \
--name "$STORAGEACCOUNT" \
--no-wait --yes 2>&1 >/dev/null)
then
break
else
rc=$?
case $result in
*"Please try after '"*)
seconds=${result#*Please try after \'}
seconds=${seconds%%\'*}
wait "$seconds"
;;
*) echo "$0: $result" >&2
exit $rc
;;
esac
fi
done
echo "$0: Storage account failover completed successfully" >&2
}注意我们如何从az命令中捕获标准错误并解析出超时消息,或者如果不能,则返回错误。还要注意如何将所有诊断消息打印为标准错误,并以电报形式格式化,但始终在消息中包含脚本的名称,以便您可以在脚本调用脚本调用脚本等情况下辨别哪个脚本失败。
https://stackoverflow.com/questions/66348120
复制相似问题