Skip to content

Commit

Permalink
core: Execution.skipped in core, middleware: fix overlap bahaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Oct 7, 2015
1 parent 6b741ae commit c136333
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 5 additions & 3 deletions core/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ func (w *jobWrapper) stop(ctx *Context, err error) {
}

msg := fmt.Sprintf(
"%s - Job finished %q in %q, failed: %t, error: %s",
ctx.Job.GetName(), ctx.Execution.ID, ctx.Execution.Duration, ctx.Execution.Failed, errText,
"%s - Job finished %q in %q, failed: %t, skipped: %t, error: %s",
ctx.Job.GetName(), ctx.Execution.ID, ctx.Execution.Duration, ctx.Execution.Failed, ctx.Execution.Skipped, errText,
)

if ctx.Execution.Error != nil {
if ctx.Execution.Failed {
ctx.Logger.Error(msg)
} else if ctx.Execution.Skipped {
ctx.Logger.Warning(msg)
} else {
ctx.Logger.Notice(msg)
Expand Down
2 changes: 1 addition & 1 deletion middlewares/overlap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (m *Overlap) ContinueOnStop() bool {

func (m *Overlap) Run(ctx *core.Context) error {
if m.NoOverlap && ctx.Job.Running() > 1 {
return core.ErrSkippedExecution
ctx.Stop(core.ErrSkippedExecution)
}

return ctx.Next()
Expand Down
15 changes: 4 additions & 11 deletions middlewares/overlap_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package middlewares

import (
"github.com/mcuadros/ofelia/core"
. "gopkg.in/check.v1"
)
import . "gopkg.in/check.v1"

type SuiteOverlap struct {
BaseSuite
Expand All @@ -21,16 +18,12 @@ func (s *SuiteOverlap) TestRun(c *C) {
}

func (s *SuiteOverlap) TestRunOverlap(c *C) {
s.ctx.Execution.Start()
s.ctx.Job.NotifyStart()
s.ctx.Job.NotifyStart()

m := NewOverlap(&OverlapConfig{NoOverlap: true})
c.Assert(m.Run(s.ctx), Equals, core.ErrSkippedExecution)
}

func (s *SuiteOverlap) TestRunAllowOverlap(c *C) {
s.ctx.Job.NotifyStart()

m := NewOverlap(&OverlapConfig{NoOverlap: true})
c.Assert(m.Run(s.ctx), IsNil)
c.Assert(s.ctx.Execution.IsRunning, Equals, false)
c.Assert(s.ctx.Execution.Skipped, Equals, true)
}
11 changes: 8 additions & 3 deletions middlewares/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var (
)

type SlackConfig struct {
URL string `gcfg:"slack-webhook"`
OnError bool `gcfg:"slack-on-error"`
URL string `gcfg:"slack-webhook"`
OnlyOnError bool `gcfg:"slack-only-on-error"`
}

func NewSlack(c *SlackConfig) core.Middleware {
Expand All @@ -44,7 +44,7 @@ func (m *Slack) Run(ctx *core.Context) error {
err := ctx.Next()
ctx.Stop(err)

if ctx.Execution.Failed || !m.OnError {
if ctx.Execution.Failed || !m.OnlyOnError {
m.pushMessage(ctx)
}

Expand Down Expand Up @@ -81,6 +81,11 @@ func (m *Slack) buildMessage(ctx *core.Context) *slackMessage {
Text: ctx.Execution.Error.Error(),
Color: "#F35A00",
})
} else if ctx.Execution.Skipped {
msg.Attachments = append(msg.Attachments, slackAttachment{
Title: "Execution skipped",
Color: "#FFA500",
})
} else {
msg.Attachments = append(msg.Attachments, slackAttachment{
Title: "Execution successful",
Expand Down
2 changes: 1 addition & 1 deletion middlewares/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ func (s *SuiteSlack) TestRunSuccessOnError(c *C) {
s.ctx.Start()
s.ctx.Stop(nil)

m := NewSlack(&SlackConfig{URL: ts.URL, OnError: true})
m := NewSlack(&SlackConfig{URL: ts.URL, OnlyOnError: true})
c.Assert(m.Run(s.ctx), IsNil)
}

0 comments on commit c136333

Please sign in to comment.