save on signal
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m49s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m49s
This commit is contained in:
15
main.go
15
main.go
@@ -5,6 +5,8 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
messages "git.tornberg.me/go-cart-actor/proto"
|
||||
@@ -193,6 +195,17 @@ func main() {
|
||||
mux.HandleFunc("GET /save", app.HandleSave)
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user