feat: use runners to startup the services

This commit is contained in:
Juan Pablo Villafáñez
2025-09-12 12:18:47 +02:00
committed by Jörn Friedrich Dreyer
parent 61796a2b0b
commit 9e1b80a1be
33 changed files with 997 additions and 830 deletions
+21 -30
View File
@@ -3,9 +3,10 @@ package command
import (
"context"
"fmt"
"os/signal"
"github.com/oklog/run"
"github.com/opencloud-eu/opencloud/pkg/config/configlog"
"github.com/opencloud-eu/opencloud/pkg/runner"
"github.com/opencloud-eu/opencloud/pkg/tracing"
"github.com/opencloud-eu/opencloud/pkg/version"
"github.com/opencloud-eu/opencloud/services/webfinger/pkg/config"
@@ -35,16 +36,17 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(c.Context)
m = metrics.New(metrics.Logger(logger))
)
defer cancel()
var cancel context.CancelFunc
ctx := cfg.Context
if ctx == nil {
ctx, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
defer cancel()
}
m := metrics.New(metrics.Logger(logger))
m.BuildInfo.WithLabelValues(version.GetString()).Set(1)
gr := runner.NewGroup()
{
relationProviders, err := getRelationProviders(cfg)
if err != nil {
@@ -82,23 +84,7 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
gr.Add(func() error {
return server.Run()
}, func(err error) {
if err == nil {
logger.Info().
Str("transport", "http").
Str("server", cfg.Service.Name).
Msg("Shutting down server")
} else {
logger.Error().Err(err).
Str("transport", "http").
Str("server", cfg.Service.Name).
Msg("Shutting down server")
}
cancel()
})
gr.Add(runner.NewGoMicroHttpServerRunner("webfinger_http", server))
}
{
@@ -113,13 +99,18 @@ func Server(cfg *config.Config) *cli.Command {
return err
}
gr.Add(debugServer.ListenAndServe, func(err error) {
_ = debugServer.Shutdown(ctx)
cancel()
})
gr.Add(runner.NewGolangHttpServerRunner("webfinger_debug", debugServer))
}
return gr.Run()
grResults := gr.Run(ctx)
// return the first non-nil error found in the results
for _, grResult := range grResults {
if grResult.RunnerError != nil {
return grResult.RunnerError
}
}
return nil
},
}
}