From 353cc0528c526d945c9d59eecde946a101185f91 Mon Sep 17 00:00:00 2001 From: gunshiz Date: Sun, 2 Aug 2026 19:12:58 +0700 Subject: [PATCH] refactor(worker): use native bun cron --- Dockerfile | 3 +-- scripts/video-upload-crontab | 1 - worker/video-upload.ts | 22 +++++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 scripts/video-upload-crontab diff --git a/Dockerfile b/Dockerfile index 59e2f82..829e3d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,5 +36,4 @@ CMD ["bun", "start"] # Stage 4: Scheduled video upload worker FROM deps AS video-upload-worker COPY . . -COPY scripts/video-upload-crontab /etc/crontabs/root -ENTRYPOINT ["crond", "-f", "-l", "2", "-L", "/dev/stdout"] +CMD ["bun", "run", "worker/video-upload.ts"] diff --git a/scripts/video-upload-crontab b/scripts/video-upload-crontab deleted file mode 100644 index c30fc8f..0000000 --- a/scripts/video-upload-crontab +++ /dev/null @@ -1 +0,0 @@ -* * * * * bun run /app/worker/video-upload.ts diff --git a/worker/video-upload.ts b/worker/video-upload.ts index 399b268..a586d81 100644 --- a/worker/video-upload.ts +++ b/worker/video-upload.ts @@ -1,11 +1,19 @@ import { processDueVideoUploads } from "@/lib/video/video-platforms"; -console.log(`[${new Date().toISOString()}] Checking scheduled video uploads.`); +async function processScheduledUploads() { + 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; + try { + await processDueVideoUploads(); + console.log( + `[${new Date().toISOString()}] Scheduled video upload check finished.`, + ); + } catch (error) { + console.error("Scheduled video upload worker failed:", error); + } } + +await processScheduledUploads(); + +Bun.cron("* * * * *", processScheduledUploads); +console.log("Video upload worker scheduled every minute with Bun.cron.");