feat(service): implement graceful shutdown for HTTP server
Add a context with timeout to handle graceful shutdown of the HTTP server. Update error handling during the server's close to include context-aware shutdown. Ensure that the server properly logs only non-closed errors when listening.
This commit is contained in:
Vendored
+4
-4
@@ -2,9 +2,9 @@ package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/sparetimecoders/goamqp"
|
||||
|
||||
"gitlab.com/unboundsoftware/schemas/domain"
|
||||
@@ -18,7 +18,7 @@ type Cache struct {
|
||||
services map[string]map[string]map[string]struct{}
|
||||
subGraphs map[string]string
|
||||
lastUpdate map[string]string
|
||||
logger log.Interface
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
func (c *Cache) OrganizationByAPIKey(apiKey string) *domain.Organization {
|
||||
@@ -98,7 +98,7 @@ func (c *Cache) Update(msg any, _ goamqp.Headers) (any, error) {
|
||||
case *domain.SubGraph:
|
||||
c.updateSubGraph(m.OrganizationId, m.Ref, m.ID.String(), m.Service, m.ChangedAt)
|
||||
default:
|
||||
c.logger.Warnf("unexpected message received: %+v", msg)
|
||||
c.logger.With("msg", msg).Warn("unexpected message received")
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func (c *Cache) addUser(sub string, organization domain.Organization) {
|
||||
}
|
||||
}
|
||||
|
||||
func New(logger log.Interface) *Cache {
|
||||
func New(logger *slog.Logger) *Cache {
|
||||
return &Cache{
|
||||
organizations: make(map[string]domain.Organization),
|
||||
users: make(map[string][]string),
|
||||
|
||||
Reference in New Issue
Block a user