36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { Hono } from 'hono';
|
|
import { refreshMonitoringCache } from './cache.js';
|
|
import monitoringRouter from './monitoring.js';
|
|
import targetsRouter from './targets.js';
|
|
import trendRouter from './trend.js';
|
|
import vehicleRecentRouter from './vehicle-recent.js';
|
|
import dailyReportRouter from './daily-report.js';
|
|
import { startDailyReportScheduler } from './daily-report-scheduler.js';
|
|
|
|
const app = new Hono();
|
|
|
|
app.route('/monitoring', monitoringRouter);
|
|
app.route('/targets', targetsRouter);
|
|
app.route('/target', targetsRouter);
|
|
app.route('/trend', trendRouter);
|
|
app.route('/vehicle', vehicleRecentRouter);
|
|
app.route('/reports', dailyReportRouter);
|
|
|
|
let backgroundJobsStarted = false;
|
|
|
|
/**
|
|
* 启动里程后台任务。路由装配阶段不自动调用,避免导入模块时产生副作用。
|
|
* 幂等保护用于防止开发热更新或重复引导时创建多组定时器。
|
|
*/
|
|
export function startMileageBackgroundJobs(): void {
|
|
if (backgroundJobsStarted) return;
|
|
backgroundJobsStarted = true;
|
|
|
|
// 保留原有行为:启动时立即刷新一次,之后每分钟刷新。
|
|
void refreshMonitoringCache();
|
|
setInterval(refreshMonitoringCache, 60 * 1000);
|
|
startDailyReportScheduler();
|
|
}
|
|
|
|
export default app;
|