#!/usr/bin/env bash # Weekly coaching check-in batch (Phase 3). Reads the admin API key from .env # and POSTs the batch endpoint, which generates a check-in for every eligible # user whose cadence is due. Invoked by a weekly cron entry. # # Override the target with IMPACTFLOW_BASE_URL (defaults to the local container). set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" BASE="${IMPACTFLOW_BASE_URL:-http://localhost:8011}" LOG="$DIR/data/coaching-cron.log" KEY="$(grep '^IMPACTFLOW_API_KEY=' "$DIR/.env" | cut -d= -f2 | tr -d '\r\n')" if [[ -z "$KEY" ]]; then echo "$(date -u +%FT%TZ) ERROR: IMPACTFLOW_API_KEY not found in $DIR/.env" >> "$LOG" exit 1 fi resp="$(curl -sS -m 120 -X POST -H "X-API-Key: $KEY" \ "$BASE/discovery/coaching/run" 2>&1 || echo '{"error":"curl failed"}')" echo "$(date -u +%FT%TZ) $resp" >> "$LOG"