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" "fmt"
"os/signal" "os/signal"
"syscall" "syscall"
"time"
"FRMS/internal/pkg/config" "FRMS/internal/pkg/config"
"FRMS/internal/pkg/logging" "FRMS/internal/pkg/logging"
@ -27,6 +28,9 @@ func LoadConfig(file, path, ext string) (*viper.Viper, error) {
func main() { func main() {
fmt.Printf("starting server... ")
start := time.Now()
gracefulShutdown := make(chan os.Signal, 1) gracefulShutdown := make(chan os.Signal, 1)
signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM) signal.Notify(gracefulShutdown, syscall.SIGINT, syscall.SIGTERM)
@ -48,19 +52,23 @@ func main() {
c := NewCoordinator(conf, errCh) c := NewCoordinator(conf, errCh)
go c.Start() 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 { select {
case err := <-errCh: // blocking to wait for any errors and keep alive otherwise case err := <-errCh:
panic(err) panic(err)
case <-gracefulShutdown: case <-gracefulShutdown:
// Shutdown via INT fmt.Printf("\nstopping server... ")
// storing config start := time.Now()
fmt.Printf("\nStoring config to %s\n", conf.ConfigFileUsed())
if err := conf.WriteConfig(); err != nil { if err := conf.WriteConfig(); err != nil {
panic(err) 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) os.Exit(0)
} }
} }

Loading…
Cancel
Save