Compare commits
4 Commits
1.2.1
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| c6c2b40f37 | |||
| 8f093159cd | |||
| e1549dda2f | |||
| 163ac0e808 |
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
logStatus(status)
|
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 {
|
for {
|
||||||
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
|
time.Sleep(delay * 2)
|
||||||
|
if time.Now().After(deadline) {
|
||||||
|
return stockStatus, nil
|
||||||
}
|
}
|
||||||
logStatus(status)
|
|
||||||
|
status, _ = c.do(ctx, cmdStatus)
|
||||||
|
|
||||||
stockStatus = stockTake(status)
|
stockStatus = stockTake(status)
|
||||||
c.setStock(status)
|
c.setStock(status)
|
||||||
|
logStatus(status)
|
||||||
|
|
||||||
|
// error states first
|
||||||
|
if isCardWellEmpty(status) {
|
||||||
|
return stockStatus, fmt.Errorf(stockStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
if isAtEncoderPosition(status) {
|
||||||
return stockStatus, nil
|
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)
|
|
||||||
}
|
|
||||||
logStatus(status)
|
|
||||||
stockStatus = stockTake(status)
|
|
||||||
c.setStock(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)
|
|
||||||
if err != nil {
|
|
||||||
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
|
|
||||||
}
|
|
||||||
logStatus(status)
|
logStatus(status)
|
||||||
stockStatus = stockTake(status)
|
}()
|
||||||
c.setStock(status)
|
|
||||||
|
|
||||||
|
deadline := time.Now().Add(6 * time.Second)
|
||||||
|
|
||||||
|
for {
|
||||||
|
time.Sleep(delay * 2)
|
||||||
|
if time.Now().After(deadline) {
|
||||||
return stockStatus, nil
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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(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(
|
mail.SendEmailOnError(
|
||||||
app.cfg.Hotel,
|
app.cfg.Hotel,
|
||||||
app.cfg.Kiosk,
|
app.cfg.Kiosk,
|
||||||
title,
|
title,
|
||||||
"ChipDNA PDQ unavailable for more than 60 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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
4
main.go
4
main.go
@ -29,7 +29,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
buildVersion = "1.2.1"
|
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)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@ -2,6 +2,19 @@
|
|||||||
|
|
||||||
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
|
#### 1.2.1 - 09 February 2026
|
||||||
increased waiting time befor sending email on PDQ unavailability to 60 seconds
|
increased waiting time befor sending email on PDQ unavailability to 60 seconds
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user