forked from mcuadros/ofelia
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoverlap.go
38 lines (30 loc) · 917 Bytes
/
overlap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package middlewares
import "github.com/mcuadros/ofelia/core"
// OverlapConfig configuration for the Overlap middleware
type OverlapConfig struct {
NoOverlap bool `gcfg:"no-overlap" mapstructure:"no-overlap"`
}
// NewOverlap returns a Overlap middleware if the given configuration is not empty
func NewOverlap(c *OverlapConfig) core.Middleware {
var m core.Middleware
if !IsEmpty(c) {
m = &Overlap{*c}
}
return m
}
// Overlap when this middleware is enabled avoid to overlap executions from a
// specific job
type Overlap struct {
OverlapConfig
}
// ContinueOnStop Overlap is only called if the process is still running
func (m *Overlap) ContinueOnStop() bool {
return false
}
// Run stops the execution if the another execution is already running
func (m *Overlap) Run(ctx *core.Context) error {
if m.NoOverlap && ctx.Job.Running() > 1 {
ctx.Stop(core.ErrSkippedExecution)
}
return ctx.Next()
}