fix(upload): isolate cron jobs in worker

This commit is contained in:
2026-08-02 18:21:31 +07:00 Unverified
parent 53606c60af
commit dbf8e345a3
7 changed files with 28 additions and 35 deletions
+5
View File
@@ -32,3 +32,8 @@ COPY --from=builder /app/package.json ./package.json
EXPOSE 3000 EXPOSE 3000
CMD ["bun", "start"] CMD ["bun", "start"]
# Stage 4: Scheduled video upload worker
FROM builder AS video-upload-worker
COPY scripts/video-upload-crontab /etc/crontabs/root
ENTRYPOINT ["crond", "-f", "-l", "2", "-L", "/dev/stdout"]
-8
View File
@@ -1,8 +0,0 @@
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"]
+10 -7
View File
@@ -2,6 +2,8 @@ services:
app: app:
build: . build: .
restart: unless-stopped restart: unless-stopped
ports:
- "8606:80"
expose: expose:
- "3000" - "3000"
env_file: env_file:
@@ -11,23 +13,24 @@ services:
nginx: nginx:
image: nginx:alpine image: nginx:alpine
ports:
- "8606:80"
volumes: volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on: depends_on:
- app app:
condition: service_started
restart: true
network_mode: "service:app"
restart: unless-stopped restart: unless-stopped
video-upload-scheduler: video-upload-worker:
build: build:
context: . context: .
dockerfile: Dockerfile.scheduler target: video-upload-worker
restart: unless-stopped restart: unless-stopped
depends_on:
- app
env_file: env_file:
- .env - .env
volumes:
- /nfs/erika:/nfs/erika
secret-scan: secret-scan:
image: ghcr.io/gitleaks/gitleaks:v8.30.1 image: ghcr.io/gitleaks/gitleaks:v8.30.1
+1 -1
View File
@@ -33,7 +33,7 @@ http {
listen 80; listen 80;
location / { location / {
proxy_pass http://app:3000; proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -1,18 +0,0 @@
#!/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 @@
* * * * * /usr/local/bin/process-scheduled-video-uploads * * * * * bun run worker/video-upload.ts
+11
View File
@@ -0,0 +1,11 @@
import { processDueVideoUploads } from "@/lib/video/video-platforms";
console.log(`[${new Date().toISOString()}] Checking scheduled video uploads.`);
try {
await processDueVideoUploads();
console.log(`[${new Date().toISOString()}] Scheduled video upload check finished.`);
} catch (error) {
console.error("Scheduled video upload worker failed:", error);
process.exitCode = 1;
}