From 112fbb4c51e3f1770d7b98b7cd2b9da57b9e0fbc Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 20 Jan 2024 11:04:43 -0500 Subject: [PATCH] refactor: moved anon func to private released method --- storage/locker.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/storage/locker.go b/storage/locker.go index 5d242ab..d7e36c4 100644 --- a/storage/locker.go +++ b/storage/locker.go @@ -6,7 +6,6 @@ import ( "git.lumeweb.com/LumeWeb/portal/interfaces" tusd "github.com/tus/tusd/v2/pkg/handler" "go.uber.org/zap" - "gorm.io/gorm" "os" "sync" "time" @@ -37,6 +36,15 @@ func NewMySQLLocker(storage interfaces.StorageService) *MySQLLocker { return &MySQLLocker{storage: storage, HolderPollInterval: 5 * time.Second, AcquirerPollInterval: 2 * time.Second} } +func (l *Lock) released() error { + err := l.lockRecord.Released(l.locker.storage.Portal().Database()) + if err != nil { + l.locker.storage.Portal().Logger().Error("Failed to release lock", zap.Error(err)) + return err + } + + return nil +} func (l *Lock) Lock(ctx context.Context, requestUnlock func()) error { db := l.locker.storage.Portal().Database() @@ -67,13 +75,6 @@ func (l *Lock) Lock(ctx context.Context, requestUnlock func()) error { } } - defer func(lockRecord *models.TusLock, db *gorm.DB) { - err := lockRecord.Released(db) - if err != nil { - l.locker.storage.Portal().Logger().Error("Failed to release lock", zap.Error(err)) - } - }(&l.lockRecord, db) - go func() { for { select {