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) {
|
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()
|
startTimeRepo := time.Now().UnixNano()
|
||||||
jsonBytes, err = get(repo.server)
|
jsonBytes, err = get(repo.server)
|
||||||
repoRuntime = time.Now().UnixNano() - startTimeRepo
|
repoRuntime = time.Now().UnixNano() - startTimeRepo
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/foomo/contentserver/content"
|
"github.com/foomo/contentserver/content"
|
||||||
@ -25,6 +26,7 @@ type Dimension struct {
|
|||||||
type Repo struct {
|
type Repo struct {
|
||||||
server string
|
server string
|
||||||
Directory map[string]*Dimension
|
Directory map[string]*Dimension
|
||||||
|
updateLock *sync.Mutex
|
||||||
updateChannel chan *repoDimension
|
updateChannel chan *repoDimension
|
||||||
updateDoneChannel chan error
|
updateDoneChannel chan error
|
||||||
history *history
|
history *history
|
||||||
@ -43,6 +45,7 @@ func NewRepo(server string, varDir string) *Repo {
|
|||||||
server: server,
|
server: server,
|
||||||
Directory: map[string]*Dimension{},
|
Directory: map[string]*Dimension{},
|
||||||
history: newHistory(varDir),
|
history: newHistory(varDir),
|
||||||
|
updateLock: &sync.Mutex{},
|
||||||
updateChannel: make(chan *repoDimension),
|
updateChannel: make(chan *repoDimension),
|
||||||
updateDoneChannel: make(chan error),
|
updateDoneChannel: make(chan error),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user