Skip to content

Commit

Permalink
Make server fx init more extendable (#4419)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnr committed May 31, 2023
1 parent 8aab8ab commit 2a4aec0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
60 changes: 24 additions & 36 deletions temporal/fx.go
Expand Up @@ -129,12 +129,10 @@ type (
}
)

func NewServerFx(opts ...ServerOption) (*ServerFx, error) {
var s ServerFx
s.app = fx.New(
var (
TopLevelModule = fx.Options(
pprof.Module,
fx.Provide(NewServerFxImpl),
fx.Supply(opts),
fx.Provide(ServerOptionsProvider),
TraceExportModule,

Expand All @@ -148,7 +146,14 @@ func NewServerFx(opts ...ServerOption) (*ServerFx, error) {
fx.Provide(ApplyClusterMetadataConfigProvider),
fx.Invoke(ServerLifetimeHooks),
FxLogAdapter,
)
)

func NewServerFx(topLevelModule fx.Option, opts ...ServerOption) (*ServerFx, error) {
var s ServerFx
s.app = fx.New(
topLevelModule,
fx.Supply(opts),
fx.Populate(&s.startupSynchronizationMode),
fx.Populate(&s.logger),
)
Expand Down Expand Up @@ -346,6 +351,17 @@ type (
}
)

func NewService(app *fx.App, serviceName primitives.ServiceName, logger log.Logger, stopChan chan struct{}) ServicesGroupOut {
return ServicesGroupOut{
Services: &ServicesMetadata{
app: app,
serviceName: serviceName,
logger: logger,
stopChan: stopChan,
},
}
}

func HistoryServiceProvider(
params ServiceProviderParamsCommon,
) (ServicesGroupOut, error) {
Expand Down Expand Up @@ -393,14 +409,7 @@ func HistoryServiceProvider(
FxLogAdapter,
)

return ServicesGroupOut{
Services: &ServicesMetadata{
app: app,
serviceName: serviceName,
logger: params.Logger,
stopChan: stopChan,
},
}, app.Err()
return NewService(app, serviceName, params.Logger, stopChan), app.Err()
}

func MatchingServiceProvider(
Expand Down Expand Up @@ -447,14 +456,7 @@ func MatchingServiceProvider(
FxLogAdapter,
)

return ServicesGroupOut{
Services: &ServicesMetadata{
app: app,
serviceName: serviceName,
logger: params.Logger,
stopChan: stopChan,
},
}, app.Err()
return NewService(app, serviceName, params.Logger, stopChan), app.Err()
}

func FrontendServiceProvider(
Expand Down Expand Up @@ -531,14 +533,7 @@ func genericFrontendServiceProvider(
FxLogAdapter,
)

return ServicesGroupOut{
Services: &ServicesMetadata{
app: app,
serviceName: serviceName,
logger: params.Logger,
stopChan: stopChan,
},
}, app.Err()
return NewService(app, serviceName, params.Logger, stopChan), app.Err()
}

func WorkerServiceProvider(
Expand Down Expand Up @@ -585,14 +580,7 @@ func WorkerServiceProvider(
FxLogAdapter,
)

return ServicesGroupOut{
Services: &ServicesMetadata{
app: app,
serviceName: serviceName,
logger: params.Logger,
stopChan: stopChan,
},
}, app.Err()
return NewService(app, serviceName, params.Logger, stopChan), app.Err()
}

// ApplyClusterMetadataConfigProvider performs a config check against the configured persistence store for cluster metadata.
Expand Down
2 changes: 1 addition & 1 deletion temporal/server.go
Expand Up @@ -66,5 +66,5 @@ var (

// NewServer returns a new instance of server that serves one or many services.
func NewServer(opts ...ServerOption) (Server, error) {
return NewServerFx(opts...)
return NewServerFx(TopLevelModule, opts...)
}

0 comments on commit 2a4aec0

Please sign in to comment.