Skip to content

Commit

Permalink
add initPersistenceFactory into persistenceManagerFactory as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenxia committed Oct 29, 2024
1 parent 648d2d4 commit 994e269
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tools/cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewCliApp(cf ClientFactory, opts ...CLIAppOptions) *cli.App {
app.Usage = "A command-line tool for cadence users"
app.Version = version
app.Metadata = map[string]any{
depsKey: &deps{ClientFactory: cf, IOHandler: &defaultIOHandler{app: app}, PersistenceManagerFactory: &DefaultPersistenceManagerFactory{}},
depsKey: &deps{ClientFactory: cf, IOHandler: &defaultIOHandler{app: app}, PersistenceManagerFactory: &defaultPersistenceManagerFactory{}},
}
app.Flags = []cli.Flag{
&cli.StringFlag{
Expand Down
15 changes: 8 additions & 7 deletions tools/cli/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ type PersistenceManagerFactory interface {
initializeHistoryManager(c *cli.Context) (persistence.HistoryManager, error)
initializeShardManager(c *cli.Context) (persistence.ShardManager, error)
initializeDomainManager(c *cli.Context) (persistence.DomainManager, error)
initPersistenceFactory(c *cli.Context) (client.Factory, error)
}

type DefaultPersistenceManagerFactory struct{}
type defaultPersistenceManagerFactory struct{}

func (f *DefaultPersistenceManagerFactory) initializeExecutionStore(c *cli.Context, shardID int) (persistence.ExecutionManager, error) {
func (f *defaultPersistenceManagerFactory) initializeExecutionStore(c *cli.Context, shardID int) (persistence.ExecutionManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
Expand All @@ -173,7 +174,7 @@ func (f *DefaultPersistenceManagerFactory) initializeExecutionStore(c *cli.Conte
return executionManager, nil
}

func (f *DefaultPersistenceManagerFactory) initializeHistoryManager(c *cli.Context) (persistence.HistoryManager, error) {
func (f *defaultPersistenceManagerFactory) initializeHistoryManager(c *cli.Context) (persistence.HistoryManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
Expand All @@ -185,7 +186,7 @@ func (f *DefaultPersistenceManagerFactory) initializeHistoryManager(c *cli.Conte
return historyManager, nil
}

func (f *DefaultPersistenceManagerFactory) initializeShardManager(c *cli.Context) (persistence.ShardManager, error) {
func (f *defaultPersistenceManagerFactory) initializeShardManager(c *cli.Context) (persistence.ShardManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
Expand All @@ -197,7 +198,7 @@ func (f *DefaultPersistenceManagerFactory) initializeShardManager(c *cli.Context
return shardManager, nil
}

func (f *DefaultPersistenceManagerFactory) initializeDomainManager(c *cli.Context) (persistence.DomainManager, error) {
func (f *defaultPersistenceManagerFactory) initializeDomainManager(c *cli.Context) (persistence.DomainManager, error) {
factory, err := getPersistenceFactory(c)
if err != nil {
return nil, fmt.Errorf("Failed to get persistence factory: %w", err)
Expand All @@ -214,15 +215,15 @@ var persistenceFactory client.Factory
func getPersistenceFactory(c *cli.Context) (client.Factory, error) {
var err error
if persistenceFactory == nil {
persistenceFactory, err = initPersistenceFactory(c)
persistenceFactory, err = getDeps(c).initPersistenceFactory(c)
if err != nil {
return persistenceFactory, fmt.Errorf("%w", err)
}
}
return persistenceFactory, nil
}

func initPersistenceFactory(c *cli.Context) (client.Factory, error) {
func (f *defaultPersistenceManagerFactory) initPersistenceFactory(c *cli.Context) (client.Factory, error) {
cfg, err := getDeps(c).ServerConfig(c)

if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions tools/cli/database_mock.go

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

0 comments on commit 994e269

Please sign in to comment.