challenge-sync-airbus: Avoid concurrent map write
This commit is contained in:
parent
59cf98ead2
commit
c53140b88e
@ -7,6 +7,7 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
@ -18,6 +19,7 @@ var (
|
||||
|
||||
type Walker struct {
|
||||
LastSync map[string]*TSValue
|
||||
LastSyncLock sync.RWMutex
|
||||
Exercices AirbusExercicesBindings
|
||||
Teams map[string]fic.ExportedTeam
|
||||
RevTeams map[string]string
|
||||
@ -158,7 +160,9 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
|
||||
maxts := TSValue{
|
||||
Time: time.Time{},
|
||||
}
|
||||
w.LastSyncLock.RLock()
|
||||
ts, ok := w.LastSync[airbusTeam.Name]
|
||||
w.LastSyncLock.RUnlock()
|
||||
if ok {
|
||||
maxts = *ts
|
||||
} else {
|
||||
@ -198,7 +202,9 @@ func (w *Walker) TreatScoreGrid(path string, airbusTeam *AirbusTeam) error {
|
||||
maxts.Score = int64(math.Trunc(expected_score))
|
||||
}
|
||||
|
||||
w.LastSyncLock.Lock()
|
||||
w.LastSync[airbusTeam.Name] = &maxts
|
||||
w.LastSyncLock.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -221,12 +227,14 @@ func (w *Walker) BalanceScores() error {
|
||||
return fmt.Errorf("Unable to award team %s: %w", myteam.Name, err)
|
||||
}
|
||||
|
||||
w.LastSyncLock.Lock()
|
||||
if _, ok := w.LastSync[airbusTeam.Name]; !ok {
|
||||
w.LastSync[airbusTeam.Name] = &TSValue{}
|
||||
}
|
||||
|
||||
w.LastSync[airbusTeam.Name].Score = expected_score
|
||||
w.LastSync[airbusTeam.Name].Time = time.Now()
|
||||
w.LastSyncLock.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user