Skip to content

Commit

Permalink
Wire up cluster metadata in start fx DI (#2398)
Browse files Browse the repository at this point in the history
* Wire up cluster metadata in start fx DI
  • Loading branch information
yux0 committed Jan 21, 2022
1 parent 75bf59f commit 2dbf144
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
54 changes: 54 additions & 0 deletions common/cluster/fx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package cluster

import (
"context"

"go.uber.org/fx"
)

var MetadataLifetimeHooksModule = fx.Options(
fx.Provide(NewMetadataFromConfig),
fx.Invoke(MetadataLifetimeHooks),
)

func MetadataLifetimeHooks(
lc fx.Lifecycle,
clusterMetadata Metadata,
) {
lc.Append(
fx.Hook{
OnStart: func(context.Context) error {
clusterMetadata.Start()
return nil
},
OnStop: func(context.Context) error {
clusterMetadata.Stop()
return nil
},
},
)
}
5 changes: 4 additions & 1 deletion common/resource/fx.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ type (
MatchingClient matchingservice.MatchingServiceClient
)

// Module
// Use fx.Hook and OnStart/OnStop to manage Daemon resource lifecycle
// See LifetimeHooksModule for detail
var Module = fx.Options(
persistenceClient.Module,
fx.Provide(SnTaggedLoggerProvider),
Expand All @@ -82,7 +85,7 @@ var Module = fx.Options(
fx.Provide(HostNameProvider),
fx.Provide(ServiceNameProvider),
fx.Provide(TimeSourceProvider),
fx.Provide(cluster.NewMetadataFromConfig),
cluster.MetadataLifetimeHooksModule,
fx.Provide(MetricsClientProvider),
fx.Provide(SearchAttributeProviderProvider),
fx.Provide(SearchAttributeManagerProvider),
Expand Down

0 comments on commit 2dbf144

Please sign in to comment.