Refactor EPG scheduling: replace CRON_SCHEDULE with GRAB_INTERVAL_HOURS for improved interval-based grabbing and add lock mechanism to prevent concurrent executions.
Build and Push Docker Images / build-and-push (push) Successful in 1m38s

This commit is contained in:
2026-05-24 13:48:27 +02:00
parent 6b63abc2af
commit b9f292280b
2 changed files with 17 additions and 19 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
FROM node:20-alpine FROM node:20-alpine
# Install required packages # Install required packages
RUN apk add --no-cache git curl unzip coreutils dcron RUN apk add --no-cache git curl unzip coreutils
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
@@ -22,7 +22,7 @@ RUN chmod +x /app/entrypoint.sh
EXPOSE 3000 EXPOSE 3000
# Set environment variables with defaults # Set environment variables with defaults
ENV CRON_SCHEDULE="0 0,12 * * *" \ ENV GRAB_INTERVAL_HOURS=12 \
SITES="" \ SITES="" \
MAX_CONNECTIONS=10 \ MAX_CONNECTIONS=10 \
DAYS="" \ DAYS="" \
+15 -17
View File
@@ -56,6 +56,11 @@ grab_epg() {
} }
if [ "$1" = "grab" ]; then if [ "$1" = "grab" ]; then
if ! mkdir /tmp/epg-grab.lock 2>/dev/null; then
echo "EPG grab already running, skipping"
exit 0
fi
trap 'rmdir /tmp/epg-grab.lock 2>/dev/null || true' EXIT INT TERM
grab_epg grab_epg
exit 0 exit 0
fi fi
@@ -67,24 +72,17 @@ if [ -n "$SITES" ]; then
grab_epg grab_epg
fi fi
if [ -n "$CRON_SCHEDULE" ] && [ -n "$SITES" ]; then if [ -n "$SITES" ] && [ "${GRAB_INTERVAL_HOURS:-0}" -gt 0 ] 2>/dev/null; then
echo "Setting up cron job with schedule: $CRON_SCHEDULE" echo "Scheduling EPG grab every ${GRAB_INTERVAL_HOURS} hours"
# Cron runs with a minimal env — bake grab-related vars into a wrapper script. (
{ while true; do
echo '#!/bin/sh' sleep $((GRAB_INTERVAL_HOURS * 3600))
echo 'cd /app' echo "Starting scheduled EPG grab at $(date -u '+%Y-%m-%d %H:%M:%S UTC' 2>/dev/null || date)"
for var in SITES OUTPUT MAX_CONNECTIONS DAYS TIMEOUT DELAY LANG PROXY GZIP JSON CURL; do /app/entrypoint.sh grab
eval "val=\$$var"
if [ -n "$val" ]; then
printf "export %s='%s'\n" "$var" "$(printf '%s' "$val" | sed "s/'/'\\\\''/g")"
fi
done done
echo 'exec /app/entrypoint.sh grab' ) &
} >/app/run-grab.sh elif [ -n "$CRON_SCHEDULE" ]; then
chmod +x /app/run-grab.sh echo "WARNING: CRON_SCHEDULE is deprecated, use GRAB_INTERVAL_HOURS instead (ignored)"
echo "$CRON_SCHEDULE /app/run-grab.sh >> /proc/1/fd/1 2>&1" >/etc/crontabs/root
chmod 600 /etc/crontabs/root
crond -b -l 2
fi fi
echo "Starting server on port 3000 to serve EPG files from /app/guides" echo "Starting server on port 3000 to serve EPG files from /app/guides"