Skip to content

Commit

Permalink
Fixes intelsdi-x#1113: removes fixed max-failure value from task crea…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Tom McSweeney committed Aug 2, 2016
1 parent 8f40854 commit 0c33039
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
8 changes: 2 additions & 6 deletions cmd/snapctl/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ package main

import "github.com/codegangsta/cli"

const (
DefaultMaxFailures = 10
)

var (

// Main flags
Expand Down Expand Up @@ -128,8 +124,8 @@ var (
}
flTaskMaxFailures = cli.IntFlag{
Name: "max-failures",
Usage: "The number of consecutive failures before snap disable the task (Default 10 consective failures)",
Value: DefaultMaxFailures,
Usage: "The number of consecutive failures before snap disable the task",
Value: -1,
}

// metric
Expand Down
6 changes: 3 additions & 3 deletions cmd/snapctl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ func createTaskUsingTaskManifest(ctx *cli.Context) error {
return fmt.Errorf("Invalid version provided")
}

// If the number of failures does not specific, default value is 10
// If the maximum number of failures is not specified, set it so that
// the default value will be used
if t.MaxFailures == 0 {
fmt.Println("If the number of maximum failures is not specified, use default value of", DefaultMaxFailures)
t.MaxFailures = DefaultMaxFailures
t.MaxFailures = -1
}

r := pClient.CreateTask(t.Schedule, t.Workflow, t.Name, t.Deadline, !ctx.IsSet("no-start"), t.MaxFailures)
Expand Down
7 changes: 6 additions & 1 deletion core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ func CreateTaskFromContent(body io.ReadCloser,
if tr.Name != "" {
opts = append(opts, SetTaskName(tr.Name))
}
opts = append(opts, OptionStopOnFailure(10))

// if a MaxFailures value is included as part of the task creation request
if tr.MaxFailures > 0 {
// then set the appropriate value in the opts
opts = append(opts, OptionStopOnFailure(tr.MaxFailures))
}

if mode == nil {
mode = &tr.Start
Expand Down
12 changes: 6 additions & 6 deletions mgmt/rest/client/client_func_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestSnapClient(t *testing.T) {
So(t1.Err.Error(), ShouldEqual, fmt.Sprintf("Task not found: ID(%s)", uuid))
})
Convey("invalid task (missing metric)", func() {
tt := c.CreateTask(sch, wf, "baron", "", true, rest.DefaultMaxFailures)
tt := c.CreateTask(sch, wf, "baron", "", true, -1)
So(tt.Err, ShouldNotBeNil)
So(tt.Err.Error(), ShouldContainSubstring, "Metric not found: /intel/mock/foo")
})
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestSnapClient(t *testing.T) {
So(p.AvailablePlugins, ShouldBeEmpty)
})
Convey("invalid task (missing publisher)", func() {
tf := c.CreateTask(sch, wf, "baron", "", false, rest.DefaultMaxFailures)
tf := c.CreateTask(sch, wf, "baron", "", false, -1)
So(tf.Err, ShouldNotBeNil)
So(tf.Err.Error(), ShouldContainSubstring, "Plugin not found: type(publisher) name(mock-file)")
})
Expand Down Expand Up @@ -338,11 +338,11 @@ func TestSnapClient(t *testing.T) {
Convey("Tasks", func() {
Convey("Passing a bad task manifest", func() {
wfb := getWMFromSample("bad.json")
ttb := c.CreateTask(sch, wfb, "bad", "", true, rest.DefaultMaxFailures)
ttb := c.CreateTask(sch, wfb, "bad", "", true, -1)
So(ttb.Err, ShouldNotBeNil)
})

tf := c.CreateTask(sch, wf, "baron", "", false, rest.DefaultMaxFailures)
tf := c.CreateTask(sch, wf, "baron", "", false, -1)
Convey("valid task not started on creation", func() {
So(tf.Err, ShouldBeNil)
So(tf.Name, ShouldEqual, "baron")
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestSnapClient(t *testing.T) {
})
})

tt := c.CreateTask(sch, wf, "baron", "", true, rest.DefaultMaxFailures)
tt := c.CreateTask(sch, wf, "baron", "", true, -1)
Convey("valid task started on creation", func() {
So(tt.Err, ShouldBeNil)
So(tt.Name, ShouldEqual, "baron")
Expand Down Expand Up @@ -473,7 +473,7 @@ func TestSnapClient(t *testing.T) {
Convey("event stream", func() {
rest.StreamingBufferWindow = 0.01
sch := &Schedule{Type: "simple", Interval: "100ms"}
tf := c.CreateTask(sch, wf, "baron", "", false, rest.DefaultMaxFailures)
tf := c.CreateTask(sch, wf, "baron", "", false, -1)

type ea struct {
events []string
Expand Down
4 changes: 0 additions & 4 deletions mgmt/rest/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import (
"github.com/codegangsta/cli"
)

const (
DefaultMaxFailures = 10
)

var (
flAPIDisabled = cli.BoolFlag{
Name: "disable-api, d",
Expand Down
4 changes: 2 additions & 2 deletions scheduler/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
const (
// DefaultDeadlineDuration - The default timeout is 5 second
DefaultDeadlineDuration = time.Second * 5
// DefaultStopOnFailure - The default stopping a failure is after three tries
DefaultStopOnFailure = 3
// DefaultStopOnFailure is used to set the number of failures before a task is disabled
DefaultStopOnFailure = 10
)

var (
Expand Down

0 comments on commit 0c33039

Please sign in to comment.