Compare commits

...

5 Commits

5 changed files with 100 additions and 32 deletions

View File

@ -279,7 +279,9 @@ func (c *Client) DispenserStart(ctx context.Context) (string, error) {
return stockStatus, fmt.Errorf("[%s] check status: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] check status: %w", funcName, err)
} }
logStatus(status) defer func() {
logStatus(status)
}()
stockStatus = stockTake(status) stockStatus = stockTake(status)
c.setStock(status) c.setStock(status)
@ -294,48 +296,75 @@ func (c *Client) DispenserStart(ctx context.Context) (string, error) {
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
} }
time.Sleep(delay) deadline := time.Now().Add(6 * time.Second)
status, err = c.CheckStatus(ctx)
if err != nil {
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
}
logStatus(status)
stockStatus = stockTake(status)
c.setStock(status)
return stockStatus, nil for {
time.Sleep(delay * 2)
if time.Now().After(deadline) {
return stockStatus, nil
}
status, _ = c.do(ctx, cmdStatus)
stockStatus = stockTake(status)
c.setStock(status)
logStatus(status)
// error states first
if isCardWellEmpty(status) {
return stockStatus, fmt.Errorf(stockStatus)
}
if isAtEncoderPosition(status) {
return stockStatus, nil
}
}
} }
func (c *Client) DispenserFinal(ctx context.Context) (string, error) { func (c *Client) DispenserFinal(ctx context.Context) (string, error) {
const funcName = "DispenserFinal" const funcName = "DispenserFinal"
stockStatus := "" stockStatus := ""
var status []byte
if err := c.OutOfMouth(ctx); err != nil { if err := c.OutOfMouth(ctx); err != nil {
return stockStatus, fmt.Errorf("[%s] out of mouth: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] out of mouth: %w", funcName, err)
} }
time.Sleep(delay) time.Sleep(delay)
status, err := c.CheckStatus(ctx) status, err := c.do(ctx, cmdStatus)
if err != nil { if err == nil && len(status) >= 4 {
return stockStatus, fmt.Errorf("[%s] check status: %w", funcName, err) c.setStock(status)
} }
logStatus(status)
stockStatus = stockTake(status)
c.setStock(status)
time.Sleep(delay) time.Sleep(delay)
if err := c.ToEncoder(ctx); err != nil { if err := c.ToEncoder(ctx); err != nil {
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
} }
time.Sleep(delay) defer func() {
status, err = c.CheckStatus(ctx) logStatus(status)
if err != nil { }()
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
}
logStatus(status)
stockStatus = stockTake(status)
c.setStock(status)
return stockStatus, nil deadline := time.Now().Add(6 * time.Second)
for {
time.Sleep(delay * 2)
if time.Now().After(deadline) {
return stockStatus, nil
}
status, _ = c.do(ctx, cmdStatus)
stockStatus = stockTake(status)
c.setStock(status)
logStatus(status)
if isCardWellEmpty(status) {
return stockStatus, nil
}
if isAtEncoderPosition(status) {
return stockStatus, nil
}
}
} }

View File

@ -191,6 +191,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
writeTransactionResult(w, http.StatusServiceUnavailable, theResponse) writeTransactionResult(w, http.StatusServiceUnavailable, theResponse)
return return
} }
} }
if r.Method == http.MethodOptions { if r.Method == http.MethodOptions {

View File

@ -192,8 +192,13 @@ func (app *App) onChipDNAError(w http.ResponseWriter, r *http.Request) {
} }
func (app *App) handleAvailabilityDebounced(isAvailable bool) { func (app *App) handleAvailabilityDebounced(isAvailable bool) {
title := "ChipDNA Error" const (
key := fmt.Sprintf("%s-%d", app.cfg.Hotel, app.cfg.Kiosk) debounceDay = 30
debounceNight = 600
title = "ChipDNA Error"
)
key := app.availabilityKey()
app.availabilityMu.Lock() app.availabilityMu.Lock()
defer app.availabilityMu.Unlock() defer app.availabilityMu.Unlock()
@ -213,14 +218,21 @@ func (app *App) handleAvailabilityDebounced(isAvailable bool) {
return return
} }
log.Println("PDQ reported unavailable - starting 10s debounce timer") debounce := debounceDay
timer := time.AfterFunc(5*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( mail.SendEmailOnError(
app.cfg.Hotel, app.cfg.Hotel,
app.cfg.Kiosk, app.cfg.Kiosk,
title, title,
"ChipDNA PDQ unavailable for more than 5 seconds", fmt.Sprintf("ChipDNA PDQ unavailable for more than %d seconds", debounce),
) )
app.availabilityMu.Lock() app.availabilityMu.Lock()
@ -230,3 +242,11 @@ func (app *App) handleAvailabilityDebounced(isAvailable bool) {
app.availabilityTimers[key] = timer 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 ( const (
buildVersion = "1.2.0" buildVersion = "1.2.5"
serviceName = "hardlink" serviceName = "hardlink"
pollingFrequency = 8 * time.Second pollingFrequency = 8 * time.Second
) )
@ -127,7 +127,7 @@ func main() {
if err != nil { if err != nil {
mail.SendEmailOnError(cfg.Hotel, cfg.Kiosk, "PDQ Status Read Error", err.Error()) mail.SendEmailOnError(cfg.Hotel, cfg.Kiosk, "PDQ Status Read Error", err.Error())
} else { } else {
fmt.Printf("PDQ availabile: %v\n", pdqstatus.IsAvailable) fmt.Printf("\nPDQ availabile: %v\n", pdqstatus.IsAvailable)
log.Infof("PDQ availabile: %v", pdqstatus.IsAvailable) log.Infof("PDQ availabile: %v", pdqstatus.IsAvailable)
} }
}() }()
@ -205,6 +205,7 @@ func startChipDnaClient() {
err := cmd.Wait() err := cmd.Wait()
if err != nil { if err != nil {
log.Errorf("ChipDnaClient exited unexpectedly: %v", err) log.Errorf("ChipDnaClient exited unexpectedly: %v", err)
fmt.Printf("ChipDnaClient exited unexpectedly: %v", err)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
cmd, err = startClient() cmd, err = startClient()
if err != nil { if err != nil {
@ -212,6 +213,7 @@ func startChipDnaClient() {
return return
} }
log.Info("ChipDnaClient restarted successfully") log.Info("ChipDnaClient restarted successfully")
fmt.Printf("ChipDnaClient restarted successfully")
} }
} }
}() }()

View File

@ -2,6 +2,22 @@
builtVersion is a const in main.go builtVersion is a const in main.go
#### 1.2.5 - 20 March 2026
removed early return on error when checking dispenser status in the start and final loops.
#### 1.2.4 - 18 March 2026
added check if keycard at the encoder position before trying to encode key
#### 1.2.3 - 17 March 2026
added check if keycard at the encoder position before trying to encode key
#### 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
#### 1.2.0 - 09 February 2026 #### 1.2.0 - 09 February 2026
added testissuedoorcard endpoint for testing the full workflow of encoding a door card without moving the card out added testissuedoorcard endpoint for testing the full workflow of encoding a door card without moving the card out
added ping-pdq endpoint to check the status of the pdq terminal added ping-pdq endpoint to check the status of the pdq terminal