Skip to content

Commit

Permalink
Fix wire creating publishers with invalid config
Browse files Browse the repository at this point in the history
  • Loading branch information
boreq committed Nov 16, 2023
1 parent b381434 commit 199cb43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 11 additions & 5 deletions cmd/event-service/di/inject_pubsub.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package di

import (
"github.com/ThreeDotsLabs/watermill"
"github.com/boreq/errors"
"github.com/google/wire"
"github.com/planetary-social/nos-event-service/service/adapters/gcp"
"github.com/planetary-social/nos-event-service/service/adapters/memorypubsub"
Expand Down Expand Up @@ -31,14 +33,18 @@ var sqliteTxPubsubSet = wire.NewSet(

var externalPubsubSet = wire.NewSet(
gcp.NewNoopPublisher,
gcp.NewPublisher,
gcp.NewWatermillPublisher,
selectExternalPublisher,
)

func selectExternalPublisher(conf config.Config, real *gcp.Publisher, noop *gcp.NoopPublisher) app.ExternalEventPublisher {
func selectExternalPublisher(conf config.Config, logger watermill.LoggerAdapter, noop *gcp.NoopPublisher) (app.ExternalEventPublisher, error) {
if conf.Environment() == config.EnvironmentDevelopment {
return noop
return noop, nil
}
return real

watermillPublisher, err := gcp.NewWatermillPublisher(conf, logger)
if err != nil {
return nil, errors.Wrap(err, "error creating watermill publisher")
}

return gcp.NewPublisher(watermillPublisher), nil
}
6 changes: 2 additions & 4 deletions cmd/event-service/di/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 199cb43

Please sign in to comment.