Files
ocis/services/postprocessing/pkg/command/server.go
T

106 lines
2.7 KiB
Go
Raw Normal View History

2022-12-08 11:00:42 +01:00
package command
import (
2023-05-02 16:59:13 +02:00
"context"
2022-12-08 11:00:42 +01:00
"fmt"
"os"
2022-12-19 10:18:05 +01:00
"github.com/cs3org/reva/v2/pkg/events/stream"
2023-05-11 13:05:49 +02:00
"github.com/cs3org/reva/v2/pkg/store"
2023-05-02 16:59:13 +02:00
"github.com/oklog/run"
"github.com/urfave/cli/v2"
microstore "go-micro.dev/v4/store"
"github.com/owncloud/ocis/v2/ocis-pkg/tracing"
2022-12-08 11:00:42 +01:00
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/config/parser"
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/logging"
2024-10-10 11:57:59 +02:00
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/server/debug"
2022-12-08 11:00:42 +01:00
"github.com/owncloud/ocis/v2/services/postprocessing/pkg/service"
)
// Server is the entrypoint for the server command.
func Server(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "server",
Usage: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name),
Category: "server",
Before: func(c *cli.Context) error {
err := parser.ParseConfig(cfg)
if err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
return err
},
Action: func(c *cli.Context) error {
2023-05-02 16:59:13 +02:00
var (
2024-07-24 13:37:39 +02:00
gr = run.Group{}
logger = logging.Configure(cfg.Service.Name, cfg.Log)
ctx, cancel = context.WithCancel(c.Context)
2023-05-02 16:59:13 +02:00
)
defer cancel()
traceProvider, err := tracing.GetServiceTraceProvider(cfg.Tracing, cfg.Service.Name)
if err != nil {
return err
}
2023-05-02 16:59:13 +02:00
{
2023-12-18 11:47:25 +01:00
bus, err := stream.NatsFromConfig(cfg.Service.Name, false, stream.NatsConfig(cfg.Postprocessing.Events))
2023-05-02 16:59:13 +02:00
if err != nil {
return err
2022-12-08 11:00:42 +01:00
}
2023-05-11 13:05:49 +02:00
st := store.Create(
store.Store(cfg.Store.Store),
store.TTL(cfg.Store.TTL),
store.Size(cfg.Store.Size),
microstore.Nodes(cfg.Store.Nodes...),
microstore.Database(cfg.Store.Database),
microstore.Table(cfg.Store.Table),
2023-12-18 14:58:20 +01:00
store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword),
2023-05-11 13:05:49 +02:00
)
svc, err := service.NewPostprocessingService(ctx, bus, logger, st, traceProvider, cfg.Postprocessing)
2023-05-02 16:59:13 +02:00
if err != nil {
return err
}
gr.Add(func() error {
err := make(chan error)
select {
case <-ctx.Done():
return nil
case err <- svc.Run():
return <-err
}
}, func(err error) {
logger.Error().
Err(err).
2024-04-26 17:03:49 +02:00
Str("server", "http").
2023-05-02 16:59:13 +02:00
Msg("Shutting down server")
cancel()
})
2022-12-08 11:00:42 +01:00
}
2023-05-02 16:59:13 +02:00
{
2024-10-10 11:57:59 +02:00
debugServer, err := debug.Server(
2023-05-02 16:59:13 +02:00
debug.Logger(logger),
2024-10-10 11:57:59 +02:00
debug.Context(ctx),
debug.Config(cfg),
2023-05-02 16:59:13 +02:00
)
2024-10-10 11:57:59 +02:00
if err != nil {
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
return err
}
2023-05-02 16:59:13 +02:00
2024-10-10 11:57:59 +02:00
gr.Add(debugServer.ListenAndServe, func(_ error) {
_ = debugServer.Shutdown(ctx)
2023-05-02 16:59:13 +02:00
cancel()
})
2022-12-08 11:00:42 +01:00
}
2023-05-02 16:59:13 +02:00
return gr.Run()
2022-12-08 11:00:42 +01:00
},
}
}