ingredient/locker: Unlock even after cancel

This commit is contained in:
Tom Wiesing 2022-12-05 14:01:53 +01:00
parent 7006277409
commit b86e6294de
No known key found for this signature in database
2 changed files with 73 additions and 1 deletions

View file

@ -2,9 +2,11 @@ package locker
import (
"context"
"time"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
"github.com/FAU-CDI/wisski-distillery/pkg/cancel"
"github.com/tkw1536/goprogram/exit"
)
@ -34,8 +36,11 @@ func (lock *Locker) TryLock(ctx context.Context) bool {
}
// TryUnlock attempts to unlock this WissKI and reports if it succeeded.
// An unlock can only
// An Unlock is also attempted when ctx is cancelled.
func (lock *Locker) TryUnlock(ctx context.Context) bool {
ctx, close := cancel.Anyways(ctx, time.Second)
defer close()
table, err := lock.Malt.SQL.QueryTable(ctx, true, models.LockTable)
if err != nil {
return false