#!/usr/bin/env bash
# Cron entrypoint: 3-hourly project report (gen report + digest conversation).
set -u
cd /var/www/html/mi-digital-new-platform
[ -f automation/.env ] && . automation/.env
LOCK=/tmp/api_hub_report.lock
exec 9>"$LOCK"
if ! flock -n 9; then
  echo "[$(date '+%F %T')] report job: another run in progress; skipping" >> automation/report.log
  exit 0
fi
echo "[$(date '+%F %T')] report job start" >> automation/report.log
python3 automation/report_job.py >> automation/report.log 2>&1
echo "[$(date '+%F %T')] report job done (exit $?)" >> automation/report.log
tail -n 500 automation/report.log > automation/report.log.tmp && mv automation/report.log.tmp automation/report.log
