save on signal
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m49s

This commit is contained in:
matst80
2024-11-10 00:19:01 +01:00
parent bbc9b9476d
commit 53a8e0a58f

15
main.go
View File

@@ -5,6 +5,8 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"os/signal"
"syscall"
"time" "time"
messages "git.tornberg.me/go-cart-actor/proto" messages "git.tornberg.me/go-cart-actor/proto"
@@ -193,6 +195,17 @@ func main() {
mux.HandleFunc("GET /save", app.HandleSave) mux.HandleFunc("GET /save", app.HandleSave)
mux.Handle("/metrics", promhttp.Handler()) mux.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":8080", mux) sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGTERM)
done := make(chan bool, 1)
go func() {
sig := <-sigs
fmt.Println("Shutting down due to signal:", sig)
app.Save()
done <- true
}()
go http.ListenAndServe(":8080", mux)
<-done
} }