From 163ac0e8084d0190e44b9d8cb020088884126a73 Mon Sep 17 00:00:00 2001 From: yurii Date: Wed, 11 Mar 2026 18:47:06 +0000 Subject: [PATCH] added debounceNight 10 minutes --- handlers/testhandlers.go | 30 +++++++++++++++++++++++++----- main.go | 4 ++-- release notes.md | 4 ++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/handlers/testhandlers.go b/handlers/testhandlers.go index 7e388a6..17767f7 100644 --- a/handlers/testhandlers.go +++ b/handlers/testhandlers.go @@ -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, + ) +} diff --git a/main.go b/main.go index 39e2225..2664aa1 100644 --- a/main.go +++ b/main.go @@ -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) } }() diff --git a/release notes.md b/release notes.md index 9c6cbcf..9a2165c 100644 --- a/release notes.md +++ b/release notes.md @@ -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