2022-07-23 17:30:25 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
func shutdownHTTP(ctx context.Context, wg *sync.WaitGroup, srv *http.Server) {
|
2022-07-25 10:55:25 +02:00
|
|
|
defer wg.Done()
|
|
|
|
|
2022-07-23 17:30:25 +02:00
|
|
|
hub := sentry.CurrentHub().Clone()
|
|
|
|
defer hub.Flush(10 * time.Second)
|
|
|
|
|
|
|
|
ctx2, cancel := context.WithTimeout(ctx, 10*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
if err := srv.Shutdown(ctx2); err != nil {
|
|
|
|
hub.CaptureException(err)
|
|
|
|
log.Printf("Error shutting down HTTP server: %v", err)
|
|
|
|
}
|
|
|
|
}
|