add mutex fo safety working with files
This commit is contained in:
parent
6dd5085bf6
commit
f071cfaf24
@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
@ -27,6 +28,7 @@ type Amo struct {
|
|||||||
integrationSecret string
|
integrationSecret string
|
||||||
rateLimiter *limiter.RateLimiter
|
rateLimiter *limiter.RateLimiter
|
||||||
amoStorageURL string
|
amoStorageURL string
|
||||||
|
fileMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type AmoDeps struct {
|
type AmoDeps struct {
|
||||||
@ -579,6 +581,8 @@ func (a *Amo) downloadFile(urlFile string) (*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Amo) UploadFileToAmo(urlFile string, accessToken string) (*models.ValuesFile, error) {
|
func (a *Amo) UploadFileToAmo(urlFile string, accessToken string) (*models.ValuesFile, error) {
|
||||||
|
a.fileMutex.Lock()
|
||||||
|
defer a.fileMutex.Unlock()
|
||||||
localFile, err := a.downloadFile(urlFile)
|
localFile, err := a.downloadFile(urlFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user