ignore service.ErrPersistenceNotExists error

This commit is contained in:
c9s 2022-05-05 14:04:44 +08:00
parent 57a9647401
commit 57c43936d6
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 13 additions and 1 deletions

View File

@ -136,6 +136,10 @@ func loadPersistenceFields(obj interface{}, id string, persistence service.Persi
// inf := value.Interface()
store := persistence.NewStore(id, tag)
if err := store.Load(&newValueInf); err != nil {
if err == service.ErrPersistenceNotExists {
return nil
}
return err
}

View File

@ -252,7 +252,10 @@ func (trader *Trader) RunSingleExchangeStrategy(ctx context.Context, strategy Si
// 1) scan the struct fields and find the persistence field
// 2) load the data and set the value into the persistence field.
_ = trader.environment.PersistenceServiceFacade
ps := trader.environment.PersistenceServiceFacade.Get()
if err := loadPersistenceFields(strategy, strategy.ID(), ps); err != nil {
return err
}
return strategy.Run(ctx, orderExecutor, session)
}
@ -319,6 +322,7 @@ func (trader *Trader) Run(ctx context.Context) error {
router.executors[sessionID] = orderExecutor
}
ps := trader.environment.PersistenceServiceFacade.Get()
for _, strategy := range trader.crossExchangeStrategies {
rs := reflect.ValueOf(strategy)
@ -332,6 +336,10 @@ func (trader *Trader) Run(ctx context.Context) error {
return err
}
if err := loadPersistenceFields(strategy, strategy.ID(), ps); err != nil {
return err
}
if err := strategy.CrossRun(ctx, router, trader.environment.sessions); err != nil {
return err
}