재생목록 검토: 서버 DB 곡으로 바꾼 스포티파이 곡도 그 영상의 다른 사이트 재생을 확인(막혔으면 재생 불가 → 엑셀의 빠진 곡) — DB 상태만 믿고 건너뛰던 것, 회귀 테스트. 재생목록으로 엑셀 만들기: 검토 상황 조회가 한 번 실패하면 다음 조회가 없어 '검토 중'에 멈추던 것 — 실패해도 점점 느리게 계속 묻고(연결 다시 시도 중 표시, 알림은 처음 한 번), 작업이 없어졌으면(404) 실패로 끝냄. e2e: 첫 조회 502 뒤에도 엑셀 받기까지

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-11-03 23:24:18 +09:00
parent 70edadfe36
commit 4e2b81c224
4 changed files with 60 additions and 11 deletions

View File

@@ -5,7 +5,7 @@
*/
import { useEffect, useMemo, useState } from 'react';
import { playlistSheets, writeXlsxSheets, type PlaylistSheetRow } from '@mq/shared/lite';
import { apiCall } from '../../net/api';
import { ApiError, apiCall } from '../../net/api';
import { toast } from '../../store/toast';
import { download } from './QuizFile';
@@ -23,17 +23,31 @@ export function PlaylistSheet({ onClose }: { onClose: () => void }) {
const [url, setUrl] = useState('');
const [job, setJob] = useState<ImportJob | null>(null);
const [busy, setBusy] = useState(false);
/** Polls in a row that failed: the job goes on on the server, so polling keeps going (slower) until it answers. */
const [fails, setFails] = useState(0);
useEffect(() => {
if (!job || job.status !== 'running') return;
const t = setTimeout(() => {
apiCall<{ job: ImportJob }>('GET', `/api/admin/quizzes/pick/playlist/${job.id}`)
.then((r) => setJob(r.job))
.catch((e: Error) => toast(e.message, 'error'));
}, 1000);
const t = setTimeout(
() => {
apiCall<{ job: ImportJob }>('GET', `/api/admin/quizzes/pick/playlist/${job.id}`)
.then((r) => {
setFails(0);
setJob(r.job);
})
.catch((e: ApiError) => {
// the job is gone (server restarted or an hour passed): nothing more will come
if (e.status === 404) return setJob({ ...job, status: 'failed', error: `${e.message} 다시 검토해 주세요.` });
if (!fails) toast(`검토 상황을 못 받았어요. 계속 다시 물어볼게요: ${e.message}`, 'error');
setFails((n) => n + 1);
});
},
fails ? Math.min(10_000, 1000 * 2 ** fails) : 1000,
);
return () => clearTimeout(t);
}, [job]);
}, [job, fails]);
const begin = async () => {
setBusy(true);
setFails(0);
try {
setJob((await apiCall<{ job: ImportJob }>('POST', '/api/admin/quizzes/pick/playlist', { url: url.trim() })).job);
} catch (e) {
@@ -75,7 +89,7 @@ export function PlaylistSheet({ onClose }: { onClose: () => void }) {
{job && (
<div className="stack" style={{ gap: 4 }}>
<span className="small">
<b>{job.name || '재생목록'}</b> · {job.status === 'running' ? `검토 중 ${job.done}/${job.total}곡` : job.status === 'failed' ? `실패: ${job.error}` : `${job.total}곡 검토 끝`}
<b>{job.name || '재생목록'}</b> · {job.status === 'running' ? `검토 중 ${job.done}/${job.total}곡${fails ? ' (연결 다시 시도 중)' : ''}` : job.status === 'failed' ? `실패: ${job.error}` : `${job.total}곡 검토 끝`}
{sheets && (
<span className="muted">
{' '}