Skip to content

Commit

Permalink
Stop Heartbeat monitor jobs on cancelation (elastic#20570)
Browse files Browse the repository at this point in the history
If a monitor is stopped, for example when using autodiscover, the
scheduled tasks should be stopped too. Scheduler was rescheduling tasks
forever once started, though these tasks were not being executed because
they are also aware of the context.

This change avoids the execution and rescheduling of tasks once its job
context is done.
  • Loading branch information
jsoriano authored Aug 13, 2020
1 parent dbd6e36 commit a6d98d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fixed excessive memory usage introduced in 7.5 due to over-allocating memory for HTTP checks. {pull}15639[15639]
- Fixed TCP TLS checks to properly validate hostnames, this broke in 7.x and only worked for IP SANs. {pull}17549[17549]
- Add support for new `service_name` option to all monitors. {pull}19932[19932].
- Stop rescheduling tasks of stopped monitors. {pull}20570[20570]

*Journalbeat*

Expand Down
6 changes: 6 additions & 0 deletions heartbeat/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ func (s *Scheduler) Add(sched Schedule, id string, entrypoint TaskFunc) (removeF
var taskFn timerqueue.TimerTaskFn

taskFn = func(_ time.Time) {
select {
case <-jobCtx.Done():
debugf("Job '%v' canceled", id)
return
default:
}
s.stats.activeJobs.Inc()
lastRanAt = s.runRecursiveJob(jobCtx, entrypoint)
s.stats.activeJobs.Dec()
Expand Down

0 comments on commit a6d98d6

Please sign in to comment.