mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
bbgo: call global persistence facade to sync data
This commit is contained in:
parent
612df45c5e
commit
7c9ad535fd
|
@ -26,24 +26,22 @@ var PersistenceServiceFacade = DefaultPersistenceServiceFacade
|
|||
// Persistence is used for strategy to inject the persistence.
|
||||
type Persistence struct {
|
||||
PersistenceSelector *PersistenceSelector `json:"persistence,omitempty" yaml:"persistence,omitempty"`
|
||||
|
||||
Facade *service.PersistenceServiceFacade `json:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
func (p *Persistence) backendService(t string) (service.PersistenceService, error) {
|
||||
switch t {
|
||||
case "json":
|
||||
return p.Facade.Json, nil
|
||||
return PersistenceServiceFacade.Json, nil
|
||||
|
||||
case "redis":
|
||||
if p.Facade.Redis == nil {
|
||||
if PersistenceServiceFacade.Redis == nil {
|
||||
log.Warn("redis persistence is not available, fallback to memory backend")
|
||||
return p.Facade.Memory, nil
|
||||
return PersistenceServiceFacade.Memory, nil
|
||||
}
|
||||
return p.Facade.Redis, nil
|
||||
return PersistenceServiceFacade.Redis, nil
|
||||
|
||||
case "memory":
|
||||
return p.Facade.Memory, nil
|
||||
return PersistenceServiceFacade.Memory, nil
|
||||
|
||||
}
|
||||
|
||||
|
@ -88,7 +86,18 @@ func (p *Persistence) Sync(obj interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
ps := p.Facade.Get()
|
||||
ps := PersistenceServiceFacade.Get()
|
||||
return storePersistenceFields(obj, id, ps)
|
||||
}
|
||||
|
||||
// Sync syncs the object properties into the persistence layer
|
||||
func Sync(obj interface{}) error {
|
||||
id := callID(obj)
|
||||
if len(id) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
ps := PersistenceServiceFacade.Get()
|
||||
return storePersistenceFields(obj, id, ps)
|
||||
}
|
||||
|
||||
|
|
|
@ -389,7 +389,6 @@ var defaultPersistenceSelector = &PersistenceSelector{
|
|||
func (trader *Trader) injectCommonServices(s interface{}) error {
|
||||
persistence := &Persistence{
|
||||
PersistenceSelector: defaultPersistenceSelector,
|
||||
Facade: PersistenceServiceFacade,
|
||||
}
|
||||
|
||||
// a special injection for persistence selector:
|
||||
|
|
Loading…
Reference in New Issue
Block a user