本文整理汇总了Golang中github.com/daohoangson/go-socialcounters/utils.Utils.HistorySave方法的典型用法代码示例。如果您正苦于以下问题:Golang Utils.HistorySave方法的具体用法?Golang Utils.HistorySave怎么用?Golang Utils.HistorySave使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/daohoangson/go-socialcounters/utils.Utils
的用法示例。
在下文中一共展示了Utils.HistorySave方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: executeRequests
func executeRequests(u utils.Utils, requests *MapServiceRequest, data *MapUrlServiceCount) {
utils.Verbosef(u, "services.executeRequests(%s)", requests)
if len(*requests) < 1 {
return
}
var wg sync.WaitGroup
var cacheWg sync.WaitGroup
cacheCh := make(chan cache, 1)
caches := make(sliceCache, 0)
var historyWg sync.WaitGroup
historyTime := time.Now()
historyCh := make(chan utils.HistoryRecord, 1)
histories := make([]utils.HistoryRecord, 0)
wg.Add(len(*requests))
for _, req := range *requests {
go func(req request) {
defer wg.Done()
req.Worker(u, &req)
if req.Error != nil {
u.Errorf("services.%s: %v", req.Service, req.Error)
}
for url, res := range req.Results {
oldCount, _ := (*data)[url][req.Service]
(*data)[url][req.Service] = res.Count
if res.Error != nil {
u.Errorf("services.%s: %s error %v response %s", req.Service, url, res.Error, res.Response)
} else {
if res.Count > COUNT_INITIAL_VALUE && res.Count > oldCount {
cacheWg.Add(1)
cacheCh <- cache{Service: req.Service, Url: url, Count: res.Count}
historyWg.Add(1)
historyCh <- utils.HistoryRecord{Service: req.Service, Url: url, Count: res.Count, Time: historyTime}
}
}
}
}(req)
}
go func() {
for cache := range cacheCh {
caches = append(caches, cache)
cacheWg.Done()
}
}()
go func() {
for history := range historyCh {
histories = append(histories, history)
historyWg.Done()
}
}()
wg.Wait()
cacheWg.Wait()
historyWg.Wait()
setCaches(u, &caches)
if err := u.HistorySave(&histories); err != nil {
u.Errorf("u.HistorySave error %v", err)
}
}