Skip to content

Commit aeee3fd

Browse files
committed
added helper functions for programmatic use
1 parent 9d15fc4 commit aeee3fd

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

pkg/coordinator/scheduler/options.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/ethpandaops/assertoor/pkg/coordinator/helper"
7-
"github.com/ethpandaops/assertoor/pkg/coordinator/human-duration"
87
"github.com/ethpandaops/assertoor/pkg/coordinator/types"
98
"gopkg.in/yaml.v3"
109
)
@@ -18,37 +17,18 @@ func (ts *TaskScheduler) ParseTaskOptions(rawtask *helper.RawMessage) (*types.Ta
1817
return options, nil
1918
}
2019

21-
type TaskOptsSettings struct {
22-
// The title of the task - this is used to describe the task to the user.
23-
Title string `yaml:"title" json:"title"`
24-
// The configuration settings to consume from runtime variables.
25-
ConfigVars map[string]string `yaml:"configVars" json:"configVars"`
26-
// Timeout defines the max time waiting for the condition to be met.
27-
Timeout human.Duration `yaml:"timeout" json:"timeout"`
28-
}
29-
30-
func (ts *TaskScheduler) NewTaskOptions(task *types.TaskDescriptor, config interface{}, settings *TaskOptsSettings) (*types.TaskOptions, error) {
31-
options := &types.TaskOptions{
32-
Name: task.Name,
20+
func GetRawConfig(config interface{}) *helper.RawMessage {
21+
configYaml, err := yaml.Marshal(config)
22+
if err != nil {
23+
return nil
3324
}
3425

35-
if settings != nil {
36-
options.Title = settings.Title
37-
options.ConfigVars = settings.ConfigVars
38-
options.Timeout = settings.Timeout
39-
}
26+
configRaw := helper.RawMessage{}
4027

41-
if config != nil {
42-
configYaml, err := yaml.Marshal(config)
43-
if err != nil {
44-
return nil, fmt.Errorf("error serializing task config: %w", err)
45-
}
46-
47-
err = yaml.Unmarshal(configYaml, options.Config)
48-
if err != nil {
49-
return nil, fmt.Errorf("error parsing task config: %w", err)
50-
}
28+
err = yaml.Unmarshal(configYaml, &configRaw)
29+
if err != nil {
30+
return nil
5131
}
5232

53-
return options, nil
33+
return &configRaw
5434
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package scheduler
2+
3+
import (
4+
"github.com/ethpandaops/assertoor/pkg/coordinator/clients"
5+
"github.com/ethpandaops/assertoor/pkg/coordinator/names"
6+
"github.com/ethpandaops/assertoor/pkg/coordinator/types"
7+
"github.com/ethpandaops/assertoor/pkg/coordinator/wallet"
8+
)
9+
10+
type servicesProvider struct {
11+
clientPool *clients.ClientPool
12+
walletManager *wallet.Manager
13+
validatorNames *names.ValidatorNames
14+
}
15+
16+
func NewServicesProvider(clientPool *clients.ClientPool, walletManager *wallet.Manager, validatorNames *names.ValidatorNames) types.TaskServices {
17+
return &servicesProvider{
18+
clientPool: clientPool,
19+
walletManager: walletManager,
20+
validatorNames: validatorNames,
21+
}
22+
}
23+
24+
func (p *servicesProvider) ClientPool() *clients.ClientPool {
25+
return p.clientPool
26+
}
27+
28+
func (p *servicesProvider) WalletManager() *wallet.Manager {
29+
return p.walletManager
30+
}
31+
32+
func (p *servicesProvider) ValidatorNames() *names.ValidatorNames {
33+
return p.validatorNames
34+
}

0 commit comments

Comments
 (0)