feat: 自动同步每天两次(02:00+19:00) + 启动时首次同步
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
690766528a
commit
246410e12c
@ -14,6 +14,7 @@ import { adminRoutes } from './routes/admin';
|
|||||||
// Importing db triggers auto-migration on first load (B-07 fix)
|
// Importing db triggers auto-migration on first load (B-07 fix)
|
||||||
import { db } from './db/index';
|
import { db } from './db/index';
|
||||||
import { seedAdminUser } from './db/seed-auto';
|
import { seedAdminUser } from './db/seed-auto';
|
||||||
|
import { startScheduler } from './sync/scheduler';
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
@ -60,6 +61,9 @@ seedAdminUser().catch((err) => {
|
|||||||
console.error('[Seed] Failed to seed admin user:', err);
|
console.error('[Seed] Failed to seed admin user:', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 启动自动同步(每天凌晨 2 点 + 启动时首次同步)
|
||||||
|
startScheduler();
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
const port = config.PORT;
|
const port = config.PORT;
|
||||||
console.info(`DevPerf Dashboard API starting on port ${port}`);
|
console.info(`DevPerf Dashboard API starting on port ${port}`);
|
||||||
|
|||||||
@ -1,40 +1,25 @@
|
|||||||
import { Cron } from 'croner';
|
import { Cron } from 'croner';
|
||||||
import { config } from '../config';
|
|
||||||
import { syncPlane } from './sync-plane';
|
|
||||||
import { syncGitea } from './sync-gitea';
|
import { syncGitea } from './sync-gitea';
|
||||||
|
|
||||||
let planeJob: Cron | null = null;
|
|
||||||
let giteaJob: Cron | null = null;
|
let giteaJob: Cron | null = null;
|
||||||
|
|
||||||
export function startScheduler(): void {
|
export function startScheduler(): void {
|
||||||
const planeInterval = config.SYNC_PLANE_INTERVAL;
|
// 每天凌晨 2 点 + 晚上 7 点各同步一次
|
||||||
const giteaInterval = config.SYNC_GITEA_INTERVAL;
|
giteaJob = new Cron('0 2,19 * * *', async () => {
|
||||||
|
console.info('[SCHEDULER] Gitea 定时同步开始...');
|
||||||
// Plane sync every N minutes
|
|
||||||
planeJob = new Cron(`*/${planeInterval} * * * *`, async () => {
|
|
||||||
console.info('[SCHEDULER] Starting Plane sync...');
|
|
||||||
await syncPlane();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Gitea sync every N minutes
|
|
||||||
giteaJob = new Cron(`*/${giteaInterval} * * * *`, async () => {
|
|
||||||
console.info('[SCHEDULER] Starting Gitea sync...');
|
|
||||||
await syncGitea();
|
await syncGitea();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.info(`[SCHEDULER] Plane sync scheduled every ${planeInterval} minutes`);
|
console.info('[SCHEDULER] Gitea 自动同步已启动(每天 02:00 + 19:00)');
|
||||||
console.info(`[SCHEDULER] Gitea sync scheduled every ${giteaInterval} minutes`);
|
|
||||||
|
|
||||||
// Run initial sync after 5 seconds
|
// 启动后 10 秒执行一次首次同步
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
console.info('[SCHEDULER] Running initial sync...');
|
console.info('[SCHEDULER] 执行首次同步...');
|
||||||
await syncPlane().catch(e => console.error('[SCHEDULER] Initial Plane sync failed:', e));
|
await syncGitea().catch(e => console.error('[SCHEDULER] 首次同步失败:', e));
|
||||||
await syncGitea().catch(e => console.error('[SCHEDULER] Initial Gitea sync failed:', e));
|
}, 10000);
|
||||||
}, 5000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopScheduler(): void {
|
export function stopScheduler(): void {
|
||||||
planeJob?.stop();
|
|
||||||
giteaJob?.stop();
|
giteaJob?.stop();
|
||||||
console.info('[SCHEDULER] Stopped all sync jobs');
|
console.info('[SCHEDULER] 已停止同步任务');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user