added debounceNight 10 minutes

This commit is contained in:
2026-03-11 18:47:06 +00:00
parent 19cfbf185b
commit 163ac0e808
3 changed files with 31 additions and 7 deletions
+25 -5
View File
@@ -192,8 +192,13 @@ func (app *App) onChipDNAError(w http.ResponseWriter, r *http.Request) {
}
func (app *App) handleAvailabilityDebounced(isAvailable bool) {
title := "ChipDNA Error"
key := fmt.Sprintf("%s-%d", app.cfg.Hotel, app.cfg.Kiosk)
const (
debounceDay = 30
debounceNight = 600
title = "ChipDNA Error"
)
key := app.availabilityKey()
app.availabilityMu.Lock()
defer app.availabilityMu.Unlock()
@@ -213,14 +218,21 @@ func (app *App) handleAvailabilityDebounced(isAvailable bool) {
return
}
log.Println("PDQ reported unavailable - starting 10s debounce timer")
debounce := debounceDay
timer := time.AfterFunc(60*time.Second, func() {
hour := time.Now().Hour()
if hour < 6 {
debounce = debounceNight
}
log.Printf("PDQ reported unavailable - starting %ds debounce timer", debounce)
timer := time.AfterFunc(time.Duration(debounce)*time.Second, func() {
mail.SendEmailOnError(
app.cfg.Hotel,
app.cfg.Kiosk,
title,
"ChipDNA PDQ unavailable for more than 60 seconds",
fmt.Sprintf("ChipDNA PDQ unavailable for more than %d seconds", debounce),
)
app.availabilityMu.Lock()
@@ -230,3 +242,11 @@ func (app *App) handleAvailabilityDebounced(isAvailable bool) {
app.availabilityTimers[key] = timer
}
func (app *App) availabilityKey() string {
return fmt.Sprintf("hotel=%s|kiosk=%d|app=%p",
strings.TrimSpace(app.cfg.Hotel),
app.cfg.Kiosk,
app,
)
}