From 512ee6cc2767de8200685a08dca41783bc9c8742 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Thu, 14 May 2026 14:52:17 +0800 Subject: [PATCH] feat: wire scheduler lifecycle into Nitro plugin Co-Authored-By: Claude Opus 4.7 --- .env.example | 4 +++- server/plugins/03.scheduler.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 server/plugins/03.scheduler.ts diff --git a/.env.example b/.env.example index 6529a7c..61ec2f4 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ DATABASE_URL=file:./db.sqlite STATIC_DIR=static UPLOAD_SUBDIR=upload -NITRO_PORT=3399 \ No newline at end of file +NITRO_PORT=3399 +SCHEDULER_MAX_CONCURRENCY=5 +SCHEDULER_LOG_RETENTION_DAYS=30 \ No newline at end of file diff --git a/server/plugins/03.scheduler.ts b/server/plugins/03.scheduler.ts new file mode 100644 index 0000000..0e18a1a --- /dev/null +++ b/server/plugins/03.scheduler.ts @@ -0,0 +1,16 @@ +import { start, stop } from "../scheduler/engine"; + +const MAX_CONCURRENCY = Number(process.env.SCHEDULER_MAX_CONCURRENCY) || 5; +const LOG_RETENTION_DAYS = Number(process.env.SCHEDULER_LOG_RETENTION_DAYS) || 30; + +if (import.meta.dev) { + console.log("plugin: 03.scheduler"); +} + +export default defineNitroPlugin(async (nitroApp) => { + await start(MAX_CONCURRENCY, LOG_RETENTION_DAYS); + + nitroApp.hooks.hook("close", async () => { + await stop(); + }); +});