better error handling

This commit is contained in:
olli 2023-01-17 10:24:32 +01:00
parent f05c859b1c
commit 131641e14a

View File

@ -6,17 +6,21 @@ function g_retrycmd {
# If retrys not set default to 5 times # If retrys not set default to 5 times
[ -z "$g_tries" ] && g_tries=5 [ -z "$g_tries" ] && g_tries=5
>&2 echo "$(g_date_print) Trying $@" #>&2 echo "$(g_date_print) Trying $@"
local g_try=0 local g_try=0
until [ $g_try -eq $g_tries ] until [ $g_try -eq $g_tries ]
do do
((g_try=g_try+1)) ((g_try=g_try+1))
>&2 echo "$(g_date_print) Try $g_try of $g_tries" #>&2 echo "$(g_date_print) Try $g_try of $g_tries"
echo "$@" >$g_tmp/g_retrycmd.cmd echo "$@" >$g_tmp/g_retrycmd.cmd
bash $g_tmp/g_retrycmd.cmd && break bash $g_tmp/g_retrycmd.cmd && break
g_return=$? g_return=$?
[ $g_try -eq $g_tries ] && return $g_return if [ $g_try -eq $g_tries ]
then
[ -z "$g_return" ] || g_echo_error "${FUNCNAME}: $@ failed all $g_tries tries"
return $g_return
fi
sleep $g_tries_delay sleep $g_tries_delay
done done