feat(scheduler): 启动 + 跳过 AI 时写诊断日志到 sync_logs
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m2s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m2s
加入两条诊断写入: 1. 服务启动时立刻写 [BOOT] 日志,包含 AI_ENABLED / AI_API_KEY 长度 / AI_MODEL / AI_BASE_URL,可在 sync_logs UI 直接确认 pod 拿到 的环境变量 2. 每次 cron/手动触发若因 AI_ENABLED=false 或 AI_API_KEY 空被跳过, 写一条 status=error 的 ai_okr 日志说明跳过原因 这样不需要 kubectl logs 就能定位"为什么 AI 没跑"。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
33b3a2208e
commit
08ec749cd8
@ -1,6 +1,9 @@
|
|||||||
|
import { v4 as uuid } from 'uuid';
|
||||||
import { Cron } from 'croner';
|
import { Cron } from 'croner';
|
||||||
import { syncGitea } from './sync-gitea';
|
import { syncGitea } from './sync-gitea';
|
||||||
import { analyzeCommitsForOKR } from '../services/okr-ai-sync';
|
import { analyzeCommitsForOKR } from '../services/okr-ai-sync';
|
||||||
|
import { db } from '../db/index';
|
||||||
|
import { syncLogs } from '../db/schema';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
|
|
||||||
let giteaJob: Cron | null = null;
|
let giteaJob: Cron | null = null;
|
||||||
@ -12,6 +15,17 @@ async function runSyncAndAnalyze() {
|
|||||||
await analyzeCommitsForOKR().catch(e =>
|
await analyzeCommitsForOKR().catch(e =>
|
||||||
console.error('[SCHEDULER] AI OKR 分析失败:', e)
|
console.error('[SCHEDULER] AI OKR 分析失败:', e)
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
const reason = !config.AI_ENABLED ? 'AI_ENABLED=false' : 'AI_API_KEY 为空';
|
||||||
|
console.warn(`[SCHEDULER] 跳过 AI 分析: ${reason}`);
|
||||||
|
await db.insert(syncLogs).values({
|
||||||
|
id: uuid(),
|
||||||
|
source: 'ai_okr',
|
||||||
|
status: 'error',
|
||||||
|
message: `AI 分析被跳过: ${reason} (AI_ENABLED=${config.AI_ENABLED}, AI_API_KEY length=${config.AI_API_KEY?.length || 0}, AI_MODEL=${config.AI_MODEL})`,
|
||||||
|
recordsProcessed: 0,
|
||||||
|
syncedAt: new Date(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +36,17 @@ export function startScheduler(): void {
|
|||||||
await runSyncAndAnalyze();
|
await runSyncAndAnalyze();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.info('[SCHEDULER] Gitea 自动同步已启动(每天 02:00 + 19:00)');
|
console.info(`[SCHEDULER] Gitea 自动同步已启动(每天 02:00 + 19:00 UTC), AI_ENABLED=${config.AI_ENABLED}, AI_API_KEY length=${config.AI_API_KEY?.length || 0}`);
|
||||||
|
|
||||||
|
// 启动时立刻写一条诊断日志(不阻塞)
|
||||||
|
db.insert(syncLogs).values({
|
||||||
|
id: uuid(),
|
||||||
|
source: 'ai_okr',
|
||||||
|
status: 'success',
|
||||||
|
message: `[BOOT] Scheduler started. AI_ENABLED=${config.AI_ENABLED}, AI_API_KEY length=${config.AI_API_KEY?.length || 0}, AI_MODEL=${config.AI_MODEL}, AI_BASE_URL=${config.AI_BASE_URL}`,
|
||||||
|
recordsProcessed: 0,
|
||||||
|
syncedAt: new Date(),
|
||||||
|
}).catch(e => console.error('[SCHEDULER] 启动诊断日志写入失败:', e));
|
||||||
|
|
||||||
// 启动后 10 秒执行一次首次同步
|
// 启动后 10 秒执行一次首次同步
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user