fix: 중복 인쇄 race condition 수정
문제: Set에 추가하는 타이밍이 인쇄 완료 후라서
비동기로 2개 요청이 거의 동시에 들어오면 둘 다 통과
해결: 요청 전에 먼저 Set에 추가
실패/오류 시에만 Set에서 제거 (재시도 가능)
This commit is contained in:
parent
c7169e6679
commit
ebd4669d24
@ -2687,11 +2687,13 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 중복 인쇄 방지
|
||||
// 2. 중복 인쇄 방지 (요청 전에 먼저 체크 & 추가!)
|
||||
if (window.printedSerials.has(preSerial)) {
|
||||
console.log('[AutoPrint] 이미 인쇄됨, 스킵:', preSerial);
|
||||
return;
|
||||
}
|
||||
// 즉시 Set에 추가 (비동기 race condition 방지)
|
||||
window.printedSerials.add(preSerial);
|
||||
|
||||
// 3. 인쇄 진행
|
||||
try {
|
||||
@ -2710,20 +2712,22 @@
|
||||
|
||||
var data = await response.json();
|
||||
if (data.success) {
|
||||
// 인쇄 성공 → Set에 추가 (중복 방지)
|
||||
window.printedSerials.add(preSerial);
|
||||
console.log('[AutoPrint] ' + now + ' ✅ 인쇄 완료:', preSerial, patientName);
|
||||
window.showToast('🖨️ ' + patientName, 'success');
|
||||
|
||||
// 5분 후 Set에서 제거 (메모리 관리)
|
||||
setTimeout(function() {
|
||||
window.printedSerials.delete(preSerial);
|
||||
}, 5 * 60 * 1000);
|
||||
} else {
|
||||
// 실패 시 Set에서 제거 (재시도 가능하도록)
|
||||
window.printedSerials.delete(preSerial);
|
||||
console.error('[AutoPrint] ' + now + ' ❌ 실패:', preSerial, data.error);
|
||||
window.showToast('인쇄 실패: ' + patientName, 'error');
|
||||
}
|
||||
|
||||
// 5분 후 Set에서 제거 (메모리 관리)
|
||||
setTimeout(function() {
|
||||
window.printedSerials.delete(preSerial);
|
||||
}, 5 * 60 * 1000);
|
||||
} catch (err) {
|
||||
// 오류 시 Set에서 제거
|
||||
window.printedSerials.delete(preSerial);
|
||||
console.error('[AutoPrint] 오류:', preSerial, err);
|
||||
window.showToast('인쇄 오류', 'error');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user