From a11de63eb613c4b6f3c3cd3fe352b0ca5dd89b37 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sat, 10 Feb 2024 23:37:35 +0100 Subject: [PATCH] added helper functions for programmatic use --- pkg/coordinator/scheduler/options.go | 22 ++++++++++------- pkg/coordinator/scheduler/services.go | 34 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 pkg/coordinator/scheduler/services.go diff --git a/pkg/coordinator/scheduler/options.go b/pkg/coordinator/scheduler/options.go index 4acdf74..46aa82f 100644 --- a/pkg/coordinator/scheduler/options.go +++ b/pkg/coordinator/scheduler/options.go @@ -27,9 +27,9 @@ type TaskOptsSettings struct { Timeout human.Duration `yaml:"timeout" json:"timeout"` } -func (ts *TaskScheduler) NewTaskOptions(task *types.TaskDescriptor, config interface{}, settings *TaskOptsSettings) (*types.TaskOptions, error) { +func (ts *TaskScheduler) NewTaskOptions(task string, config interface{}, settings *TaskOptsSettings) *types.TaskOptions { options := &types.TaskOptions{ - Name: task.Name, + Name: task, } if settings != nil { @@ -41,14 +41,18 @@ func (ts *TaskScheduler) NewTaskOptions(task *types.TaskDescriptor, config inter if config != nil { configYaml, err := yaml.Marshal(config) if err != nil { - return nil, fmt.Errorf("error serializing task config: %w", err) - } - - err = yaml.Unmarshal(configYaml, options.Config) - if err != nil { - return nil, fmt.Errorf("error parsing task config: %w", err) + ts.logger.Errorf("failed marshalling task options: %v", err) + } else { + configRaw := helper.RawMessage{} + + err = yaml.Unmarshal(configYaml, &configRaw) + if err != nil { + ts.logger.Errorf("failed unmarshalling task options: %v", err) + } else { + options.Config = &configRaw + } } } - return options, nil + return options } diff --git a/pkg/coordinator/scheduler/services.go b/pkg/coordinator/scheduler/services.go new file mode 100644 index 0000000..b9b83cd --- /dev/null +++ b/pkg/coordinator/scheduler/services.go @@ -0,0 +1,34 @@ +package scheduler + +import ( + "github.com/ethpandaops/assertoor/pkg/coordinator/clients" + "github.com/ethpandaops/assertoor/pkg/coordinator/names" + "github.com/ethpandaops/assertoor/pkg/coordinator/types" + "github.com/ethpandaops/assertoor/pkg/coordinator/wallet" +) + +type servicesProvider struct { + clientPool *clients.ClientPool + walletManager *wallet.Manager + validatorNames *names.ValidatorNames +} + +func NewServicesProvider(clientPool *clients.ClientPool, walletManager *wallet.Manager, validatorNames *names.ValidatorNames) types.TaskServices { + return &servicesProvider{ + clientPool: clientPool, + walletManager: walletManager, + validatorNames: validatorNames, + } +} + +func (p *servicesProvider) ClientPool() *clients.ClientPool { + return p.clientPool +} + +func (p *servicesProvider) WalletManager() *wallet.Manager { + return p.walletManager +} + +func (p *servicesProvider) ValidatorNames() *names.ValidatorNames { + return p.validatorNames +}