Skip to content

Commit

Permalink
Merge pull request #801 from dotmesh-io/parse_empty_interval
Browse files Browse the repository at this point in the history
handle empty value set as require_zfs.sh sets it anyway
  • Loading branch information
rusenask authored Apr 28, 2020
2 parents d95d573 + e1723fa commit 676320e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/dotmesh-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func main() {

// Set the URL to an empty string (or leave it unset) to disable checkpoints
if serverConfig.Upgrades.URL != "" {
checkInterval := serverConfig.Upgrades.IntervalSeconds
checkInterval := serverConfig.Upgrades.IntervalSeconds.Value()
// This is the name that the checkpoint library looks for
os.Setenv("CHECKPOINT_URL", serverConfig.Upgrades.URL)

Expand Down
25 changes: 23 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type (
}

Upgrades struct {
URL string `envconfig:"DOTMESH_UPGRADES_URL"`
IntervalSeconds int `default:"300" envconfig:"DOTMESH_UPGRADES_INTERVAL_SECONDS"`
URL string `envconfig:"DOTMESH_UPGRADES_URL"`
IntervalSeconds DefaultInt `default:"300" envconfig:"DOTMESH_UPGRADES_INTERVAL_SECONDS"`
}
}
)
Expand Down Expand Up @@ -61,3 +61,24 @@ func (b *DefaultDuration) Decode(value string) error {
func (b *DefaultDuration) Duration() time.Duration {
return time.Duration(*b)
}

type DefaultInt int

func (b *DefaultInt) Value() int {
return int(*b)
}

func (b *DefaultInt) Decode(value string) error {
if value == "" {
*b = DefaultInt(0)
return nil
}

i, err := strconv.Atoi(value)
if err != nil {
return err
}

*b = DefaultInt(i)
return nil
}
13 changes: 13 additions & 0 deletions pkg/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ func TestLoadTime(t *testing.T) {
t.Errorf("expected 1s, got: %d", cfg.PollDirty.SuccessTimeout)
}
}

func TestLoadInterval(t *testing.T) {
os.Setenv("DOTMESH_UPGRADES_INTERVAL_SECONDS", "")

cfg, err := Load()
if err != nil {
t.Errorf("failed to load: %s", err)
}

if int(cfg.Upgrades.IntervalSeconds) != 0 {
t.Errorf("expected 0, got: %d", int(cfg.Upgrades.IntervalSeconds))
}
}

0 comments on commit 676320e

Please sign in to comment.