refactor: moved anon func to private released method

This commit is contained in:
Derrick Hammer 2024-01-20 11:04:43 -05:00
parent 5465cf7a63
commit 112fbb4c51
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 8 deletions

View File

@ -6,7 +6,6 @@ import (
"git.lumeweb.com/LumeWeb/portal/interfaces" "git.lumeweb.com/LumeWeb/portal/interfaces"
tusd "github.com/tus/tusd/v2/pkg/handler" tusd "github.com/tus/tusd/v2/pkg/handler"
"go.uber.org/zap" "go.uber.org/zap"
"gorm.io/gorm"
"os" "os"
"sync" "sync"
"time" "time"
@ -37,6 +36,15 @@ func NewMySQLLocker(storage interfaces.StorageService) *MySQLLocker {
return &MySQLLocker{storage: storage, HolderPollInterval: 5 * time.Second, AcquirerPollInterval: 2 * time.Second} 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 { func (l *Lock) Lock(ctx context.Context, requestUnlock func()) error {
db := l.locker.storage.Portal().Database() 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() { go func() {
for { for {
select { select {