fix(weather_kma): 단기예보 NO_DATA(03)면 직전 발표로 최대 2회 재시도
발표 직후(11:04)에 API가 일시적으로 NO_DATA를 내 모델이 openmeteo로 빠지고 기상청 값이 답에서 사라졌다. 03이면 3시간 전 발표 기준으로 내려가 다시 받는다. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6233861f6
commit
1bfc60e57f
1 file changed
+16
-2
+16
-2
@@ -1754,8 +1754,22 @@ export const weatherKmaTool = {
|
||||
if (ultra.length) lines.splice(lines.length - 2, 0, ...ultra, '');
|
||||
return { success: true, stdout: lines.join('\n'), data: { location: displayName, nx, ny, items, todayRain, aws, episode, fogLine } };
|
||||
} else {
|
||||
const { base_date, base_time } = getKmaBaseDateTime('fcst');
|
||||
const items = await kmaFetch('getVilageFcst', { base_date, base_time, nx: String(nx), ny: String(ny) });
|
||||
// 2026-10-14: 발표 직후(11:04 등) API가 NO_DATA(03)를 내는 순간이 있다. 이때 모델이 openmeteo로
|
||||
// 도망가 기상청 값이 답에서 빠졌다. 03이면 직전 발표(3시간 전)로 최대 2번 내려가 다시 받는다.
|
||||
let { base_date, base_time } = getKmaBaseDateTime('fcst');
|
||||
let items: any[];
|
||||
for (let attempt = 0; ; attempt++) {
|
||||
try {
|
||||
items = await kmaFetch('getVilageFcst', { base_date, base_time, nx: String(nx), ny: String(ny) });
|
||||
break;
|
||||
} catch (e: any) {
|
||||
if (attempt >= 2 || !/\(03\)|NO_DATA/.test(String(e?.message || ''))) throw e;
|
||||
const t = new Date(Date.UTC(+base_date.slice(0, 4), +base_date.slice(4, 6) - 1, +base_date.slice(6, 8), +base_time.slice(0, 2)) - 3 * 3600_000);
|
||||
base_date = `${t.getUTCFullYear()}${String(t.getUTCMonth() + 1).padStart(2, '0')}${String(t.getUTCDate()).padStart(2, '0')}`;
|
||||
base_time = `${String(t.getUTCHours()).padStart(2, '0')}00`;
|
||||
console.log(`[weather_kma] 단기예보 NO_DATA → 직전 발표 ${base_date} ${base_time}로 재시도`);
|
||||
}
|
||||
}
|
||||
|
||||
// Group forecast by date
|
||||
const byDay: Record<string, Record<string, string[]>> = {};
|
||||
|
||||
Reference in new issue
Block a user