mirror of https://github.com/harness/drone.git
Make buffer for the cleanup reaper configurable (#3308)
parent
fdf51e70b2
commit
8668d901d8
|
@ -103,6 +103,7 @@ type (
|
||||||
Interval time.Duration `envconfig:"DRONE_CLEANUP_INTERVAL" default:"24h"`
|
Interval time.Duration `envconfig:"DRONE_CLEANUP_INTERVAL" default:"24h"`
|
||||||
Running time.Duration `envconfig:"DRONE_CLEANUP_DEADLINE_RUNNING" default:"24h"`
|
Running time.Duration `envconfig:"DRONE_CLEANUP_DEADLINE_RUNNING" default:"24h"`
|
||||||
Pending time.Duration `envconfig:"DRONE_CLEANUP_DEADLINE_PENDING" default:"24h"`
|
Pending time.Duration `envconfig:"DRONE_CLEANUP_DEADLINE_PENDING" default:"24h"`
|
||||||
|
Buffer time.Duration `envconfig:"DRONE_CLEANUP_BUFFER" default:"30m"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cron provides the cron configuration.
|
// Cron provides the cron configuration.
|
||||||
|
|
|
@ -181,6 +181,7 @@ func provideReaper(
|
||||||
canceler,
|
canceler,
|
||||||
config.Cleanup.Running,
|
config.Cleanup.Running,
|
||||||
config.Cleanup.Pending,
|
config.Cleanup.Pending,
|
||||||
|
config.Cleanup.Buffer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +213,7 @@ func provideDatadog(
|
||||||
EnableStash: config.IsStash(),
|
EnableStash: config.IsStash(),
|
||||||
EnableGogs: config.IsGogs(),
|
EnableGogs: config.IsGogs(),
|
||||||
EnableGitea: config.IsGitea(),
|
EnableGitea: config.IsGitea(),
|
||||||
EnableGitee: config.IsGitee(),
|
EnableGitee: config.IsGitee(),
|
||||||
EnableAgents: !config.Agent.Disabled,
|
EnableAgents: !config.Agent.Disabled,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,6 +34,10 @@ type Reaper struct {
|
||||||
Canceler core.Canceler
|
Canceler core.Canceler
|
||||||
Pending time.Duration // Pending is the pending pipeline deadline
|
Pending time.Duration // Pending is the pending pipeline deadline
|
||||||
Running time.Duration // Running is the running pipeline deadline
|
Running time.Duration // Running is the running pipeline deadline
|
||||||
|
|
||||||
|
// Buffer is applied when calculating whether or not the timeout
|
||||||
|
// period is exceeded. The added buffer helps prevent false positives.
|
||||||
|
Buffer time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Reaper.
|
// New returns a new Reaper.
|
||||||
|
@ -44,6 +48,7 @@ func New(
|
||||||
canceler core.Canceler,
|
canceler core.Canceler,
|
||||||
running time.Duration,
|
running time.Duration,
|
||||||
pending time.Duration,
|
pending time.Duration,
|
||||||
|
buffer time.Duration,
|
||||||
) *Reaper {
|
) *Reaper {
|
||||||
if running == 0 {
|
if running == 0 {
|
||||||
running = time.Hour * 24
|
running = time.Hour * 24
|
||||||
|
@ -51,6 +56,10 @@ func New(
|
||||||
if pending == 0 {
|
if pending == 0 {
|
||||||
pending = time.Hour * 24
|
pending = time.Hour * 24
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if buffer == 0 {
|
||||||
|
buffer = time.Minute * 30
|
||||||
|
}
|
||||||
return &Reaper{
|
return &Reaper{
|
||||||
Repos: repos,
|
Repos: repos,
|
||||||
Builds: builds,
|
Builds: builds,
|
||||||
|
@ -58,6 +67,7 @@ func New(
|
||||||
Canceler: canceler,
|
Canceler: canceler,
|
||||||
Pending: pending,
|
Pending: pending,
|
||||||
Running: running,
|
Running: running,
|
||||||
|
Buffer: buffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +115,7 @@ func (r *Reaper) reap(ctx context.Context) error {
|
||||||
|
|
||||||
// if a build is pending for longer than the maximum
|
// if a build is pending for longer than the maximum
|
||||||
// pending time limit, the build is maybe cancelled.
|
// pending time limit, the build is maybe cancelled.
|
||||||
if isExceeded(build.Created, r.Pending, buffer) {
|
if isExceeded(build.Created, r.Pending, r.Buffer) {
|
||||||
logger.Traceln("reaper: cancel build: time limit exceeded")
|
logger.Traceln("reaper: cancel build: time limit exceeded")
|
||||||
err = r.reapMaybe(ctx, build)
|
err = r.reapMaybe(ctx, build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -134,7 +144,7 @@ func (r *Reaper) reap(ctx context.Context) error {
|
||||||
|
|
||||||
// if a build is running for longer than the maximum
|
// if a build is running for longer than the maximum
|
||||||
// running time limit, the build is maybe cancelled.
|
// running time limit, the build is maybe cancelled.
|
||||||
if isExceeded(build.Started, r.Running, buffer) {
|
if isExceeded(build.Started, r.Running, r.Buffer) {
|
||||||
logger.Traceln("reaper: cancel build: time limit exceeded")
|
logger.Traceln("reaper: cancel build: time limit exceeded")
|
||||||
|
|
||||||
err = r.reapMaybe(ctx, build)
|
err = r.reapMaybe(ctx, build)
|
||||||
|
@ -188,7 +198,7 @@ func (r *Reaper) reapMaybe(ctx context.Context, build *core.Build) error {
|
||||||
|
|
||||||
// if the build stage has exceeded the timeout by a reasonable
|
// if the build stage has exceeded the timeout by a reasonable
|
||||||
// margin cancel the build and all build stages, else ignore.
|
// margin cancel the build and all build stages, else ignore.
|
||||||
if isExceeded(started, time.Duration(repo.Timeout)*time.Minute, buffer) {
|
if isExceeded(started, time.Duration(repo.Timeout)*time.Minute, r.Buffer) {
|
||||||
// TODO trace log entry
|
// TODO trace log entry
|
||||||
return r.Canceler.Cancel(ctx, repo, build)
|
return r.Canceler.Cancel(ctx, repo, build)
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ func TestReapPending(t *testing.T) {
|
||||||
canceler,
|
canceler,
|
||||||
time.Hour*24,
|
time.Hour*24,
|
||||||
time.Hour*24,
|
time.Hour*24,
|
||||||
|
time.Minute*30,
|
||||||
)
|
)
|
||||||
|
|
||||||
r.reap(nocontext)
|
r.reap(nocontext)
|
||||||
|
@ -139,6 +140,7 @@ func TestReapRunning(t *testing.T) {
|
||||||
canceler,
|
canceler,
|
||||||
time.Hour*24,
|
time.Hour*24,
|
||||||
time.Hour*24,
|
time.Hour*24,
|
||||||
|
time.Minute*30,
|
||||||
)
|
)
|
||||||
|
|
||||||
r.reap(nocontext)
|
r.reap(nocontext)
|
||||||
|
|
|
@ -16,10 +16,6 @@ package reaper
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// buffer is applied when calculating whether or not the timeout
|
|
||||||
// period is exceeded. The added buffer helps prevent false positives.
|
|
||||||
var buffer = time.Minute * 30
|
|
||||||
|
|
||||||
// helper function returns the current time.
|
// helper function returns the current time.
|
||||||
var now = time.Now
|
var now = time.Now
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue