Skip to content

Commit

Permalink
fix: speed up pubsub provisioning (#3916)
Browse files Browse the repository at this point in the history
fixes: #3901
prerequisite: #3917

Wraps `docker compose up` with a lock and a cached success flag.
  • Loading branch information
matt2e authored Jan 7, 2025
1 parent 0fbebeb commit 37542a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (s *Service) deploy(ctx context.Context, key model.DeploymentKey, module *s
pubSub, err := pubsub.New(module, key, s, s.timelineClient)
if err != nil {
observability.Deployment.Failure(ctx, optional.Some(key.String()))
return fmt.Errorf("failed to create pubsub service: %w", err)
return fmt.Errorf("failed to set up pubsub: %w", err)
}
s.pubSub = pubSub

Expand Down
12 changes: 12 additions & 0 deletions internal/dev/redpanda.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "embed"
"fmt"
"os"
"sync"

"github.com/alecthomas/types/optional"

Expand All @@ -14,7 +15,17 @@ import (
//go:embed docker-compose.redpanda.yml
var redpandaDockerCompose string

// use this lock while checking redPandaRunning status and running `docker compose up` if needed
var redPandaLock = &sync.Mutex{}
var redPandaRunning bool

func SetUpRedPanda(ctx context.Context) error {
redPandaLock.Lock()
defer redPandaLock.Unlock()

if redPandaRunning {
return nil
}
var profile optional.Option[string]
if _, ci := os.LookupEnv("CI"); !ci {
// include console except in CI
Expand All @@ -24,5 +35,6 @@ func SetUpRedPanda(ctx context.Context) error {
if err != nil {
return fmt.Errorf("could not start redpanda: %w", err)
}
redPandaRunning = true
return nil
}

0 comments on commit 37542a5

Please sign in to comment.