fix(upload): prevent overlapping cron runs

This commit is contained in:
2026-08-02 18:09:00 +07:00 Unverified
parent 5b0bc32845
commit 9bbde8b7b5
3 changed files with 22 additions and 1 deletions
+3
View File
@@ -1,5 +1,8 @@
FROM nginx:alpine
COPY scripts/video-upload-crontab /etc/crontabs/root
COPY scripts/process-scheduled-video-uploads.sh /usr/local/bin/process-scheduled-video-uploads
RUN chmod 0755 /usr/local/bin/process-scheduled-video-uploads
ENTRYPOINT ["crond", "-f", "-l", "2", "-L", "/dev/stdout"]
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu
upload_cron_lock=/tmp/erika-video-upload-cron.lock
if ! mkdir "$upload_cron_lock" 2>/dev/null; then
echo "Previous scheduled video upload run is still active; skipping this minute."
exit 0
fi
trap 'rmdir "$upload_cron_lock"' EXIT INT TERM
wget -q -O /dev/null \
--header="Authorization: Bearer ${CRON_SECRET}" \
http://app:3000/api/cron/video-uploads || {
echo "Scheduled video upload processing failed." >&2
exit 1
}
+1 -1
View File
@@ -1 +1 @@
* * * * * wget -q -O /dev/null --header="Authorization: Bearer ${CRON_SECRET}" http://app:3000/api/cron/video-uploads || echo "Scheduled video upload processing failed." >&2
* * * * * /usr/local/bin/process-scheduled-video-uploads