Skip to content

Commit

Permalink
refactor(apimanager): restart in a non-blocking way
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Aug 19, 2024
1 parent c633212 commit 35d1ed5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apimanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ func (s *server) Shutdown(ctx context.Context) error {
// Restart restarts the server by shutting it down and starting it again.
// If any routes or groups are provided, they will be added to the server.
// All existing routes and groups will be preserved.
// Runs indefinitely until an error occurs, the server shuts down, or the provided context is done.
//
// Note: The method returns immediately and the server restarts asynchronously.
func (s *server) Restart(ctx context.Context, routes []Route, groups []RouteGroup) error {
s.mu.Lock()
if !s.running {
Expand Down Expand Up @@ -358,7 +359,12 @@ func (s *server) Restart(ctx context.Context, routes []Route, groups []RouteGrou
return err
}

return s.Run(ctx)
go func() {
if err := s.Run(ctx); err != nil {
logger.FromContext(ctx).ErrorContext(ctx, "Failed to run server after restart", "error", err)
}
}()
return nil
}

// App returns the fiber app of the server.
Expand Down

0 comments on commit 35d1ed5

Please sign in to comment.