adding timing to server start/stop, reduced output

main
KeeganForelight 1 year ago
parent 36ccdf1df0
commit 920b0b3746

@ -1 +1 @@
e832d011a7759af5da2bf569d9d999ac
a38a750f4484175244aabc5aebd5ddf9

@ -4,6 +4,7 @@ import (
"fmt"
"os/signal"
"syscall"
"time"
"FRMS/internal/pkg/config"
"FRMS/internal/pkg/logging"
@ -27,6 +28,9 @@ func LoadConfig(file, path, ext string) (*viper.Viper, error) {
func main() {
fmt.Printf("starting server... ")
start := time.Now()
gracefulShutdown := make(chan os.Signal, 1)
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)
@ -48,19 +52,23 @@ func main() {
c := NewCoordinator(conf, errCh)
go c.Start()
logging.Debug(logging.DStart, "CCO 01 Server %s started", conf.Get("name"))
logging.Debug(logging.DStart, "CCO 01 %s started", conf.Get("name"))
elapsed := time.Now().Sub(start)
fmt.Printf("done %v\n", elapsed.Round(time.Microsecond))
select {
case err := <-errCh: // blocking to wait for any errors and keep alive otherwise
case err := <-errCh:
panic(err)
case <-gracefulShutdown:
// Shutdown via INT
// storing config
fmt.Printf("\nStoring config to %s\n", conf.ConfigFileUsed())
fmt.Printf("\nstopping server... ")
start := time.Now()
if err := conf.WriteConfig(); err != nil {
panic(err)
}
fmt.Println("Stored config successfully. Exiting...")
logging.Debug(logging.DExit, "CON wrote %s", conf.ConfigFileUsed())
elapsed := time.Now().Sub(start)
fmt.Printf("done %v\n", elapsed.Round(time.Microsecond))
os.Exit(0)
}
}

Loading…
Cancel
Save