challenge-sync-airbus: Do job

This commit is contained in:
nemunaire 2023-04-06 03:48:52 +02:00
commit 3344e05e0d
6 changed files with 256 additions and 65 deletions

View file

@ -18,11 +18,13 @@ import (
var (
TeamsDir string
skipInitialSync bool
dryRun bool
)
func main() {
flag.StringVar(&TeamsDir, "teams", "./TEAMS", "Base directory where save teams JSON files")
var debugINotify = flag.Bool("debuginotify", false, "Show skipped inotofy events")
flag.BoolVar(&dryRun, "dry-run", dryRun, "Don't perform any write action, just display")
flag.BoolVar(&skipInitialSync, "skipinitialsync", skipInitialSync, "Skip the initial synchronization")
flag.BoolVar(&noValidateChallenge, "no-validate-challenge", noValidateChallenge, "Consider challenge validation as a standard award (if each exercice hasn't been imported on their side)")
daemon := flag.Bool("watch", false, "Enable daemon mode by watching the directory")
@ -41,13 +43,27 @@ func main() {
if v, exists := os.LookupEnv("AIRBUS_TOKEN"); exists {
api.Token = v
}
if v, exists := os.LookupEnv("AIRBUS_SESSIONID"); exists {
var err error
api.SessionID, err = strconv.ParseInt(v, 10, 64)
if err != nil {
log.Fatal("AIRBUS_SESSIONID is invalid: ", err.Error())
}
} else if v, exists := os.LookupEnv("AIRBUS_SESSION_NAME"); exists {
sessions, err := api.GetSessions()
if err != nil {
log.Fatal("Unable to retrieve session: ", err)
}
for _, session := range sessions {
if session.Name == v {
api.SessionID = session.ID
break
}
}
}
if v, exists := os.LookupEnv("AIRBUS_SESSIONUUID"); exists {
api.SessionUUID = v
}
@ -62,12 +78,6 @@ func main() {
log.Fatal("Unable to open timestamp file: ", err.Error())
}
// Load exercices bindings
exbindings, err := ReadExercicesBindings(*exercicespath)
if err != nil {
log.Fatal("Unable to open exercices bindings file: ", err.Error())
}
// Load teams.json
teamsbindings, err := getTeams(filepath.Join(TeamsDir, "teams.json"))
if err != nil {
@ -75,18 +85,28 @@ func main() {
}
w := Walker{
LastSync: ts,
Exercices: exbindings,
Teams: teamsbindings,
API: api,
Coeff: *coeff,
LastSync: ts,
Teams: teamsbindings,
API: api,
Coeff: *coeff,
}
if err = w.fetchTeams(); err != nil {
log.Fatal("Unable to fetch Airbus teams: ", err.Error())
}
if !noValidateChallenge {
// Load exercices bindings
w.Exercices, err = ReadExercicesBindings(*exercicespath)
if err != nil {
log.Fatal("Unable to open exercices bindings file: ", err.Error())
}
}
if !skipInitialSync {
// Iterate over teams scores
err = filepath.WalkDir(TeamsDir, w.WalkScoreSync)
if err != nil {
log.Printf("Something goes wrong during walking")
log.Println("Something goes wrong during walking: ", err.Error())
}
// save current timestamp for teams
@ -131,6 +151,9 @@ func main() {
return
}
w.Teams = teamsbindings
if err = w.fetchTeams(); err != nil {
log.Fatal("Unable to fetch teams: ", err.Error())
}
// save current timestamp for teams
err = saveTS(*tspath, w.LastSync)
@ -160,6 +183,9 @@ func main() {
return
}
w.Teams = teamsbindings
if err = w.fetchTeams(); err != nil {
log.Fatal("Unable to fetch teams: ", err.Error())
}
// FIXME
@ -183,6 +209,9 @@ func main() {
return
}
w.Teams = teamsbindings
if err = w.fetchTeams(); err != nil {
log.Fatal("Unable to fetch teams: ", err.Error())
}
}
} else if ev.Op&fsnotify.Write == fsnotify.Write {
log.Println("FSNOTIFY WRITE SEEN. Prefer looking at them, as it appears files are not atomically moved.")