Skip to content

Commit c136333

Browse files
committed
core: Execution.skipped in core, middleware: fix overlap bahaviour
1 parent 6b741ae commit c136333

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

core/scheduler.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ func (w *jobWrapper) stop(ctx *Context, err error) {
110110
}
111111

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

117-
if ctx.Execution.Error != nil {
117+
if ctx.Execution.Failed {
118+
ctx.Logger.Error(msg)
119+
} else if ctx.Execution.Skipped {
118120
ctx.Logger.Warning(msg)
119121
} else {
120122
ctx.Logger.Notice(msg)

middlewares/overlap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (m *Overlap) ContinueOnStop() bool {
2525

2626
func (m *Overlap) Run(ctx *core.Context) error {
2727
if m.NoOverlap && ctx.Job.Running() > 1 {
28-
return core.ErrSkippedExecution
28+
ctx.Stop(core.ErrSkippedExecution)
2929
}
3030

3131
return ctx.Next()

middlewares/overlap_test.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package middlewares
22

3-
import (
4-
"github.com/mcuadros/ofelia/core"
5-
. "gopkg.in/check.v1"
6-
)
3+
import . "gopkg.in/check.v1"
74

85
type SuiteOverlap struct {
96
BaseSuite
@@ -21,16 +18,12 @@ func (s *SuiteOverlap) TestRun(c *C) {
2118
}
2219

2320
func (s *SuiteOverlap) TestRunOverlap(c *C) {
21+
s.ctx.Execution.Start()
2422
s.ctx.Job.NotifyStart()
2523
s.ctx.Job.NotifyStart()
2624

27-
m := NewOverlap(&OverlapConfig{NoOverlap: true})
28-
c.Assert(m.Run(s.ctx), Equals, core.ErrSkippedExecution)
29-
}
30-
31-
func (s *SuiteOverlap) TestRunAllowOverlap(c *C) {
32-
s.ctx.Job.NotifyStart()
33-
3425
m := NewOverlap(&OverlapConfig{NoOverlap: true})
3526
c.Assert(m.Run(s.ctx), IsNil)
27+
c.Assert(s.ctx.Execution.IsRunning, Equals, false)
28+
c.Assert(s.ctx.Execution.Skipped, Equals, true)
3629
}

middlewares/slack.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ var (
1616
)
1717

1818
type SlackConfig struct {
19-
URL string `gcfg:"slack-webhook"`
20-
OnError bool `gcfg:"slack-on-error"`
19+
URL string `gcfg:"slack-webhook"`
20+
OnlyOnError bool `gcfg:"slack-only-on-error"`
2121
}
2222

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

47-
if ctx.Execution.Failed || !m.OnError {
47+
if ctx.Execution.Failed || !m.OnlyOnError {
4848
m.pushMessage(ctx)
4949
}
5050

@@ -81,6 +81,11 @@ func (m *Slack) buildMessage(ctx *core.Context) *slackMessage {
8181
Text: ctx.Execution.Error.Error(),
8282
Color: "#F35A00",
8383
})
84+
} else if ctx.Execution.Skipped {
85+
msg.Attachments = append(msg.Attachments, slackAttachment{
86+
Title: "Execution skipped",
87+
Color: "#FFA500",
88+
})
8489
} else {
8590
msg.Attachments = append(msg.Attachments, slackAttachment{
8691
Title: "Execution successful",

middlewares/slack_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ func (s *SuiteSlack) TestRunSuccessOnError(c *C) {
6161
s.ctx.Start()
6262
s.ctx.Stop(nil)
6363

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

0 commit comments

Comments
 (0)