func (f *factoryImpl) NewTaskManager() (p.TaskManager, error) {
	ds := f.datastores[storeTypeTask]
	taskStore, err := ds.factory.NewTaskStore()
	if err != nil {
		return nil, err
	}
	result := p.NewTaskManager(taskStore)
	if ds.ratelimit != nil {
		result = p.NewTaskPersistenceRateLimitedClient(result, ds.ratelimit, f.logger)
	}
	if f.metricsClient != nil {
		result = p.NewTaskPersistenceMetricsClient(result, f.metricsClient, f.logger)
	}
	return result, nil
}
NewTaskManager returns a new task manager
package client
import (
	"sync"
	"go.temporal.io/server/common/config"
	"go.temporal.io/server/common/dynamicconfig"
	"go.temporal.io/server/common/log"
	"go.temporal.io/server/common/metrics"
	p "go.temporal.io/server/common/persistence"
	"go.temporal.io/server/common/persistence/cassandra"
	"go.temporal.io/server/common/persistence/sql"
	"go.temporal.io/server/common/quotas"
	"go.temporal.io/server/common/resolver"
)
type (
	Factory interface {
		Close()
		NewTaskManager() (p.TaskManager, error)
		NewShardManager() (p.ShardManager, error)
		NewMetadataManager() (p.MetadataManager, error)
		NewExecutionManager() (p.ExecutionManager, error)
		NewNamespaceReplicationQueue() (p.NamespaceReplicationQueue, error)
		NewClusterMetadataManager() (p.ClusterMetadataManager, error)
		FaultInjection() *FaultInjectionDataStoreFactory
	}
	DataStoreFactory interface {
		Close()
		NewTaskStore() (p.TaskStore, error)
		NewShardStore() (p.ShardStore, error)
		NewMetadataStore() (p.MetadataStore, error)
		NewExecutionStore() (p.ExecutionStore, error)
		NewQueue(queueType p.QueueType) (p.Queue, error)
		NewClusterMetadataStore() (p.ClusterMetadataStore, error)
	}
	AbstractDataStoreFactory interface {
		NewFactory(
			cfg config.CustomDatastoreConfig,
			r resolver.ServiceResolver,
			clusterName string,
			logger log.Logger,
			metricsClient metrics.Client,
		) DataStoreFactory
	}
	Datastore struct {
		factory   DataStoreFactory
		ratelimit quotas.RateLimiter
	}
	factoryImpl struct {
		sync.RWMutex
		config                   *config.Persistence
		abstractDataStoreFactory AbstractDataStoreFactory
		faultInjection           *FaultInjectionDataStoreFactory
		metricsClient            metrics.Client
		logger                   log.Logger
		datastores               map[storeType]Datastore
		clusterName              string
	}
	storeType int
)
const (
	storeTypeHistory storeType = iota + 1
	storeTypeTask
	storeTypeShard
	storeTypeMetadata
	storeTypeExecution
	storeTypeQueue
	storeTypeClusterMetadata
)
var storeTypes = []storeType{
	storeTypeHistory,
	storeTypeTask,
	storeTypeShard,
	storeTypeMetadata,
	storeTypeExecution,
	storeTypeQueue,
	storeTypeClusterMetadata,
}
func NewFactory(
	cfg *config.Persistence,
	r resolver.ServiceResolver,
	persistenceMaxQPS dynamicconfig.IntPropertyFn,
	abstractDataStoreFactory AbstractDataStoreFactory,
	clusterName string,
	metricsClient metrics.Client,
	logger log.Logger,
) Factory {
	return NewFactoryImpl(cfg, r, persistenceMaxQPS, abstractDataStoreFactory, clusterName, metricsClient, logger)
}
func NewFactoryImpl(
	cfg *config.Persistence,
	r resolver.ServiceResolver,
	persistenceMaxQPS dynamicconfig.IntPropertyFn,
	abstractDataStoreFactory AbstractDataStoreFactory,
	clusterName string,
	metricsClient metrics.Client,
	logger log.Logger,
) *factoryImpl {
	factory := &factoryImpl{
		config:                   cfg,
		abstractDataStoreFactory: abstractDataStoreFactory,
		metricsClient:            metricsClient,
		logger:                   logger,
		clusterName:              clusterName,
	}
	limiters := buildRateLimiters(cfg, persistenceMaxQPS)
	factory.init(clusterName, limiters, r)
	return factory
}