0709
This commit is contained in:
@@ -22,6 +22,9 @@ ROUTING_KEY="${ROUTING_KEY:-}" # irrelevant when EXCHANGE is empty
|
|||||||
# Polling interval when no messages
|
# Polling interval when no messages
|
||||||
SLEEP_SECS="${SLEEP_SECS:-1}"
|
SLEEP_SECS="${SLEEP_SECS:-1}"
|
||||||
|
|
||||||
|
# GO/NO-GO gate bypass (requested): set ignore_gonogo=true to ignore gate
|
||||||
|
ignore_gonogo="${ignore_gonogo:-false}"
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
APP_ROOT="/opt/containers/ansible-worker/app"
|
APP_ROOT="/opt/containers/ansible-worker/app"
|
||||||
NBPLAY="${APP_ROOT}/bin/nbplay"
|
NBPLAY="${APP_ROOT}/bin/nbplay"
|
||||||
@@ -46,6 +49,39 @@ log() { printf '[consumer] %s\n' "$*"; }
|
|||||||
warn() { printf '[consumer][WARN] %s\n' "$*" >&2; }
|
warn() { printf '[consumer][WARN] %s\n' "$*" >&2; }
|
||||||
err() { printf '[consumer][ERROR] %s\n' "$*" >&2; }
|
err() { printf '[consumer][ERROR] %s\n' "$*" >&2; }
|
||||||
|
|
||||||
|
# --- GO/NO-GO gate helpers (surgical add) ---
|
||||||
|
gate_sleep_secs() {
|
||||||
|
# Random 2..5 seconds inclusive
|
||||||
|
echo $(( (RANDOM % 4) + 2 ))
|
||||||
|
}
|
||||||
|
|
||||||
|
gate_is_go() {
|
||||||
|
# Bypass if ignore_gonogo is true-ish
|
||||||
|
case "${ignore_gonogo,,}" in
|
||||||
|
true|1|yes|y) return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Fail-closed: any error/unreachable => NO-GO
|
||||||
|
local body val
|
||||||
|
if ! body="$(curl -fsS --connect-timeout 2 --max-time 3 "http://10.210.12.2:8090/data/go_nogo.txt" 2>/dev/null)"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Must match ^go$ (allow trailing newline in file)
|
||||||
|
val="$(printf '%s' "$body" | tr -d '\r' | head -n1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||||
|
val="${val,,}"
|
||||||
|
[[ "$val" == "go" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
gate_block_if_needed() {
|
||||||
|
# If gate is closed, sleep random 2..5 seconds and signal caller to continue loop
|
||||||
|
if gate_is_go; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
sleep "$(gate_sleep_secs)"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Safely append string options into an array using eval (so quotes are honored).
|
# Safely append string options into an array using eval (so quotes are honored).
|
||||||
append_opts() {
|
append_opts() {
|
||||||
local opts_str="$1"
|
local opts_str="$1"
|
||||||
@@ -64,7 +100,6 @@ dispatch_task() {
|
|||||||
task="$(jq -er '.task_name // empty' <<<"$json")" || task=""
|
task="$(jq -er '.task_name // empty' <<<"$json")" || task=""
|
||||||
task_options="$(jq -r '.task_options // empty' <<<"$json")" || task_options=""
|
task_options="$(jq -r '.task_options // empty' <<<"$json")" || task_options=""
|
||||||
|
|
||||||
|
|
||||||
# Pass after-upgrade metadata via -e by augmenting task_options (single source of truth)
|
# Pass after-upgrade metadata via -e by augmenting task_options (single source of truth)
|
||||||
# Supports both historic 'afterupgrade_check' and current 'afterupgrade_indoor_check'
|
# Supports both historic 'afterupgrade_check' and current 'afterupgrade_indoor_check'
|
||||||
if [[ "$task" == "afterupgrade_indoor_check" || "$task" == "afterupgrade_check" ]]; then
|
if [[ "$task" == "afterupgrade_indoor_check" || "$task" == "afterupgrade_check" ]]; then
|
||||||
@@ -100,7 +135,6 @@ dispatch_task() {
|
|||||||
task_options+=" -e is_run_by='$(esc "$is_run_by")'"
|
task_options+=" -e is_run_by='$(esc "$is_run_by")'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [[ -z "$device" || -z "$task" ]]; then
|
if [[ -z "$device" || -z "$task" ]]; then
|
||||||
warn "payload missing required keys (inscope_device/task_name). Skipping."
|
warn "payload missing required keys (inscope_device/task_name). Skipping."
|
||||||
return 0
|
return 0
|
||||||
@@ -233,6 +267,11 @@ if [[ -n "$EXCHANGE" ]]; then
|
|||||||
# Single-queue consume loop (unchanged branch)
|
# Single-queue consume loop (unchanged branch)
|
||||||
log "Press Ctrl+C to stop."
|
log "Press Ctrl+C to stop."
|
||||||
while :; do
|
while :; do
|
||||||
|
# GO/NO-GO gate: do NOT dequeue unless gate is GO
|
||||||
|
if ! gate_block_if_needed; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
RESP="$(api POST "/api/queues/$(urlenc "$VHOST")/$QUEUE/get" '{
|
RESP="$(api POST "/api/queues/$(urlenc "$VHOST")/$QUEUE/get" '{
|
||||||
"count": 1, "ackmode": "ack_requeue_false", "encoding": "auto", "truncate": 1000000
|
"count": 1, "ackmode": "ack_requeue_false", "encoding": "auto", "truncate": 1000000
|
||||||
}')"
|
}')"
|
||||||
@@ -282,6 +321,11 @@ else
|
|||||||
|
|
||||||
# Multi-queue round-robin: try each queue once per loop; if any yields a message, process it and start over.
|
# Multi-queue round-robin: try each queue once per loop; if any yields a message, process it and start over.
|
||||||
while :; do
|
while :; do
|
||||||
|
# GO/NO-GO gate: do NOT dequeue unless gate is GO
|
||||||
|
if ! gate_block_if_needed; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
local_got_message=0
|
local_got_message=0
|
||||||
|
|
||||||
for Q in "${QUEUE_LIST[@]}"; do
|
for Q in "${QUEUE_LIST[@]}"; do
|
||||||
@@ -326,3 +370,4 @@ else
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user