Skip to content

Commit

Permalink
refactor: Moving starter to a common workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Mar 17, 2023
1 parent 9314110 commit 1af9588
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
13 changes: 13 additions & 0 deletions cmd/fibr/background.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
7 changes: 3 additions & 4 deletions cmd/fibr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
9 changes: 3 additions & 6 deletions cmd/fibr/fibr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 1af9588

Please sign in to comment.