Commit be626bdc authored by Mahmoud Aglan's avatar Mahmoud Aglan

chore(server): the once-a-minute scheduler for the tournament engine and campaigns

tools/server/el3ab-cron.sh runs api/cron.php (player app) and the manager's
api/cron/notifications under flock, logging only failures. Installed on
169.58.165.0 as /usr/local/bin/el3ab-cron.sh with /etc/cron.d/el3ab-cron;
the service key lives in /etc/el3ab-cron.headers (root, 600).
Co-Authored-By: 's avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 89610750
# El3ab: tournament engine and scheduled notifications, once a minute.
* * * * * root /usr/local/bin/el3ab-cron.sh >>/var/log/el3ab-cron.log 2>&1
#!/bin/bash
# Once a minute on the server (/etc/cron.d/el3ab-cron): the player app's
# tournament engine (api/cron.php) and the manager's scheduled notification
# campaigns (api/cron/notifications). Both ticks are idempotent; flock keeps a
# slow tick from overlapping the next one.
#
# Install (as root on 169.58.165.0):
# install -m 755 el3ab-cron.sh /usr/local/bin/el3ab-cron.sh
# install -m 644 el3ab-cron.cron /etc/cron.d/el3ab-cron
# printf 'X-Service-Key: %s\n' "$SUPABASE_SERVICE_KEY" > /etc/el3ab-cron.headers
# chmod 600 /etc/el3ab-cron.headers
#
# Only failures are logged (/var/log/el3ab-cron.log); the last report of each
# tick is kept in /var/lib/el3ab-cron/.
exec 9>/run/el3ab-cron.lock
flock -n 9 || exit 0
HEADERS=/etc/el3ab-cron.headers
STATE=/var/lib/el3ab-cron
mkdir -p "$STATE"
tick() {
local name=$1 url=$2 limit=$3 code
code=$(curl -sS -m "$limit" -X POST -H @"$HEADERS" -o "$STATE/$name.json" -w '%{http_code}' "$url") || code=000
if [ "$code" != 200 ]; then
echo "$(date -Is) $name: HTTP $code $(head -c 300 "$STATE/$name.json" 2>/dev/null)"
elif ! grep -q '"errors":\[\]' "$STATE/$name.json"; then
echo "$(date -Is) $name: errors $(head -c 600 "$STATE/$name.json")"
fi
}
tick player https://el3ab-player.caprover.al-arcade.com/api/cron.php 50
tick manager https://el3ab-management.caprover.al-arcade.com/api/cron/notifications 30
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment