Files
infrapuzzle/k8s/openclaw/setup-dashboards-cron.sh

41 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# ==============================================================================
# setup-dashboards-cron.sh
# Declaratively registers periodic background publishing for Mila & Moritz dashboards in OpenClaw.
# Schedule: Every 10 minutes (pure shell command execution, zero LLM token cost)
# ==============================================================================
set -euo pipefail
NAMESPACE="${NAMESPACE:-openclaw}"
POD_NAME="${POD_NAME:-openclaw-0}"
CONTAINER_NAME="${CONTAINER_NAME:-openclaw}"
JOB_NAME="dashboards-periodic-publish"
SCHEDULE_EVERY="10m"
echo "=== Registering Dashboards Periodic Publish in OpenClaw ($POD_NAME) ==="
# 1. Check if job already exists
EXISTING_ID=$(kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron list --json 2>/dev/null | python3 -c 'import sys, json; data=json.load(sys.stdin); print(next((j["id"] for j in data.get("jobs", []) if j.get("declarationKey") == "'"$JOB_NAME"'" or j.get("name") == "'"$JOB_NAME"'"), ""))' 2>/dev/null || true)
if [ -n "$EXISTING_ID" ]; then
echo "Found existing job with ID $EXISTING_ID. Removing for idempotent recreation..."
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron rm "$EXISTING_ID" || true
fi
# 2. Add the job as direct shell command execution with --no-deliver
echo "Creating automation $JOB_NAME (every $SCHEDULE_EVERY)..."
CMD="sh -lc 'cd /home/node/mop-skills/mop-skills/skills/datastore && uv run scripts/update_website.py --data-dir /home/node/.openclaw/wiki/main/data && uv run scripts/update_moritz_website.py --data-dir /home/node/.openclaw/wiki/main/data'"
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron add \
--name "$JOB_NAME" \
--description "Periodically regenerates and uploads Mila & Moritz family HTML dashboards to S3" \
--command "$CMD" \
--every "$SCHEDULE_EVERY" \
--no-deliver
echo "=== Automation successfully registered! ==="
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron list | grep "$JOB_NAME" || true