From 920b0b3746206e929abbee039efcacfb832f2816 Mon Sep 17 00:00:00 2001 From: KeeganForelight Date: Fri, 16 Jun 2023 17:14:18 -0400 Subject: [PATCH] adding timing to server start/stop, reduced output --- .task/checksum/go-build | 2 +- cmd/server/main.go | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.task/checksum/go-build b/.task/checksum/go-build index fb78ec6..2244bd3 100644 --- a/.task/checksum/go-build +++ b/.task/checksum/go-build @@ -1 +1 @@ -e832d011a7759af5da2bf569d9d999ac +a38a750f4484175244aabc5aebd5ddf9 diff --git a/cmd/server/main.go b/cmd/server/main.go index 810c6dd..f5109db 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -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) } }