Files
stack/dev/scripts/refarm_cms_2026_2377.sh

54 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Post-comment-close re-farm for docket CMS-2026-2377 (CY2027 PFS NPRM,
# CMS-1848-P). Scheduled via host crontab for 2026-09-15 (comment period
# closes 2026-09-14 per 91 FR 43842 DATES block). Tracker: issue #615.
#
# Every step is resumable/incremental — safe to re-run on partial failure.
set -uo pipefail
cd "$(dirname "$0")/../.."
export PATH="$HOME/.local/bin:$PATH"
set -a; source .env; set +a
mkdir -p .state/comments
LOG=.state/comments/refarm-CMS-2026-2377.log
exec >>"$LOG" 2>&1
echo "=== re-farm run $(date -Is) ==="
FAILURES=0
uv run stack bib fetch-pfs-comments || { echo "WARN: fetch-pfs-comments rc=$?"; FAILURES=$((FAILURES+1)); }
uv run stack bib backfill-comments || { echo "WARN: backfill rc=$?"; FAILURES=$((FAILURES+1)); }
uv run stack comments extract --docket CMS-2026-2377 || { echo "WARN: extract rc=$?"; FAILURES=$((FAILURES+1)); }
uv run stack comments extract-ocr --docket CMS-2026-2377 || { echo "WARN: ocr rc=$?"; FAILURES=$((FAILURES+1)); }
uv run stack llm index --collection comments --docket CMS-2026-2377 \
|| { echo "WARN: index rc=$?"; FAILURES=$((FAILURES+1)); }
COUNTS=$(uv run python - <<'EOF'
from conf import connect
s = connect.bib()
con = s._con()
total, enriched = con.execute(
"SELECT count(*), sum(CASE WHEN coalesce(abstract,'')<>'' THEN 1 ELSE 0 END) "
"FROM items WHERE url LIKE 'https://www.regulations.gov/comment/CMS-2026-2377-%'"
).fetchone()
print(f"comments={total} enriched={enriched}")
s.close()
EOF
) || { echo "WARN: counts rc=$?"; FAILURES=$((FAILURES+1)); }
echo "$COUNTS"
if [ "$FAILURES" -eq 0 ]; then
RESULT_MSG="Automated post-close re-farm ran $(date -I): $COUNTS."
else
RESULT_MSG="Automated post-close re-farm ran $(date -I) — completed with $FAILURES failed steps — check log. $COUNTS."
fi
curl -sf -X POST \
"https://git.fhirworx.io/api/v1/repos/homelab/stack/issues/615/comments" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-H "User-Agent: curl/8.5.0" \
-d "{\"body\": \"$RESULT_MSG Log: .state/comments/refarm-CMS-2026-2377.log. Review counts, spot-check indexing, then close this issue and milestone P37.\n\nIf complete: close #615, close milestone P37, and REMOVE the crontab line (re-fires annually).\"}" \
|| echo "WARN: gitea comment failed"
echo "=== done $(date -Is) ==="