feat(performance): 업데이트 중에도 [매출 업데이트]로 진행 창 다시 보기 · 서버 재시작으로 남은 진행 기록 정리
- 버튼은 업데이트 중 '업데이트 중 · 진행 보기', 누르면 진행 중 작업(수동·자동)을 새로 시작하지 않고 진행 창으로 - 서버 시작 때 perf_sync_runs running 행을 '중단됨(서버 재시작)'으로 정리 — 30분 막힘 방지 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -371,3 +371,6 @@ td.is-link:hover { background: #eef2ff; text-decoration: underline; }
|
||||
.perf-ev-xsub { font-size: 11px; font-weight: 500; color: var(--color-midtone-gray, #777); }
|
||||
.perf-ev-table tfoot .perf-ev-x, .perf-ev-table tfoot .perf-ev-x b { color: #fff; } /* 검은 합계 줄 — 흰 글자 */
|
||||
.perf-ev-table tfoot .perf-ev-xsub { color: #c9c9c9; }
|
||||
/* [매출 업데이트] — 업데이트 중이면 "업데이트 중 · 진행 보기"(눌러서 진행 창 다시 열기), 살짝 깜박임 */
|
||||
#perf-sync-btn.is-running { animation: perf-sync-pulse 1.6s ease-in-out infinite; }
|
||||
@keyframes perf-sync-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .72; } }
|
||||
|
||||
+29
-13
@@ -148,7 +148,8 @@
|
||||
if (job.error) html += '<p class="perf-notice is-warn">' + esc(job.error) + "</p>";
|
||||
box.innerHTML = html;
|
||||
}
|
||||
function runSyncWithProgress(payload, title) {
|
||||
// existing = 이미 돌고 있는 작업(GET /api/sync/current) — 주면 새로 시작하지 않고 그 진행 창만 다시 연다(2026-10-19)
|
||||
function runSyncWithProgress(payload, title, existing) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let timer = null, closed = false, last = null;
|
||||
const m = openModal(title || "매출 업데이트", { narrow: true, onClose: function () { closed = true; clearTimeout(timer); if (last) resolve(last); } });
|
||||
@@ -194,7 +195,8 @@
|
||||
alertMsg("취소 실패: " + err.message);
|
||||
}
|
||||
});
|
||||
api("POST", "/performance/api/sync", Object.assign({ background: true }, payload)).then(function (res) {
|
||||
(existing ? Promise.resolve({ job: existing, joined: true })
|
||||
: api("POST", "/performance/api/sync", Object.assign({ background: true }, payload))).then(function (res) {
|
||||
last = res.job;
|
||||
jobId = res.job.id;
|
||||
const joined = res.joined;
|
||||
@@ -497,15 +499,24 @@
|
||||
const syncBtn = document.getElementById("perf-sync-btn");
|
||||
const resultBox = document.getElementById("perf-sync-result");
|
||||
if (syncBtn) syncBtn.addEventListener("click", async function () {
|
||||
syncBtn.disabled = true;
|
||||
const label = syncBtn.textContent;
|
||||
syncBtn.textContent = "업데이트 중…";
|
||||
if (syncBtn.dataset.busy === "1") return; // 같은 창을 두 번 열지 않게
|
||||
syncBtn.dataset.busy = "1";
|
||||
syncBtn.textContent = "업데이트 중 · 진행 보기";
|
||||
syncBtn.classList.add("is-running");
|
||||
try {
|
||||
// 지금 보고 있는 기간(오늘까지)을 가져온다 — "이번달"이면 1일부터 오늘까지.
|
||||
const from = data.period_start, to = data.period_end < data.today ? data.period_end : data.today;
|
||||
if (from > data.today) throw new Error("앞으로의 기간은 가져올 수 없습니다.");
|
||||
// 진행 창(쇼핑몰별·전체 막대) — 창을 닫아도 서버에서 계속된다.
|
||||
const job = await runSyncWithProgress({ from: from, to: to }, "매출 업데이트 " + from + " ~ " + to);
|
||||
// 이미 돌고 있는 업데이트(다른 사람·자동 업데이트 포함)가 있으면 새로 시작하지 않고 그 진행 창을 다시 연다
|
||||
let cur = null;
|
||||
try { cur = (await api("GET", "/performance/api/sync/current")).job; } catch (_) { cur = null; }
|
||||
let job;
|
||||
if (cur && !cur.finished) {
|
||||
job = await runSyncWithProgress(null, "매출 업데이트 진행 상황 " + (cur.from || "") + " ~ " + (cur.to || ""), cur);
|
||||
} else {
|
||||
// 지금 보고 있는 기간(오늘까지)을 가져온다 — "이번달"이면 1일부터 오늘까지.
|
||||
const from = data.period_start, to = data.period_end < data.today ? data.period_end : data.today;
|
||||
if (from > data.today) throw new Error("앞으로의 기간은 가져올 수 없습니다.");
|
||||
// 진행 창(쇼핑몰별·전체 막대) — 창을 닫아도 서버에서 계속된다.
|
||||
job = await runSyncWithProgress({ from: from, to: to }, "매출 업데이트 " + from + " ~ " + to);
|
||||
}
|
||||
const res = { results: jobResults(job).filter(function (r) { return r.finished; }), last_update_at: job && job.last_update_at };
|
||||
const running = job && !job.finished;
|
||||
// 실패(빨강)는 인증 실패·API 오류처럼 손봐야 하는 것만. 인증정보를 아직 안 넣은 쇼핑몰(미설정)과
|
||||
@@ -530,7 +541,7 @@
|
||||
if (cancelled.length) parts.push("<b>취소됨</b>(기존 매출 그대로) " + esc(cancelled.join(", ")));
|
||||
if (pending.length) parts.push('<span class="perf-muted">연동 준비 중: ' + esc(pending.join(", ")) + "</span>");
|
||||
if (unset.length) parts.push('<span class="perf-muted">인증정보 미설정: ' + esc(unset.join(", ")) + "</span>");
|
||||
if (running) parts.unshift("<b>업데이트가 아직 진행 중입니다</b> — 끝나면 다시 [매출 업데이트]를 눌러 결과를 보세요");
|
||||
if (running) parts.unshift("<b>업데이트가 아직 진행 중입니다</b> — [업데이트 중 · 진행 보기]를 누르면 진행 창을 다시 볼 수 있습니다");
|
||||
resultBox.innerHTML = parts.join(" · ") || "업데이트할 쇼핑몰이 없습니다.";
|
||||
resultBox.className = "perf-notice" + (bad.length ? " is-warn" : " is-ok");
|
||||
resultBox.hidden = false;
|
||||
@@ -539,13 +550,18 @@
|
||||
if (lu) lu.textContent = res.last_update_at.slice(0, 16).replace("T", " ");
|
||||
}
|
||||
if (changed > 0 && !running) setTimeout(function () { location.reload(); }, 800);
|
||||
syncBtn.dataset.running = running ? "1" : ""; // 창을 닫았는데 아직 진행 중 → 버튼은 [업데이트 중 · 진행 보기]
|
||||
} catch (err) {
|
||||
resultBox.textContent = "업데이트 실패: " + err.message;
|
||||
resultBox.className = "perf-notice is-warn";
|
||||
resultBox.hidden = false;
|
||||
syncBtn.dataset.running = "";
|
||||
} finally {
|
||||
syncBtn.disabled = false;
|
||||
syncBtn.textContent = label === "업데이트 중…" ? "매출 업데이트" : label;
|
||||
syncBtn.dataset.busy = "";
|
||||
const still = syncBtn.dataset.running === "1";
|
||||
syncBtn.textContent = still ? "업데이트 중 · 진행 보기" : "매출 업데이트";
|
||||
syncBtn.classList.toggle("is-running", still);
|
||||
syncBtn.title = still ? "업데이트 진행 상황 보기" : "지금 보고 있는 기간의 매출을 쇼핑몰에서 다시 가져옵니다";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user