Created
May 8, 2017 07:23
-
-
Save xigang/22b3ce177b522185337dcde74483e66a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func RecordAlertHistory(q *Queue, ah *AlertHistory) { | |
q.PushQueue(ah) | |
c := make(chan int) | |
currentQueueLen := q.GetQueueLength() | |
beego.Debug("Get Queue Len AAA: ", currentQueueLen) | |
wg.Add(2) | |
go func() { | |
defer wg.Done() | |
c <- currentQueueLen | |
}() | |
// 每隔1分钟,或者队列中的数据达到1000条,将数据批量写入influxdb | |
go func() { | |
defer wg.Done() | |
ticker := time.NewTicker(DEFAULTINTERVAL) | |
defer ticker.Stop() | |
for { | |
select { | |
case t := <-ticker.C: | |
func() { | |
beego.Debug("ticker... ", t) | |
writeToInfluxDB(currentQueueLen, q) | |
}() | |
case length := <-c: | |
func() { | |
beego.Debug("Get Queue Len... ", length) | |
if length == MAX_LENGTH { | |
writeToInfluxDB(length, q) | |
} | |
}() | |
} | |
} | |
}() | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment