app
Mouser Electronics Search
Public Made by Adomby adom
Mouser component search in your workspace — stock, quantity price breaks, datasheets and lifecycle. CLI verbs, a Hydrogen app, and a shared backend service.
#!/usr/bin/env bash
# adom-mouser cron smoke runner. Same shape as adom-jlcpcb's:
# state-transition alerts via Kel, no spam on repeated fails.
#
# Install:
# (crontab -l 2>/dev/null; echo '20 * * * * /home/adom/adom-mouser/tests/cron-smoke.sh >> /tmp/adom-mouser-smoke.log 2>&1') | crontab -
set -u
set -a; [ -f /etc/environment ] && . /etc/environment; set +a
REPO_DIR="${ADOM_MOUSER_REPO:-$HOME/adom-mouser}"
# Pass `--live` to run the daily live suite instead of the cheap hourly
# check. Separate state files so pass/fail tracking doesn't cross over.
MODE="cheap"
if [ "${1:-}" = "--live" ]; then MODE="live"; shift; fi
STATE_FILE="${ADOM_MOUSER_SMOKE_STATE:-/tmp/adom-mouser-smoke-state-$MODE}"
BACKEND="${MOUSER_API:-http://127.0.0.1:${MOUSER_PORT:-8775}}"
WEBHOOK="${KEL_ALERT_WEBHOOK:-}"
HOSTNAME_SHORT="$(hostname -s 2>/dev/null || echo mouser-host)"
prev_status="pass"
[ -f "$STATE_FILE" ] && prev_status="$(cat "$STATE_FILE" 2>/dev/null || echo pass)"
if [ "$MODE" = "live" ]; then
log_out="$(bash "$REPO_DIR/tests/smoke-live.sh" "$BACKEND" 2>&1)"
else
log_out="$(bash "$REPO_DIR/tests/smoke.sh" "$BACKEND" 2>&1)"
fi
status=$?
printf '[%s] status=%s\n%s\n' "$(date -Iseconds)" "$status" "$log_out"
new_status="pass"
[ "$status" -ne 0 ] && new_status="fail"
post_kel() {
[ -z "$WEBHOOK" ] && return 0
local body; body="$(jq -n --arg t "$1" '{text:$t}')"
curl -s --max-time 3 -X POST -H 'content-type: application/json' -d "$body" "$WEBHOOK" >/dev/null || true
}
if [ "$prev_status" = "pass" ] && [ "$new_status" = "fail" ]; then
summary="$(printf '%s' "$log_out" | grep -E '^(FAIL|OK|FAIL.*passed)' | head -4)"
post_kel "⚠️ *adom-mouser backend smoke FAILING on $HOSTNAME_SHORT.*
Backend: $BACKEND
$(printf '%s' "$summary")
/tmp/adom-mouser-smoke.log has the full run. One alert per incident."
elif [ "$prev_status" = "fail" ] && [ "$new_status" = "pass" ]; then
post_kel "✅ *adom-mouser backend smoke RECOVERED on $HOSTNAME_SHORT.*
Backend: $BACKEND"
fi
echo "$new_status" > "$STATE_FILE"
exit "$status"