Skip to content

Commit 4b6e864

Browse files
committed
refactor: start shutdown in their own goroutines and start metrics server before controller
1 parent 935698a commit 4b6e864

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

cmd/kar-controllers/app/server.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ func Run(ctx context.Context, opt *options.ServerOption) error {
7272
return fmt.Errorf("failed to create a job controller")
7373
}
7474

75-
go jobctrl.Run(ctx.Done())
7675

76+
// Start the health and metrics servers
7777
err = startHealthAndMetricsServers(ctx, opt)
7878
if err != nil {
7979
return err
8080
}
8181

82-
<-ctx.Done()
82+
// Start the job controller
83+
go jobctrl.Run(ctx.Done())
84+
8385
return nil
8486
}
8587

@@ -107,11 +109,16 @@ func startHealthAndMetricsServers(ctx context.Context, opt *options.ServerOption
107109
g.Go(metricsServer.Start)
108110
g.Go(healthServer.Start)
109111

110-
go func() {
112+
g.Go(func() error {
111113
<-ctx.Done()
112-
metricsServer.Shutdown()
113-
healthServer.Shutdown()
114-
}()
114+
return metricsServer.Shutdown()
115+
})
115116

116-
return nil
117+
g.Go(func() error {
118+
<-ctx.Done()
119+
return healthServer.Shutdown()
120+
})
121+
122+
return g.Wait()
117123
}
124+

0 commit comments

Comments
 (0)