경기 기록 가져오기 취소 · 재개 보완: 받다가 멈춘 실행(취소 · 게임 시작 · 오류)은 history_pending 으로 남겨 다음 실행이 아는 경기 쪽에서 멈추지 않고 끝까지 훑게 (끝까지 훑은 계정에서 새 경기 일부만 받고 취소하면 나머지를 영영 못 받던 것) · 취소하면 다음 실행은 취소한 때부터 한 주기 뒤 (오래 돈 실행을 취소하면 바로 다시 시작하던 것) · 테스트
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,8 @@ export class HistorySync {
|
||||
if (!this.running || this.cancelled) return { cancelled: false, resumeAt: null };
|
||||
this.cancelled = true;
|
||||
this.prog = null;
|
||||
// 다음 실행은 취소한 때부터 한 주기 뒤 (오래 돈 실행을 취소해도 바로 다시 시작하지 않게)
|
||||
this.lastAt = Date.now();
|
||||
log.info(`${this.src.game} 경기 기록 가져오기: 사용자가 취소함`);
|
||||
return { cancelled: true, resumeAt: this.everyMs ? this.lastAt + this.everyMs : null };
|
||||
}
|
||||
@@ -101,7 +103,10 @@ export class HistorySync {
|
||||
this.cancelled = false;
|
||||
try {
|
||||
const fullKey = `history_full:${this.src.game}:${acct}`;
|
||||
// 받다가 멈춘 실행 (취소 · 게임 시작 · 오류): 받은 경기 뒤쪽에 못 받은 경기가 남아 있으니 이번에는 끝까지 훑는다
|
||||
const pendingKey = `history_pending:${this.src.game}:${acct}`;
|
||||
const full = !!this.store.meta(fullKey);
|
||||
const pending = !!this.store.meta(pendingKey);
|
||||
const skip = this.skipped();
|
||||
const todo: string[] = [];
|
||||
this.prog = { phase: 'scan', first: !full, scanned: 0, done: 0, total: 0, startedAt: Date.now(), etaMs: null };
|
||||
@@ -113,13 +118,14 @@ export class HistorySync {
|
||||
todo.push(...fresh);
|
||||
this.prog = { ...this.prog, scanned: this.prog.scanned + p.ids.length, total: todo.length };
|
||||
if (!p.ids.length || p.ids.length < this.opts.pageSize || (p.total !== null && start + this.opts.pageSize >= p.total)) break;
|
||||
// 한 번 끝까지 훑은 뒤에는 아는 경기만 나오는 쪽에서 멈춘다
|
||||
if (full && !fresh.length) break;
|
||||
// 한 번 끝까지 훑은 뒤에는 아는 경기만 나오는 쪽에서 멈춘다 (지난 실행이 받다가 멈췄으면 끝까지)
|
||||
if (full && !pending && !fresh.length) break;
|
||||
}
|
||||
if (todo.length) log.info(`${this.src.game} 경기 기록: 새 경기 ${todo.length}개 가져오는 중`);
|
||||
let added = 0;
|
||||
this.fetchStartedAt = Date.now();
|
||||
if (this.prog) this.prog = { ...this.prog, phase: 'fetch', done: 0, total: todo.length };
|
||||
if (todo.length && !pending) this.store.setMeta(pendingKey, '1');
|
||||
for (const [i, id] of todo.entries()) {
|
||||
if (this.halted()) {
|
||||
log.info(`${this.src.game} 경기 기록: ${this.cancelled ? '취소해서' : '게임이 시작돼'} 멈춤 (${added}/${todo.length})`);
|
||||
@@ -138,6 +144,7 @@ export class HistorySync {
|
||||
if (this.cancelled) return added;
|
||||
// 끝(또는 max)까지 다 받았다: 다음부터는 새 경기만 본다
|
||||
this.store.setMeta(fullKey, '1');
|
||||
if (this.store.meta(pendingKey)) this.store.setMeta(pendingKey, '');
|
||||
if (added) log.info(`${this.src.game} 경기 기록: ${added}개 저장`);
|
||||
return added;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user