diff --git a/cmd/fibr/background.go b/cmd/fibr/background.go new file mode 100644 index 00000000..bee689b3 --- /dev/null +++ b/cmd/fibr/background.go @@ -0,0 +1,13 @@ +package main + +import "context" + +type Starter func(context.Context) + +type Starters []Starter + +func (s Starters) Do(ctx context.Context) { + for _, start := range s { + go start(ctx) + } +} diff --git a/cmd/fibr/config.go b/cmd/fibr/config.go index 0fd8a8d1..438d15d3 100644 --- a/cmd/fibr/config.go +++ b/cmd/fibr/config.go @@ -58,10 +58,9 @@ func newConfig() (configuration, error) { fs := flag.NewFlagSet("fibr", flag.ExitOnError) return configuration{ - appServer: server.Flags(fs, "", flags.NewOverride("ReadTimeout", time.Minute*2), flags.NewOverride("WriteTimeout", time.Minute*2)), - promServer: server.Flags(fs, "prometheus", flags.NewOverride("Port", uint(9090)), flags.NewOverride("IdleTimeout", 10*time.Second), flags.NewOverride("ShutdownTimeout", 5*time.Second)), - health: health.Flags(fs, ""), - + appServer: server.Flags(fs, "", flags.NewOverride("ReadTimeout", time.Minute*2), flags.NewOverride("WriteTimeout", time.Minute*2)), + promServer: server.Flags(fs, "prometheus", flags.NewOverride("Port", uint(9090)), flags.NewOverride("IdleTimeout", 10*time.Second), flags.NewOverride("ShutdownTimeout", 5*time.Second)), + health: health.Flags(fs, ""), alcotest: alcotest.Flags(fs, ""), logger: logger.Flags(fs, "logger"), tracer: tracer.Flags(fs, "tracer"), diff --git a/cmd/fibr/fibr.go b/cmd/fibr/fibr.go index 1dc4fbe4..defcdc30 100644 --- a/cmd/fibr/fibr.go +++ b/cmd/fibr/fibr.go @@ -120,14 +120,11 @@ func main() { fibrApp := fibr.New(&crudApp, rendererApp, shareApp, webhookApp, middlewareApp) handler := rendererApp.Handler(fibrApp.TemplateFunc) - doneCtx := client.health.Done(ctx) endCtx := client.health.End(ctx) - go amqpThumbnailApp.Start(doneCtx) - go amqpExifApp.Start(doneCtx) - go webhookApp.Start(endCtx) - go shareApp.Start(endCtx) - go sanitizerApp.Start(endCtx) + Starters{amqpThumbnailApp.Start, amqpExifApp.Start}.Do(client.health.Done(ctx)) + Starters{webhookApp.Start, shareApp.Start, sanitizerApp.Start}.Do(endCtx) + go eventBus.Start(endCtx, storageApp, []provider.Renamer{thumbnailApp.Rename, metadataApp.Rename}, shareApp.EventConsumer, thumbnailApp.EventConsumer, metadataApp.EventConsumer, webhookApp.EventConsumer) go promServer.Start(endCtx, "prometheus", client.prometheus.Handler())