Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: go/src/infra/monitoring/looper/looper.go

Issue 1874053002: [alerts-dispatcher] update to build again :) also fixes a concurrent map access (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: fix typo Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: go/src/infra/monitoring/looper/looper.go
diff --git a/go/src/infra/monitoring/looper/looper.go b/go/src/infra/monitoring/looper/looper.go
index 9bbea5c94061a8a4c3385461da09b1b57b7b5893..2e3c3324961cf96bbb62c34c18ab706776812a68 100644
--- a/go/src/infra/monitoring/looper/looper.go
+++ b/go/src/infra/monitoring/looper/looper.go
@@ -69,7 +69,9 @@ func Run(ctx context.Context, f Runner, cycle time.Duration, maxErrs int, c cloc
}
nextCycle = cycle - dur
- tmr.Reset(nextCycle)
+ if tmr.Reset(nextCycle) {
+ log.Errorf("Timer was still active")
+ }
}
// Run f at least once.
@@ -77,12 +79,15 @@ func Run(ctx context.Context, f Runner, cycle time.Duration, maxErrs int, c cloc
// Keep running f until ctx is done.
for {
- if ar := <-tmr.GetC(); ar.Incomplete() {
- return ret
- }
- run()
- if !ret.Success {
+ select {
+ case <-ctx.Done():
+ tmr.Stop()
return ret
+ case <-tmr.GetC():
+ run()
+ if !ret.Success {
+ return ret
+ }
}
}
}

Powered by Google App Engine
This is Rietveld 408576698