Skip to content

Commit

Permalink
Stop Heartbeat monitor jobs on cancelation (#20570) (#20587)
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.

(cherry picked from commit a6d98d6)
  • Loading branch information
jsoriano authored Aug 14, 2020
1 parent 8073162 commit 4d69683
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 @@ -281,6 +281,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Fixed scheduler shutdown issues which would in rare situations cause a panic due to semaphore misuse. {pull}16397[16397]
- 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 4d69683

Please sign in to comment.