This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user