refactor: moved anon func to private released method
This commit is contained in:
parent
5465cf7a63
commit
112fbb4c51
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue