Compare commits
No commits in common. "development" and "1.2.1" have entirely different histories.
developmen
...
1.2.1
@ -279,9 +279,7 @@ func (c *Client) DispenserStart(ctx context.Context) (string, error) {
|
||||
return stockStatus, fmt.Errorf("[%s] check status: %w", funcName, err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
logStatus(status)
|
||||
}()
|
||||
stockStatus = stockTake(status)
|
||||
c.setStock(status)
|
||||
|
||||
@ -296,75 +294,48 @@ func (c *Client) DispenserStart(ctx context.Context) (string, error) {
|
||||
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
|
||||
}
|
||||
|
||||
deadline := time.Now().Add(6 * time.Second)
|
||||
|
||||
for {
|
||||
time.Sleep(delay * 2)
|
||||
if time.Now().After(deadline) {
|
||||
return stockStatus, nil
|
||||
time.Sleep(delay)
|
||||
status, err = c.CheckStatus(ctx)
|
||||
if err != nil {
|
||||
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
|
||||
}
|
||||
|
||||
status, _ = c.do(ctx, cmdStatus)
|
||||
|
||||
logStatus(status)
|
||||
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) {
|
||||
const funcName = "DispenserFinal"
|
||||
stockStatus := ""
|
||||
var status []byte
|
||||
|
||||
if err := c.OutOfMouth(ctx); err != nil {
|
||||
return stockStatus, fmt.Errorf("[%s] out of mouth: %w", funcName, err)
|
||||
}
|
||||
|
||||
time.Sleep(delay)
|
||||
status, err := c.do(ctx, cmdStatus)
|
||||
if err == nil && len(status) >= 4 {
|
||||
c.setStock(status)
|
||||
status, err := c.CheckStatus(ctx)
|
||||
if err != nil {
|
||||
return stockStatus, fmt.Errorf("[%s] check status: %w", funcName, err)
|
||||
}
|
||||
logStatus(status)
|
||||
stockStatus = stockTake(status)
|
||||
c.setStock(status)
|
||||
|
||||
time.Sleep(delay)
|
||||
if err := c.ToEncoder(ctx); err != nil {
|
||||
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
logStatus(status)
|
||||
}()
|
||||
|
||||
deadline := time.Now().Add(6 * time.Second)
|
||||
|
||||
for {
|
||||
time.Sleep(delay * 2)
|
||||
if time.Now().After(deadline) {
|
||||
return stockStatus, nil
|
||||
time.Sleep(delay)
|
||||
status, err = c.CheckStatus(ctx)
|
||||
if err != nil {
|
||||
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
|
||||
}
|
||||
|
||||
status, _ = c.do(ctx, cmdStatus)
|
||||
|
||||
logStatus(status)
|
||||
stockStatus = stockTake(status)
|
||||
c.setStock(status)
|
||||
logStatus(status)
|
||||
|
||||
if isCardWellEmpty(status) {
|
||||
return stockStatus, nil
|
||||
}
|
||||
|
||||
if isAtEncoderPosition(status) {
|
||||
return stockStatus, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +191,6 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
|
||||
writeTransactionResult(w, http.StatusServiceUnavailable, theResponse)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
|
||||
@ -192,13 +192,8 @@ func (app *App) onChipDNAError(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *App) handleAvailabilityDebounced(isAvailable bool) {
|
||||
const (
|
||||
debounceDay = 30
|
||||
debounceNight = 600
|
||||
title = "ChipDNA Error"
|
||||
)
|
||||
|
||||
key := app.availabilityKey()
|
||||
title := "ChipDNA Error"
|
||||
key := fmt.Sprintf("%s-%d", app.cfg.Hotel, app.cfg.Kiosk)
|
||||
|
||||
app.availabilityMu.Lock()
|
||||
defer app.availabilityMu.Unlock()
|
||||
@ -218,21 +213,14 @@ func (app *App) handleAvailabilityDebounced(isAvailable bool) {
|
||||
return
|
||||
}
|
||||
|
||||
debounce := debounceDay
|
||||
log.Println("PDQ reported unavailable - starting 10s debounce timer")
|
||||
|
||||
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() {
|
||||
timer := time.AfterFunc(60*time.Second, func() {
|
||||
mail.SendEmailOnError(
|
||||
app.cfg.Hotel,
|
||||
app.cfg.Kiosk,
|
||||
title,
|
||||
fmt.Sprintf("ChipDNA PDQ unavailable for more than %d seconds", debounce),
|
||||
"ChipDNA PDQ unavailable for more than 60 seconds",
|
||||
)
|
||||
|
||||
app.availabilityMu.Lock()
|
||||
@ -242,11 +230,3 @@ 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,
|
||||
)
|
||||
}
|
||||
|
||||
4
main.go
4
main.go
@ -29,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
buildVersion = "1.2.5"
|
||||
buildVersion = "1.2.1"
|
||||
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("\nPDQ availabile: %v\n", pdqstatus.IsAvailable)
|
||||
fmt.Printf("PDQ availabile: %v\n", pdqstatus.IsAvailable)
|
||||
log.Infof("PDQ availabile: %v", pdqstatus.IsAvailable)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -2,19 +2,6 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user