Skip to content

Commit

Permalink
added helper functions for programmatic use
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Feb 10, 2024
1 parent 9d15fc4 commit aeee3fd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
38 changes: 9 additions & 29 deletions pkg/coordinator/scheduler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/ethpandaops/assertoor/pkg/coordinator/helper"
"github.com/ethpandaops/assertoor/pkg/coordinator/human-duration"
"github.com/ethpandaops/assertoor/pkg/coordinator/types"
"gopkg.in/yaml.v3"
)
Expand All @@ -18,37 +17,18 @@ func (ts *TaskScheduler) ParseTaskOptions(rawtask *helper.RawMessage) (*types.Ta
return options, nil
}

type TaskOptsSettings struct {
// The title of the task - this is used to describe the task to the user.
Title string `yaml:"title" json:"title"`
// The configuration settings to consume from runtime variables.
ConfigVars map[string]string `yaml:"configVars" json:"configVars"`
// Timeout defines the max time waiting for the condition to be met.
Timeout human.Duration `yaml:"timeout" json:"timeout"`
}

func (ts *TaskScheduler) NewTaskOptions(task *types.TaskDescriptor, config interface{}, settings *TaskOptsSettings) (*types.TaskOptions, error) {
options := &types.TaskOptions{
Name: task.Name,
func GetRawConfig(config interface{}) *helper.RawMessage {
configYaml, err := yaml.Marshal(config)
if err != nil {
return nil
}

if settings != nil {
options.Title = settings.Title
options.ConfigVars = settings.ConfigVars
options.Timeout = settings.Timeout
}
configRaw := helper.RawMessage{}

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)
}
err = yaml.Unmarshal(configYaml, &configRaw)
if err != nil {
return nil
}

return options, nil
return &configRaw
}
34 changes: 34 additions & 0 deletions pkg/coordinator/scheduler/services.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit aeee3fd

Please sign in to comment.