Commit b1db8d3e authored by Marek Grabowski's avatar Marek Grabowski

Merge pull request #21262 from gmarek/backoff

Fix log gatherer
parents 05666fe6 f0bc1b6c
...@@ -218,6 +218,15 @@ func (g *LogSizeGatherer) Run() { ...@@ -218,6 +218,15 @@ func (g *LogSizeGatherer) Run() {
} }
} }
func (g *LogSizeGatherer) pushWorkItem(workItem WorkItem) {
select {
case <-time.After(time.Duration(workItem.backoffMultiplier) * pollingPeriod):
g.workChannel <- workItem
case <-g.stopChannel:
return
}
}
// Work does a single unit of work: tries to take out a WorkItem from the queue, ssh-es into a given machine, // Work does a single unit of work: tries to take out a WorkItem from the queue, ssh-es into a given machine,
// gathers data, writes it to the shared <data> map, and creates a gorouting which reinserts work item into // gathers data, writes it to the shared <data> map, and creates a gorouting which reinserts work item into
// the queue with a <pollingPeriod> delay. Returns false if worker should exit. // the queue with a <pollingPeriod> delay. Returns false if worker should exit.
...@@ -239,7 +248,7 @@ func (g *LogSizeGatherer) Work() bool { ...@@ -239,7 +248,7 @@ func (g *LogSizeGatherer) Work() bool {
if workItem.backoffMultiplier < 128 { if workItem.backoffMultiplier < 128 {
workItem.backoffMultiplier *= 2 workItem.backoffMultiplier *= 2
} }
g.workChannel <- workItem go g.pushWorkItem(workItem)
return true return true
} }
workItem.backoffMultiplier = 1 workItem.backoffMultiplier = 1
...@@ -255,13 +264,6 @@ func (g *LogSizeGatherer) Work() bool { ...@@ -255,13 +264,6 @@ func (g *LogSizeGatherer) Work() bool {
} }
g.data.AddNewData(workItem.ip, path, now, size) g.data.AddNewData(workItem.ip, path, now, size)
} }
go func() { go g.pushWorkItem(workItem)
select {
case <-time.After(time.Duration(workItem.backoffMultiplier) * pollingPeriod):
g.workChannel <- workItem
case <-g.stopChannel:
return
}
}()
return true return true
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment