本文整理匯總了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)
}
}