chg: [signaling] merge OS signaling and error handling routines

nifi
Jean-Louis Huynen 2020-03-17 11:22:34 +01:00
parent 31b491ba97
commit 7441d92eb5
No known key found for this signature in database
GPG Key ID: 64799157F4BD6B93
1 changed files with 17 additions and 18 deletions

35
main.go
View File

@ -58,15 +58,26 @@ var (
)
func main() {
// Create a chan to get the goroutines errors messages
pullreturn := make(chan error, 1)
// Create a chan to get os Signals
sortie := make(chan os.Signal, 1)
signal.Notify(sortie, os.Interrupt, os.Kill)
// Signal goroutine
// OS signaling and error handling goroutine
go func() {
<-sortie
fmt.Println("Exiting.")
compilegr.Wait()
log.Println("Exit")
os.Exit(0)
select {
case <-sortie:
fmt.Println("Exiting.")
compilegr.Wait()
log.Println("Exit")
os.Exit(0)
case err := <-pullreturn:
log.Println(err)
fmt.Println("Exiting.")
compilegr.Wait()
log.Println("Exit.")
os.Exit(1)
}
}()
// Setting up log file
@ -154,18 +165,6 @@ func main() {
redisCompilers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount)
redisInput = newPool(ri.redisHost+":"+ri.redisPort, 16)
// Create a chan to get the goroutines errors messages
pullreturn := make(chan error, 1)
// Launching Pull routines monitoring
go func() {
select {
case err := <-pullreturn:
log.Println(err)
os.Exit(1)
log.Println("Exit.")
}
}()
// Init compiler depending on the compiler flags:
if *all {
// Init all compilers