feat(dispenser): recover K720 card position during uncertain encoding
This commit is contained in:
@@ -29,6 +29,8 @@ import (
|
||||
type doorCardDispenser interface {
|
||||
BeginForeground() func()
|
||||
PrepareCurrentCard(context.Context) (string, error)
|
||||
PrepareCurrentCardForEncoding(context.Context) (dispenser.PreparationResult, error)
|
||||
RecoverCurrentCard(context.Context, dispenser.PreparationResult) error
|
||||
DeliverCurrentCard(context.Context) (string, error)
|
||||
BeginPrepareNextCard(context.Context) error
|
||||
PrepareNextCard(context.Context) (string, error)
|
||||
@@ -294,8 +296,8 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
release := app.disp.BeginForeground()
|
||||
defer release()
|
||||
|
||||
status, err := app.disp.PrepareCurrentCard(r.Context())
|
||||
app.SetCardWellStatus(status)
|
||||
preparation, err := app.disp.PrepareCurrentCardForEncoding(r.Context())
|
||||
app.SetCardWellStatus(preparation.Stock)
|
||||
if err != nil {
|
||||
logging.Error(types.ServiceName, err.Error(), "Dispense error", string(op), "", "", 0)
|
||||
if errors.Is(err, dispenser.ErrCardWellEmpty) {
|
||||
@@ -317,8 +319,28 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
||||
// Each request performs at most one encoder operation.
|
||||
encodingStarted := time.Now()
|
||||
log.Info("LockSequence started")
|
||||
var stopRecovery context.CancelCauseFunc
|
||||
var recoveryDone chan struct{}
|
||||
if preparation.UncertainHandoff {
|
||||
log.Infof("uncertain handoff; concurrent K720 recovery enabled; shakes=%d", preparation.ShakesUsed)
|
||||
var recoveryCtx context.Context
|
||||
recoveryCtx, stopRecovery = context.WithCancelCause(r.Context())
|
||||
recoveryDone = make(chan struct{})
|
||||
go func() {
|
||||
defer close(recoveryDone)
|
||||
if err := app.disp.RecoverCurrentCard(recoveryCtx, preparation); err != nil && recoveryCtx.Err() == nil {
|
||||
log.WithError(err).Warn("K720 recovery failed; awaiting original LockSequence result")
|
||||
}
|
||||
}()
|
||||
}
|
||||
encodingErr := app.lockserver.LockSequence()
|
||||
if stopRecovery != nil {
|
||||
stopRecovery(errors.New("LockSequence completed"))
|
||||
}
|
||||
log.Infof("LockSequence finished; success=%t duration=%s", encodingErr == nil, time.Since(encodingStarted))
|
||||
if recoveryDone != nil {
|
||||
<-recoveryDone
|
||||
}
|
||||
if encodingErr != nil {
|
||||
logging.Error(types.ServiceName, encodingErr.Error(), "Key encoding", string(op), "", "", 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user