added debounceNight 10 minutes

This commit is contained in:
yurii 2026-03-11 18:47:06 +00:00
parent 19cfbf185b
commit 163ac0e808
3 changed files with 31 additions and 7 deletions

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,
)
}

View File

@ -29,7 +29,7 @@ import (
)
const (
buildVersion = "1.2.1"
buildVersion = "1.2.2"
serviceName = "hardlink"
pollingFrequency = 8 * time.Second
)
@ -127,7 +127,7 @@ func main() {
if err != nil {
mail.SendEmailOnError(cfg.Hotel, cfg.Kiosk, "PDQ Status Read Error", err.Error())
} else {
fmt.Printf("PDQ availabile: %v\n", pdqstatus.IsAvailable)
fmt.Printf("\nPDQ availabile: %v\n", pdqstatus.IsAvailable)
log.Infof("PDQ availabile: %v", pdqstatus.IsAvailable)
}
}()

View File

@ -2,6 +2,10 @@
builtVersion is a const in main.go
#### 1.2.2 - 11 February 2026
increased waiting time befor sending email on PDQ unavailability to 30 seconds day time and 10 minutes night time
to give it a chance to become available again
#### 1.2.1 - 09 February 2026
increased waiting time befor sending email on PDQ unavailability to 60 seconds