fix(upload): isolate cron jobs in worker
This commit is contained in:
@@ -32,3 +32,8 @@ COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
EXPOSE 3000
|
||||
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"]
|
||||
|
||||
@@ -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
@@ -2,6 +2,8 @@ services:
|
||||
app:
|
||||
build: .
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8606:80"
|
||||
expose:
|
||||
- "3000"
|
||||
env_file:
|
||||
@@ -11,23 +13,24 @@ services:
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8606:80"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
depends_on:
|
||||
- app
|
||||
app:
|
||||
condition: service_started
|
||||
restart: true
|
||||
network_mode: "service:app"
|
||||
restart: unless-stopped
|
||||
|
||||
video-upload-scheduler:
|
||||
video-upload-worker:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.scheduler
|
||||
target: video-upload-worker
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- app
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- /nfs/erika:/nfs/erika
|
||||
|
||||
secret-scan:
|
||||
image: ghcr.io/gitleaks/gitleaks:v8.30.1
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ http {
|
||||
listen 80;
|
||||
|
||||
location / {
|
||||
proxy_pass http://app:3000;
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
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 @@
|
||||
* * * * * /usr/local/bin/process-scheduled-video-uploads
|
||||
* * * * * bun run worker/video-upload.ts
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user