bbgo: make PersistenceServiceFacade private

This commit is contained in:
c9s 2022-10-03 18:46:02 +08:00
parent 8a50474ad1
commit 2b953ad2d1
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
3 changed files with 11 additions and 11 deletions

View File

@ -283,7 +283,7 @@ func (environ *Environment) ConfigurePersistence(conf *PersistenceConfig) error
} }
redisPersistence := service.NewRedisPersistenceService(conf.Redis) redisPersistence := service.NewRedisPersistenceService(conf.Redis)
PersistenceServiceFacade.Redis = redisPersistence persistenceServiceFacade.Redis = redisPersistence
} }
if conf.Json != nil { if conf.Json != nil {
@ -295,7 +295,7 @@ func (environ *Environment) ConfigurePersistence(conf *PersistenceConfig) error
} }
jsonPersistence := &service.JsonPersistenceService{Directory: conf.Json.Directory} jsonPersistence := &service.JsonPersistenceService{Directory: conf.Json.Directory}
PersistenceServiceFacade.Json = jsonPersistence persistenceServiceFacade.Json = jsonPersistence
} }
return nil return nil
@ -630,7 +630,7 @@ func (environ *Environment) ConfigureNotificationSystem(userConfig *Config) erro
userConfig.Notifications = &NotificationConfig{} userConfig.Notifications = &NotificationConfig{}
} }
var persistence = PersistenceServiceFacade.Get() var persistence = persistenceServiceFacade.Get()
err := environ.setupInteraction(persistence) err := environ.setupInteraction(persistence)
if err != nil { if err != nil {

View File

@ -14,7 +14,7 @@ var DefaultPersistenceServiceFacade = &service.PersistenceServiceFacade{
Memory: service.NewMemoryService(), Memory: service.NewMemoryService(),
} }
var PersistenceServiceFacade = DefaultPersistenceServiceFacade var persistenceServiceFacade = DefaultPersistenceServiceFacade
// Sync syncs the object properties into the persistence layer // Sync syncs the object properties into the persistence layer
func Sync(ctx context.Context, obj interface{}) { func Sync(ctx context.Context, obj interface{}) {
@ -24,7 +24,7 @@ func Sync(ctx context.Context, obj interface{}) {
return return
} }
ps := PersistenceServiceFacade.Get() ps := persistenceServiceFacade.Get()
err := storePersistenceFields(obj, id, ps) err := storePersistenceFields(obj, id, ps)
if err != nil { if err != nil {
log.WithError(err).Errorf("persistence sync failed") log.WithError(err).Errorf("persistence sync failed")

View File

@ -376,11 +376,11 @@ func (trader *Trader) LoadState() error {
return nil return nil
} }
if PersistenceServiceFacade == nil { if persistenceServiceFacade == nil {
return nil return nil
} }
ps := PersistenceServiceFacade.Get() ps := persistenceServiceFacade.Get()
log.Infof("loading strategies states...") log.Infof("loading strategies states...")
@ -413,11 +413,11 @@ func (trader *Trader) SaveState() error {
return nil return nil
} }
if PersistenceServiceFacade == nil { if persistenceServiceFacade == nil {
return nil return nil
} }
ps := PersistenceServiceFacade.Get() ps := persistenceServiceFacade.Get()
log.Infof("saving strategies states...") log.Infof("saving strategies states...")
return trader.IterateStrategies(func(strategy StrategyID) error { return trader.IterateStrategies(func(strategy StrategyID) error {
@ -446,7 +446,7 @@ func (trader *Trader) injectCommonServices(s interface{}) error {
return fmt.Errorf("field Persistence is not a struct element, %s given", field) return fmt.Errorf("field Persistence is not a struct element, %s given", field)
} }
if err := dynamic.InjectField(elem, "Facade", PersistenceServiceFacade, true); err != nil { if err := dynamic.InjectField(elem, "Facade", persistenceServiceFacade, true); err != nil {
return err return err
} }
@ -466,6 +466,6 @@ func (trader *Trader) injectCommonServices(s interface{}) error {
trader.environment.DatabaseService, trader.environment.DatabaseService,
trader.environment.AccountService, trader.environment.AccountService,
trader.environment, trader.environment,
PersistenceServiceFacade, // if the strategy use persistence facade separately persistenceServiceFacade, // if the strategy use persistence facade separately
) )
} }