Merge pull request #1075 from c9s/bhwu/add-persistence-to-env

FEATURE: add persistence service to environment
This commit is contained in:
gx578007 2023-03-02 23:00:20 +08:00 committed by GitHub
commit 8039068d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 19 deletions

View File

@ -19,7 +19,7 @@ func BootstrapEnvironmentLightweight(ctx context.Context, environ *Environment,
}
if userConfig.Persistence != nil {
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
if err := ConfigurePersistence(ctx, environ, userConfig.Persistence); err != nil {
return errors.Wrap(err, "persistence configure error")
}
}
@ -41,7 +41,7 @@ func BootstrapEnvironment(ctx context.Context, environ *Environment, userConfig
}
if userConfig.Persistence != nil {
if err := ConfigurePersistence(ctx, userConfig.Persistence); err != nil {
if err := ConfigurePersistence(ctx, environ, userConfig.Persistence); err != nil {
return errors.Wrap(err, "persistence configure error")
}
}

View File

@ -90,6 +90,7 @@ type Environment struct {
AccountService *service.AccountService
WithdrawService *service.WithdrawService
DepositService *service.DepositService
PersistentService *service.PersistenceServiceFacade
// startTime is the time of start point (which is used in the backtest)
startTime time.Time

View File

@ -102,7 +102,7 @@ func NewPersistenceServiceFacade(conf *PersistenceConfig) (*service.PersistenceS
return facade, nil
}
func ConfigurePersistence(ctx context.Context, conf *PersistenceConfig) error {
func ConfigurePersistence(ctx context.Context, environ *Environment, conf *PersistenceConfig) error {
facade, err := NewPersistenceServiceFacade(conf)
if err != nil {
return err
@ -112,5 +112,6 @@ func ConfigurePersistence(ctx context.Context, conf *PersistenceConfig) error {
isolation.persistenceServiceFacade = facade
persistenceServiceFacade = facade
environ.PersistentService = facade
return nil
}