Avoid caching when API call fails (#164)

This commit is contained in:
Stefan Agner 2025-04-22 12:28:35 +02:00 committed by GitHub
parent d70505aada
commit 445707a903
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 104 additions and 0 deletions

View file

@ -164,6 +164,10 @@ function bashio::addons() {
info=$(bashio::cache.get 'addons.list')
else
info=$(bashio::api.supervisor GET "/addons" false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get addons from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "addons.list" "${info}"
fi
else
@ -171,6 +175,10 @@ function bashio::addons() {
info=$(bashio::cache.get "addons.${slug}.info")
else
info=$(bashio::api.supervisor GET "/addons/${slug}/info" false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get addon info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "addons.${slug}.info" "${info}"
fi
fi
@ -1202,6 +1210,10 @@ function bashio::addon.stats() {
info=$(bashio::cache.get "addons.${slug}.stats")
else
info=$(bashio::api.supervisor GET "/addons/${slug}/stats" false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get addon stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "addons.${slug}.stats" "${info}"
fi

View file

@ -77,6 +77,10 @@ function bashio::audio() {
info=$(bashio::cache.get 'audio.info')
else
info=$(bashio::api.supervisor GET /audio/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get audio info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'audio.info' "${info}"
fi
@ -147,6 +151,10 @@ function bashio::audio.stats() {
info=$(bashio::cache.get 'audio.stats')
else
info=$(bashio::api.supervisor GET /audio/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get audio stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'audio.stats' "${info}"
fi

View file

@ -51,6 +51,10 @@ function bashio::cli() {
info=$(bashio::cache.get 'cli.info')
else
info=$(bashio::api.supervisor GET /cli/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get cli info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'cli.info' "${info}"
fi
@ -113,6 +117,10 @@ function bashio::cli.stats() {
info=$(bashio::cache.get 'cli.stats')
else
info=$(bashio::api.supervisor GET /cli/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get cli stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'cli.stats' "${info}"
fi

View file

@ -99,6 +99,10 @@ function bashio::core() {
info=$(bashio::cache.get 'core.info')
else
info=$(bashio::api.supervisor GET /core/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get core info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'core.info' "${info}"
fi
@ -249,6 +253,10 @@ function bashio::core.stats() {
info=$(bashio::cache.get 'core.stats')
else
info=$(bashio::api.supervisor GET /core/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get core stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'core.stats' "${info}"
fi

View file

@ -77,6 +77,10 @@ function bashio::dns() {
info=$(bashio::cache.get 'dns.info')
else
info=$(bashio::api.supervisor GET /dns/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get dns info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'dns.info' "${info}"
fi
@ -163,6 +167,10 @@ function bashio::dns.stats() {
info=$(bashio::cache.get 'dns.stats')
else
info=$(bashio::api.supervisor GET /dns/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get dns stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'dns.stats' "${info}"
fi

View file

@ -31,6 +31,10 @@ function bashio::hardware() {
info=$(bashio::cache.get 'hardware.info')
else
info=$(bashio::api.supervisor GET /hardware/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get hardware info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'hardware.info' "${info}"
fi

View file

@ -63,6 +63,10 @@ function bashio::host() {
info=$(bashio::cache.get 'host.info')
else
info=$(bashio::api.supervisor GET /host/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get host info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'host.info' "${info}"
fi

View file

@ -31,6 +31,10 @@ function bashio::info() {
info=$(bashio::cache.get 'info')
else
info=$(bashio::api.supervisor GET /info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'info' "${info}"
fi

View file

@ -68,6 +68,10 @@ function bashio::multicast() {
info=$(bashio::cache.get 'multicast.info')
else
info=$(bashio::api.supervisor GET /multicast/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get multicast info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'multicast.info' "${info}"
fi
@ -130,6 +134,10 @@ function bashio::multicast.stats() {
info=$(bashio::cache.get 'multicast.stats')
else
info=$(bashio::api.supervisor GET /multicast/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get multicast stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'multicast.stats' "${info}"
fi

View file

@ -41,6 +41,10 @@ function bashio::network() {
info=$(bashio::cache.get 'network.info')
else
info=$(bashio::api.supervisor GET /network/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get network info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'network.info' "${info}"
fi
@ -105,6 +109,10 @@ function bashio::network.interface() {
info=$(bashio::cache.get "network.interface.${interface}.info")
else
info=$(bashio::api.supervisor GET "/network/interface/${interface}/info" false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get network interface info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "network.interface.${interface}.info" "${info}"
fi

View file

@ -51,6 +51,10 @@ function bashio::observer() {
info=$(bashio::cache.get 'observer.info')
else
info=$(bashio::api.supervisor GET /observer/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get observer info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'observer.info' "${info}"
fi
@ -121,6 +125,10 @@ function bashio::observer.stats() {
info=$(bashio::cache.get 'observer.stats')
else
info=$(bashio::api.supervisor GET /observer/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get observer stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'observer.stats' "${info}"
fi

View file

@ -59,6 +59,10 @@ function bashio::os() {
info=$(bashio::cache.get 'os.info')
else
info=$(bashio::api.supervisor GET /os/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get os info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'os.info' "${info}"
fi

View file

@ -34,6 +34,10 @@ function bashio::repositories() {
info=$(bashio::cache.get 'repositories.list')
else
info=$(bashio::api.supervisor GET "/addons" false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get addons from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "repositories.list" "${info}"
fi
else
@ -42,6 +46,10 @@ function bashio::repositories() {
else
info=$(bashio::api.supervisor GET "/addons" \
false ".repositories[] | select(.slug==\"${slug}\")")
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get repositories info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "repositories.${slug}.info" "${info}"
fi
fi

View file

@ -28,6 +28,10 @@ function bashio::services() {
config=$(bashio::cache.get "${cache_key}")
else
config=$(bashio::api.supervisor GET "/services/${service}" false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get services from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set "${cache_key}" "${config}"
fi

View file

@ -76,6 +76,10 @@ function bashio::supervisor() {
info=$(bashio::cache.get 'supervisor.info')
else
info=$(bashio::api.supervisor GET /supervisor/info false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get supervisor info from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'supervisor.info' "${info}"
fi
@ -314,6 +318,10 @@ function bashio::supervisor.stats() {
info=$(bashio::cache.get 'supervisor.stats')
else
info=$(bashio::api.supervisor GET /supervisor/stats false)
if [ "$?" -ne "${__BASHIO_EXIT_OK}" ]; then
bashio::log.error "Failed to get supervisor stats from Supervisor API"
return "${__BASHIO_EXIT_NOK}"
fi
bashio::cache.set 'supervisor.stats' "${info}"
fi