1
1
mirror of https://git.janouch.name/p/gitea-obs synced 2024-11-26 08:43:48 +01:00

Improve shutdown sequence

This commit is contained in:
Přemysl Janouch 2019-04-19 17:14:52 +02:00
parent 62de443d3b
commit f1867c1010
No known key found for this signature in database
GPG Key ID: A0420B94F92B9493

15
main.go

@ -191,12 +191,8 @@ func main() {
server := &http.Server{Addr: listenAddr}
// Run the producer
go func() {
if err := server.ListenAndServe(); err != nil &&
err != http.ErrServerClosed {
log.Fatalln(err)
}
}()
errs := make(chan error, 1)
go func() { errs <- server.ListenAndServe() }()
// Run the consumer
ctx, ctxCancel := context.WithCancel(context.Background())
@ -217,7 +213,12 @@ func main() {
// Wait for a termination signal
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
<-sigs
select {
case <-sigs:
case err := <-errs:
log.Println(err)
}
// Stop the producer gracefully
ctxSd, ctxSdCancel := context.WithTimeout(context.Background(), 5)