remote-challenge-sync-airbus: Handle interrupts
This commit is contained in:
parent
cc1b212cca
commit
d2d7b35623
@ -5,9 +5,11 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"gopkg.in/fsnotify.v1"
|
||||
)
|
||||
@ -102,10 +104,61 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Register SIGUSR1, SIGUSR2
|
||||
interrupt1 := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt1, syscall.SIGHUP)
|
||||
interrupt2 := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt2, syscall.SIGUSR1)
|
||||
interrupt3 := make(chan os.Signal, 1)
|
||||
signal.Notify(interrupt3, syscall.SIGUSR2)
|
||||
|
||||
c := time.NewTicker(5 * time.Second)
|
||||
|
||||
watchedNotify := fsnotify.Create
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-interrupt1:
|
||||
log.Println("SIGHUP received, reloading files...")
|
||||
teamsbindings, err := getTeams(filepath.Join(TeamsDir, "teams.json"))
|
||||
if err != nil {
|
||||
log.Println("Unable to open teams bindings file: ", err.Error())
|
||||
return
|
||||
}
|
||||
w.Teams = teamsbindings
|
||||
|
||||
// save current timestamp for teams
|
||||
err = saveTS(*tspath, w.LastSync)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save timestamp file: ", err.Error())
|
||||
}
|
||||
log.Println("SIGHUP treated.")
|
||||
case <-interrupt2:
|
||||
log.Println("SIGUSR1 received, resynching all teams")
|
||||
// Iterate over teams scores
|
||||
err = filepath.WalkDir(TeamsDir, w.WalkScore)
|
||||
if err != nil {
|
||||
log.Printf("Something goes wrong during walking")
|
||||
}
|
||||
|
||||
// save current timestamp for teams
|
||||
err = saveTS(*tspath, w.LastSync)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save timestamp file: ", err.Error())
|
||||
}
|
||||
log.Println("SIGUSR1 treated.")
|
||||
case <-interrupt3:
|
||||
log.Println("SIGUSR2 received, resynching all teams from teams.json")
|
||||
teamsbindings, err := getTeams(filepath.Join(TeamsDir, "teams.json"))
|
||||
if err != nil {
|
||||
log.Println("Unable to open teams bindings file: ", err.Error())
|
||||
return
|
||||
}
|
||||
w.Teams = teamsbindings
|
||||
|
||||
// FIXME
|
||||
|
||||
log.Println("SIGUSR2 treated.")
|
||||
case ev := <-watcher.Events:
|
||||
if d, err := os.Lstat(ev.Name); err == nil && ev.Op&fsnotify.Create == fsnotify.Create && d.Mode().IsDir() && d.Mode()&os.ModeSymlink == 0 && d.Name() != ".tmp" {
|
||||
// Register new subdirectory
|
||||
@ -134,9 +187,21 @@ func main() {
|
||||
}
|
||||
case err := <-watcher.Errors:
|
||||
log.Println("error:", err)
|
||||
case <-ticker.C:
|
||||
// save current timestamp for teams
|
||||
err = saveTS(*tspath, w.LastSync)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save timestamp file: ", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save current timestamp for teams
|
||||
err = saveTS(*tspath, w.LastSync)
|
||||
if err != nil {
|
||||
log.Fatal("Unable to save timestamp file: ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func watchsubdir(watcher *fsnotify.Watcher, pathname string) error {
|
||||
|
Loading…
Reference in New Issue
Block a user