feat(performance): 매출 업데이트 취소 버튼

- 진행 창 [업데이트 취소](시작한 사람·관리자) → POST /api/sync/jobs/{id}/cancel
- 어댑터가 API 호출 직전마다 ctx.progress.check() — 취소면 Cancelled 로 멈추고 저장하지 않음(기존 매출 그대로),
  차례가 안 온 쇼핑몰은 취소됨으로 건너뜀, 이미 끝난 쇼핑몰 결과는 유지
- 취소 실행은 perf_sync_runs failed + 업데이트 취소, 연결 상태는 바꾸지 않음
- 테스트 1개 추가(30개 통과), performance.js/css 캐시 버전, 문서 갱신

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 15:06:25 +09:00
parent 8b3e6dffc5
commit da63b93302
14 changed files with 178 additions and 21 deletions
@@ -1340,6 +1340,51 @@ def test_gsshop_collect_sales():
assert rec["days"][1]["amount"] == -17000 and rec["days"][1]["claimed"] == 17000
def test_sync_job_cancel():
"""[업데이트 취소]: 수집 중인 쇼핑몰은 다음 API 호출 직전에 멈추고 저장하지 않는다(기존 매출 그대로),
차례가 안 온 쇼핑몰은 취소됨으로 건너뛴다. 연결 상태(오류)는 기록하지 않는다."""
import bcrypt
import httpx
from app.modules.performance import jobs
from app.modules.performance.adapters import naver as nv
job = jobs.create_job(user="king@x", start=None, end=None)
days = []
def get(url, params=None, headers=None, timeout=None):
days.append(params["from"][:10])
if len(days) == 2:
job.cancel("king@x") # 둘째 날을 받는 도중 취소
rows = [_naver_item("A" + days[-1], "P" + days[-1], days[-1], 10000)]
return httpx.Response(200, json={"data": {"contents": rows, "pagination": {"hasNext": False}}})
st = FakeStore()
st.markets = [m for m in st.markets if m["code"] in ("naver", "gsshop")]
creds = CredentialService(st, lambda: ring())
creds.save(next(a for a in all_adapters() if a.code == "naver"),
{"client_id": "app-id", "client_secret": bcrypt.gensalt(rounds=4).decode()})
creds.save(next(a for a in all_adapters() if a.code == "gsshop"),
{"vendor_code": "1047142", "api_key": "0123456789abcdef0123456789ABCDEF"})
st.events[("naver", "SALE", "naver:OLD")] = {"amount": 5000, "is_sample": False, "sales_date": date(2026, 9, 10)}
orig = (httpx.post, httpx.get, nv.CALL_INTERVAL_SEC)
httpx.post = lambda url, data=None, timeout=None, headers=None: httpx.Response(200, json={"access_token": "T", "expires_in": 10799})
httpx.get, nv.CALL_INTERVAL_SEC = get, 0
try:
res = SyncService(st, creds).sync_all(start=date(2026, 9, 9), end=date(2026, 9, 12), user="king@x", job=job)
finally:
httpx.post, httpx.get, nv.CALL_INTERVAL_SEC = orig
job.finish()
assert days == ["2026-09-09", "2026-09-10"] # 셋째 날은 부르지 않음
assert [r.get("cancelled") for r in res] == [True, True]
snap = {s["code"]: s for s in job.snapshot()["shops"]}
assert snap["naver"]["state"] == "cancelled" and snap["gsshop"]["state"] == "cancelled"
assert list(st.events) == [("naver", "SALE", "naver:OLD")] # 저장 안 함 — 기존 매출 그대로
assert "naver" not in st.status and "gsshop" not in st.status # 연결 상태 안 바뀜
snapshot = job.snapshot()
assert snapshot["cancel_requested"] and snapshot["overall"]["finished"] == 2 and snapshot["overall"]["fraction"] == 1.0
if __name__ == "__main__":
os.environ.pop("APP_ENCRYPTION_KEY", None)
n = 0