Skip to content

Commit

Permalink
fix: make rabbitmq connection optional and disable for token generation
Browse files Browse the repository at this point in the history
  • Loading branch information
abelanger5 committed Jun 25, 2024
1 parent b6dcb4e commit 1a88a68
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
7 changes: 6 additions & 1 deletion cmd/hatchet-admin/cli/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"

"github.com/hatchet-dev/hatchet/pkg/config/loader"
"github.com/hatchet-dev/hatchet/pkg/config/server"
)

var (
Expand Down Expand Up @@ -60,7 +61,11 @@ func runCreateAPIToken() error {
// read in the local config
configLoader := loader.NewConfigLoader(configDirectory)

cleanup, serverConf, err := configLoader.LoadServerConfig()
cleanup, serverConf, err := configLoader.LoadServerConfig(func(scf *server.ServerConfigFile) {
// disable rabbitmq since it's not needed to create the api token
scf.MessageQueue.RabbitMQ.Enabled = false
})

if err != nil {
return err
}
Expand Down
24 changes: 19 additions & 5 deletions pkg/config/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hatchet-dev/hatchet/internal/integrations/email/postmark"
"github.com/hatchet-dev/hatchet/internal/integrations/vcs"
"github.com/hatchet-dev/hatchet/internal/integrations/vcs/github"
"github.com/hatchet-dev/hatchet/internal/msgqueue"
"github.com/hatchet-dev/hatchet/internal/msgqueue/rabbitmq"
"github.com/hatchet-dev/hatchet/internal/services/ingestor"
"github.com/hatchet-dev/hatchet/pkg/analytics"
Expand Down Expand Up @@ -97,8 +98,10 @@ func (c *ConfigLoader) LoadDatabaseConfig() (res *database.Config, err error) {
return GetDatabaseConfigFromConfigFile(cf, &scf.Runtime)
}

type ServerConfigFileOverride func(*server.ServerConfigFile)

// LoadServerConfig loads the server configuration
func (c *ConfigLoader) LoadServerConfig() (cleanup func() error, res *server.ServerConfig, err error) {
func (c *ConfigLoader) LoadServerConfig(overrides ...ServerConfigFileOverride) (cleanup func() error, res *server.ServerConfig, err error) {
log.Printf("Loading server config from %s", c.directory)
sharedFilePath := filepath.Join(c.directory, "server.yaml")
log.Printf("Shared file path: %s", sharedFilePath)
Expand All @@ -118,6 +121,10 @@ func (c *ConfigLoader) LoadServerConfig() (cleanup func() error, res *server.Ser
return nil, nil, err
}

for _, override := range overrides {
override(cf)
}

return GetServerConfigFromConfigfile(dc, cf)
}

Expand Down Expand Up @@ -206,10 +213,17 @@ func GetServerConfigFromConfigfile(dc *database.Config, cf *server.ServerConfigF
return nil, nil, fmt.Errorf("could not create session store: %w", err)
}

cleanup1, mq := rabbitmq.New(
rabbitmq.WithURL(cf.MessageQueue.RabbitMQ.URL),
rabbitmq.WithLogger(&l),
)
var mq msgqueue.MessageQueue
cleanup1 := func() error {
return nil
}

if cf.MessageQueue.RabbitMQ.Enabled {
cleanup1, mq = rabbitmq.New(
rabbitmq.WithURL(cf.MessageQueue.RabbitMQ.URL),
rabbitmq.WithLogger(&l),
)
}

ingestor, err := ingestor.NewIngestor(
ingestor.WithEventRepository(dc.EngineRepository.Event()),
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ type MessageQueueConfigFile struct {
}

type RabbitMQConfigFile struct {
Enabled bool `mapstructure:"enabled" json:"enabled,omitempty" default:"true"`

URL string `mapstructure:"url" json:"url,omitempty" validate:"required" default:"amqp://user:password@localhost:5672/"`
}

Expand Down

0 comments on commit 1a88a68

Please sign in to comment.