From b40e37ac0e37aa853c3fc61dddc9ca4d66d50350 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Thu, 14 May 2026 16:32:48 +0800 Subject: [PATCH] fix: use explicit import for cleanup-logs to avoid tree-shaking Nuxt's bundler tree-shakes side-effect-only imports (import "./file"). Changed to export the handler from cleanup-logs.ts and call registerTask explicitly in the plugin to ensure the task is registered at startup. Co-Authored-By: Claude Opus 4.7 --- server/plugins/03.scheduler.ts | 5 ++++- server/scheduler/tasks/cleanup-logs.ts | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/plugins/03.scheduler.ts b/server/plugins/03.scheduler.ts index f28be9f..cea6cb6 100644 --- a/server/plugins/03.scheduler.ts +++ b/server/plugins/03.scheduler.ts @@ -1,5 +1,6 @@ import { start, stop } from "../scheduler/engine"; -import "../scheduler/tasks/cleanup-logs"; +import { registerTask } from "../scheduler/registry"; +import cleanupLogs from "../scheduler/tasks/cleanup-logs"; const MAX_CONCURRENCY = Number(process.env.SCHEDULER_MAX_CONCURRENCY) || 5; const LOG_RETENTION_DAYS = Number(process.env.SCHEDULER_LOG_RETENTION_DAYS) || 30; @@ -8,6 +9,8 @@ if (import.meta.dev) { console.log("plugin: 03.scheduler"); } +registerTask("cleanup-logs", cleanupLogs); + export default defineNitroPlugin(async (nitroApp) => { await start(MAX_CONCURRENCY, LOG_RETENTION_DAYS); diff --git a/server/scheduler/tasks/cleanup-logs.ts b/server/scheduler/tasks/cleanup-logs.ts index 999dbc4..15989c5 100644 --- a/server/scheduler/tasks/cleanup-logs.ts +++ b/server/scheduler/tasks/cleanup-logs.ts @@ -1,10 +1,9 @@ -import { registerTask } from "../registry"; import log4js from "logger"; const logger = log4js.getLogger("SCHEDULER"); -registerTask("cleanup-logs", async (payload) => { +export default async function cleanupLogs(payload?: Record) { const days = (payload?.days as number) ?? 30; logger.info("Log cleanup placeholder: would remove logs older than %d days", days); return { success: true, message: `Cleaned logs older than ${days} days` }; -}); +}