Do not allow the weather zsh status code to take longer than 5s to complete

This commit is contained in:
Tony Blyler 2022-07-11 10:58:10 -04:00
parent 15ba998e43
commit 01a7b4118f

View file

@ -3,6 +3,8 @@
zmodload zsh/datetime zmodload zsh/datetime
zmodload -F zsh/stat b:zstat zmodload -F zsh/stat b:zstat
readonly WEATHER_CURL_TIMEOUT="${WEATHER_CURL_TIMEOUT:-5}"
function weather_check_requirements() { function weather_check_requirements() {
[ -r "$(_weather_api_key_path)" ] && \ [ -r "$(_weather_api_key_path)" ] && \
[ -r "$(_weather_home_location_key_path)" ] && \ [ -r "$(_weather_home_location_key_path)" ] && \
@ -149,7 +151,10 @@ function _weather_current_conditions() {
TEMP_OUTPUT="$(mktemp)" TEMP_OUTPUT="$(mktemp)"
trap 'rm -f "${TEMP_OUTPUT}"' EXIT trap 'rm -f "${TEMP_OUTPUT}"' EXIT
curl -LSsf --get -X GET \ curl -LSsf \
--max-time "${WEATHER_CURL_TIMEOUT}" \
--get \
-X GET \
--data-urlencode "apikey=${WEATHER_API_KEY}" \ --data-urlencode "apikey=${WEATHER_API_KEY}" \
--data-urlencode "language=en-us" \ --data-urlencode "language=en-us" \
--data-urlencode "details=true" \ --data-urlencode "details=true" \
@ -184,7 +189,10 @@ function _weather_12_hour_forecast() {
TEMP_OUTPUT="$(mktemp)" TEMP_OUTPUT="$(mktemp)"
trap 'rm -f "${TEMP_OUTPUT}"' EXIT trap 'rm -f "${TEMP_OUTPUT}"' EXIT
curl -LSsf --get -X GET \ curl -LSsf \
--max-time "${WEATHER_CURL_TIMEOUT}" \
--get \
-X GET \
--data-urlencode "apikey=${WEATHER_API_KEY}" \ --data-urlencode "apikey=${WEATHER_API_KEY}" \
--data-urlencode "language=en-us" \ --data-urlencode "language=en-us" \
--data-urlencode "details=true" \ --data-urlencode "details=true" \
@ -219,7 +227,10 @@ function _weather_5_day_daily_forecast() {
TEMP_OUTPUT="$(mktemp)" TEMP_OUTPUT="$(mktemp)"
trap 'rm -f "${TEMP_OUTPUT}"' EXIT trap 'rm -f "${TEMP_OUTPUT}"' EXIT
curl -LSsf --get -X GET \ curl -LSsf \
--max-time "${WEATHER_CURL_TIMEOUT}" \
--get \
-X GET \
--data-urlencode "apikey=${WEATHER_API_KEY}" \ --data-urlencode "apikey=${WEATHER_API_KEY}" \
--data-urlencode "language=en-us" \ --data-urlencode "language=en-us" \
--data-urlencode "details=true" \ --data-urlencode "details=true" \