Skip to content

Commit

Permalink
command/flag: add retry-wait to task
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Dec 27, 2021
1 parent 32b9416 commit 719f7ec
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pkg/command/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (w Wrapper) numRetries(p *int, def int) {
w.fs.IntVarP(p, "num-retries", "r", def, usage["num-retries"])
}

func (w Wrapper) retryWait(p *Duration) {
w.fs.Var(p, "retry-wait", usage["retry-wait"])
}

func (w Wrapper) MustMarkDeprecated(name, usageMessage string) {
if err := w.fs.MarkDeprecated(name, usageMessage); err != nil {
panic(err)
Expand Down
23 changes: 16 additions & 7 deletions pkg/command/flag/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package flag

import (
"time"

"github.com/scylladb/scylla-manager/pkg/managerclient"
"github.com/spf13/cobra"
)
Expand All @@ -18,19 +20,20 @@ type TaskBase struct {
interval Duration
startDate Time
numRetries int
retryWait Duration
}

func MakeTaskBase() TaskBase {
return TaskBase{}
return TaskBase{
retryWait: DurationWithDefault(10 * time.Minute),
}
}

func NewUpdateTaskBase() TaskBase {
return TaskBase{
Command: cobra.Command{
Args: cobra.MaximumNArgs(1),
},
update: true,
}
base := MakeTaskBase()
base.Command.Args = cobra.MaximumNArgs(1)
base.update = true
return base
}

func (cmd *TaskBase) Init() {
Expand All @@ -41,6 +44,7 @@ func (cmd *TaskBase) Init() {
w.interval(&cmd.interval)
w.startDate(&cmd.startDate)
w.numRetries(&cmd.numRetries, cmd.numRetries)
w.retryWait(&cmd.retryWait)
}

// Update allows differentiating instances created with NewUpdateTaskBase.
Expand All @@ -59,6 +63,7 @@ func (cmd *TaskBase) CreateTask(taskType string) *managerclient.Task {
Interval: cmd.interval.String(),
StartDate: cmd.startDate.DateTimePtr(),
NumRetries: int64(cmd.numRetries),
RetryWait: cmd.retryWait.String(),
},
Properties: make(map[string]interface{}),
}
Expand Down Expand Up @@ -91,5 +96,9 @@ func (cmd *TaskBase) UpdateTask(task *managerclient.Task) bool {
task.Schedule.NumRetries = int64(cmd.numRetries)
ok = true
}
if cmd.Flag("retry-wait").Changed {
task.Schedule.RetryWait = cmd.retryWait.String()
ok = true
}
return ok
}
4 changes: 4 additions & 0 deletions pkg/command/flag/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ start-date: |
num-retries: |
Number of times a task reruns following a failure.
retry-wait: |
Initial exponential backoff `duration` X[h|m|s].
With --retry-wait 10m task will wait 10 minutes, 20 minutes and 40 minutes after first, second and third consecutire failure.
7 changes: 7 additions & 0 deletions pkg/command/flag/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ type Duration struct {
v duration.Duration
}

// DurationWithDefault returns new Duration initialized to a given value.
func DurationWithDefault(d time.Duration) Duration {
return Duration{
v: duration.Duration(d),
}
}

var _ flag.Value = (*Duration)(nil)

func (d *Duration) String() string {
Expand Down
3 changes: 3 additions & 0 deletions swagger/gen/scylla-manager/models/schedule.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions swagger/scylla-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@
"num_retries": {
"type": "number",
"format": "int"
},
"retry_wait": {
"type": "string"
}
}
},
Expand Down

0 comments on commit 719f7ec

Please sign in to comment.