Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 7bd619d

Browse files
kaufersDavid Chung
authored andcommitted
Change time.Duration to types.Duration for run/v0 Option parsing (#689)
Signed-off-by: Steven Kaufer <[email protected]>
1 parent 13a0ed1 commit 7bd619d

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

pkg/run/v0/group/group.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ type Options struct {
4343
MaxParallelNum uint
4444

4545
// PollIntervalGroupSpec polls for group spec at this interval to update the metadata paths
46-
PollIntervalGroupSpec time.Duration
46+
PollIntervalGroupSpec types.Duration
4747

4848
// PollIntervalGroupDetail polls for group details at this interval to update the metadata paths
49-
PollIntervalGroupDetail time.Duration
49+
PollIntervalGroupDetail types.Duration
5050
}
5151

5252
// DefaultOptions return an Options with default values filled in.
5353
var DefaultOptions = Options{
5454
PollInterval: types.FromDuration(10 * time.Second),
5555
MaxParallelNum: 0,
56-
PollIntervalGroupSpec: 1 * time.Second,
57-
PollIntervalGroupDetail: 30 * time.Second,
56+
PollIntervalGroupSpec: types.FromDuration(1 * time.Second),
57+
PollIntervalGroupDetail: types.FromDuration(30 * time.Second),
5858
}
5959

6060
// Run runs the plugin, blocking the current thread. Error is returned immediately
@@ -93,8 +93,8 @@ func Run(plugins func() discovery.Plugins, name plugin.Name,
9393
updateSnapshot := make(chan func(map[string]interface{}))
9494
stopSnapshot := make(chan struct{})
9595
go func() {
96-
tick := time.Tick(options.PollIntervalGroupSpec)
97-
tick2 := time.Tick(options.PollIntervalGroupDetail)
96+
tick := time.Tick(options.PollIntervalGroupSpec.Duration())
97+
tick2 := time.Tick(options.PollIntervalGroupDetail.Duration())
9898
for {
9999
select {
100100
case <-tick:

pkg/run/v0/manager/etcd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// BackendEtcdOptions contain the options for the etcd backend
1515
type BackendEtcdOptions struct {
1616
// PollInterval is how often to check
17-
PollInterval time.Duration
17+
PollInterval types.Duration
1818

1919
etcd.Options `json:",inline" yaml:",inline"`
2020

@@ -25,7 +25,7 @@ type BackendEtcdOptions struct {
2525
// DefaultBackendEtcdOptions contains the defaults for running etcd as backend
2626
var DefaultBackendEtcdOptions = types.AnyValueMust(
2727
BackendEtcdOptions{
28-
PollInterval: 5 * time.Second,
28+
PollInterval: types.FromDuration(5 * time.Second),
2929
Options: etcd.Options{
3030
RequestTimeout: 1 * time.Second,
3131
Config: clientv3.Config{
@@ -50,7 +50,7 @@ func configEtcdBackends(options BackendEtcdOptions, managerConfig *Options) erro
5050
return err
5151
}
5252

53-
leader := etcd_leader.NewDetector(options.PollInterval, etcdClient)
53+
leader := etcd_leader.NewDetector(options.PollInterval.Duration(), etcdClient)
5454
leaderStore := etcd_leader.NewStore(etcdClient)
5555
snapshot, err := etcd_store.NewSnapshot(etcdClient)
5656
if err != nil {

pkg/run/v0/manager/file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
// BackendFileOptions contain the options for the file backend
2525
type BackendFileOptions struct {
2626
// PollInterval is how often to check
27-
PollInterval time.Duration
27+
PollInterval types.Duration
2828

2929
// LeaderFile is the location of the leader file
3030
LeaderFile string
@@ -40,15 +40,15 @@ type BackendFileOptions struct {
4040
var DefaultBackendFileOptions = types.AnyValueMust(
4141
BackendFileOptions{
4242
ID: local.Getenv(EnvID, "manager1"),
43-
PollInterval: 5 * time.Second,
43+
PollInterval: types.FromDuration(5 * time.Second),
4444
LeaderFile: local.Getenv(EnvLeaderFile, filepath.Join(local.InfrakitHome(), "leader")),
4545
StoreDir: local.Getenv(EnvStoreDir, filepath.Join(local.InfrakitHome(), "configs")),
4646
},
4747
)
4848

4949
func configFileBackends(options BackendFileOptions, managerConfig *Options) error {
5050

51-
leader, err := file_leader.NewDetector(options.PollInterval, options.LeaderFile, options.ID)
51+
leader, err := file_leader.NewDetector(options.PollInterval.Duration(), options.LeaderFile, options.ID)
5252
if err != nil {
5353
return err
5454
}

pkg/run/v0/manager/swarm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414
// BackendSwarmOptions contain the options for the swarm backend
1515
type BackendSwarmOptions struct {
1616
// PollInterval is how often to check
17-
PollInterval time.Duration
17+
PollInterval types.Duration
1818
// Docker holds the connection params to the Docker engine for join tokens, etc.
1919
Docker docker.ConnectInfo `json:",inline" yaml:",inline"`
2020
}
2121

2222
// DefaultBackendSwarmOptions is the Options for using the swarm backend.
2323
var DefaultBackendSwarmOptions = types.AnyValueMust(
2424
BackendSwarmOptions{
25-
PollInterval: 5 * time.Second,
25+
PollInterval: types.FromDuration(5 * time.Second),
2626
Docker: docker.ConnectInfo{
2727
Host: "unix:///var/run/docker.sock",
2828
TLS: &tlsconfig.Options{},
@@ -43,7 +43,7 @@ func configSwarmBackends(options BackendSwarmOptions, managerConfig *Options) er
4343
return err
4444
}
4545

46-
leader := swarm_leader.NewDetector(options.PollInterval, dockerClient)
46+
leader := swarm_leader.NewDetector(options.PollInterval.Duration(), dockerClient)
4747
leaderStore := swarm_leader.NewStore(dockerClient)
4848

4949
if managerConfig != nil {

0 commit comments

Comments
 (0)