mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
lock update requests
This commit is contained in:
parent
1449d6902c
commit
f7aea048d3
@ -130,6 +130,11 @@ func get(URL string) (data []byte, err error) {
|
||||
}
|
||||
|
||||
func (repo *Repo) update() (repoRuntime int64, jsonBytes []byte, err error) {
|
||||
|
||||
// limit ressources and allow only one update request at once
|
||||
repo.updateLock.Lock()
|
||||
defer repo.updateLock.Unlock()
|
||||
|
||||
startTimeRepo := time.Now().UnixNano()
|
||||
jsonBytes, err = get(repo.server)
|
||||
repoRuntime = time.Now().UnixNano() - startTimeRepo
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/foomo/contentserver/content"
|
||||
@ -25,6 +26,7 @@ type Dimension struct {
|
||||
type Repo struct {
|
||||
server string
|
||||
Directory map[string]*Dimension
|
||||
updateLock *sync.Mutex
|
||||
updateChannel chan *repoDimension
|
||||
updateDoneChannel chan error
|
||||
history *history
|
||||
@ -43,6 +45,7 @@ func NewRepo(server string, varDir string) *Repo {
|
||||
server: server,
|
||||
Directory: map[string]*Dimension{},
|
||||
history: newHistory(varDir),
|
||||
updateLock: &sync.Mutex{},
|
||||
updateChannel: make(chan *repoDimension),
|
||||
updateDoneChannel: make(chan error),
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user