summaryrefslogtreecommitdiffstats
path: root/modules/eventsource/manager_run.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/eventsource/manager_run.go')
-rw-r--r--modules/eventsource/manager_run.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/eventsource/manager_run.go b/modules/eventsource/manager_run.go
index ccfe2e0709..60598ecb49 100644
--- a/modules/eventsource/manager_run.go
+++ b/modules/eventsource/manager_run.go
@@ -34,6 +34,35 @@ loop:
timer.Stop()
break loop
case <-timer.C:
+ m.mutex.Lock()
+ connectionCount := len(m.messengers)
+ if connectionCount == 0 {
+ log.Trace("Event source has no listeners")
+ // empty the connection channel
+ select {
+ case <-m.connection:
+ default:
+ }
+ }
+ m.mutex.Unlock()
+ if connectionCount == 0 {
+ // No listeners so the source can be paused
+ log.Trace("Pausing the eventsource")
+ select {
+ case <-ctx.Done():
+ break loop
+ case <-m.connection:
+ log.Trace("Connection detected - restarting the eventsource")
+ // OK we're back so lets reset the timer and start again
+ // We won't change the "then" time because there could be concurrency issues
+ select {
+ case <-timer.C:
+ default:
+ }
+ continue
+ }
+ }
+
now := timeutil.TimeStampNow().Add(-2)
uidCounts, err := models.GetUIDsAndNotificationCounts(then, now)