feat(performance): automatic sales update every 30 min, 09:00-19:00 KST

A daemon thread started in the web lifespan runs the same update as the
[매출 업데이트] button at :00 and :30 from 09:00 to 19:00 (21 runs a day),
fetching the last 10 days including today. It runs as a progress job
(user "자동 업데이트", trigger 'schedule'), so a user clicking the button
meanwhile sees the running job. A slot is skipped when another update is
running; overrun slots are not replayed; the slot at server start is not run.

Env: PERFORMANCE_AUTO_SYNC (false = off), PERFORMANCE_AUTO_SYNC_DAYS (10),
PERFORMANCE_AUTO_SYNC_HOURS (9-19).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 05:28:47 +09:00
parent 20a79f5719
commit 822c955bb6
6 changed files with 225 additions and 3 deletions
+8 -1
View File
@@ -282,8 +282,15 @@
## 6. 동기화 (`sync.py`)
- `SyncService.sync_all()` / `sync_marketplace()` — 버튼·향후 cron/worker 공용. 기본 기간: 오늘 포함 최근
- `SyncService.sync_all()` / `sync_marketplace()` — 버튼·자동 업데이트 공용. 기본 기간: 오늘 포함 최근
`PERFORMANCE_SYNC_DAYS`(기본 7)일.
- **자동 업데이트**(`auto_sync.py`, 2026-10-13): 웹 프로세스 시작 때 데몬 스레드(`main._lifespan`) — 매일 **09:00~19:00(KST)
정각·30분마다**(하루 21회) **오늘 포함 최근 10일**을 [매출 업데이트]와 같은 방식(진행 창 작업 `jobs`, `trigger='schedule'`(DB CHECK 허용값),
사용자 "자동 업데이트")으로 다시 가져온다. 그 시각에 다른 업데이트가 돌고 있으면 그 회차는 건너뜀, 30분을 넘긴 회차 뒤엔
밀린 회차를 몰아서 돌리지 않고 다음 회차부터, 서버 시작 시각 회차는 돌리지 않음. 자동 업데이트 중 누가 버튼을 누르면 그 진행
창을 같이 본다(취소는 관리자). 수동 입력 전용 쇼핑몰은 대상 아님. env `PERFORMANCE_AUTO_SYNC`(false=끄기)·
`PERFORMANCE_AUTO_SYNC_DAYS`(10)·`PERFORMANCE_AUTO_SYNC_HOURS`(9-19). uvicorn 단일 워커 기준(여러 프로세스면 회차마다 겹쳐
돌지만 같은 쇼핑몰 동시 실행은 DB 에서 막힘).
- **대시보드 [매출 업데이트]** = 지금 보고 있는 기간(오늘까지)을 `POST /api/sync {from, to}` 로 다시 가져온다
("이번달"이면 1일~오늘). 모듈 권한자는 92일까지, 더 긴 기간(올해 등, 최대 366일)은 관리자만.
- **과거 매출 가져오기**(설정 화면, 관리자): 같은 API 로 임의 기간(최대 366일). 같은 사건은 덮어써서 여러 번 해도 중복 없음.