never pick previous vpn
Build and Push Docker Images / build-and-push (push) Successful in 1m51s

This commit is contained in:
2026-07-29 19:21:36 +02:00
parent 151c2fcd8d
commit d7b6553eff
2 changed files with 28 additions and 3 deletions
@@ -27,8 +27,16 @@ parse_regions() {
tr ',' '\n' <<<"$raw" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | awk 'NF'
}
read_previous_region() {
local state_path="${ROTATOR_STATE_PATH:-/config/rotator-state.json}"
if [[ ! -f "$state_path" ]]; then
return 0
fi
jq -r '.region // empty' "$state_path" 2>/dev/null || true
}
pick_random_region() {
local regions=()
local regions=() previous candidates=()
while IFS= read -r region; do
[[ -n "$region" ]] && regions+=("$region")
done < <(parse_regions)
@@ -38,7 +46,24 @@ pick_random_region() {
exit 2
fi
printf '%s\n' "${regions[@]}" | shuf -n 1
previous="$(read_previous_region)"
if [[ -n "$previous" ]]; then
for region in "${regions[@]}"; do
[[ "$region" == "$previous" ]] && continue
candidates+=("$region")
done
fi
if [[ "${#candidates[@]}" -eq 0 ]]; then
if [[ -n "$previous" && "${#regions[@]}" -eq 1 ]]; then
log "Only one region configured; reusing previous: $previous"
fi
candidates=("${regions[@]}")
else
log "Excluding previous region: $previous"
fi
printf '%s\n' "${candidates[@]}" | shuf -n 1
}
parse_additional_restart_containers() {