|
@@ -1,36 +1,54 @@
|
|
|
package services
|
|
|
|
|
|
import (
|
|
|
- "context"
|
|
|
"fmt"
|
|
|
- "hongze/mysteel_watch/global"
|
|
|
- "strings"
|
|
|
+ "hongze/mysteel_watch/cache"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// the service for log
|
|
|
-func AutoRefresh() {
|
|
|
- sub := global.Redis.Subscribe(context.TODO(), "autoRefresh")
|
|
|
+//func AutoRefresh() {
|
|
|
+// sub := global.Redis.Subscribe(context.TODO(), "autoRefresh")
|
|
|
+//
|
|
|
+// defer func() {
|
|
|
+// sub.Close()
|
|
|
+// if err := recover(); err != nil {
|
|
|
+// fmt.Println("[AutoRefresh]", err)
|
|
|
+// }
|
|
|
+// }()
|
|
|
+// for {
|
|
|
+// msg, err := sub.ReceiveMessage(context.TODO())
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("sub err:" + err.Error())
|
|
|
+// }
|
|
|
+// fmt.Println("sub:", msg.Payload)
|
|
|
+// IndexHandle(msg.Payload)
|
|
|
+//
|
|
|
+// //global.Rc.Brpop(utils.REFRESH_INDEX, func(b []byte) {
|
|
|
+// // filePath := string(b)
|
|
|
+// // fmt.Println("filePath:", filePath)
|
|
|
+// // IndexHandle(filePath)
|
|
|
+// //})
|
|
|
+// }
|
|
|
+//}
|
|
|
|
|
|
- defer func() {
|
|
|
- sub.Close()
|
|
|
- if err := recover(); err != nil {
|
|
|
- fmt.Println("[AutoRefresh]", err)
|
|
|
- }
|
|
|
- }()
|
|
|
+// AutoRefresh 调用python刷新指标
|
|
|
+func AutoRefresh() {
|
|
|
for {
|
|
|
- msg, err := sub.ReceiveMessage(context.TODO())
|
|
|
- if err != nil {
|
|
|
- fmt.Println("sub err:" + err.Error())
|
|
|
+ el := cache.RefreshList.Front()
|
|
|
+ // 如果没取到,那么就睡眠1s
|
|
|
+ if el == nil {
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
+ continue
|
|
|
}
|
|
|
- fmt.Println("sub:", msg.Payload)
|
|
|
- IndexHandle(msg.Payload)
|
|
|
+ filePath := el.Value.(string)
|
|
|
+ IndexHandle(filePath)
|
|
|
+ // 处理完后就移除该list
|
|
|
+ cache.RefreshList.Remove(el)
|
|
|
|
|
|
- //global.Rc.Brpop(utils.REFRESH_INDEX, func(b []byte) {
|
|
|
- // filePath := string(b)
|
|
|
- // fmt.Println("filePath:", filePath)
|
|
|
- // IndexHandle(filePath)
|
|
|
- //})
|
|
|
+ cache.FilePathMutex.Lock()
|
|
|
+ delete(cache.FilePathMap, filePath)
|
|
|
+ cache.FilePathMutex.Unlock()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -39,10 +57,10 @@ func IndexHandle(filePath string) {
|
|
|
//if err != nil {
|
|
|
// go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+filePath, 3)
|
|
|
//}
|
|
|
- filePath = strings.Replace(filePath, `"`, ``, -1)
|
|
|
+ //filePath = strings.Replace(filePath, `"`, ``, -1)
|
|
|
fmt.Println("开始刷新文件:", filePath)
|
|
|
time.Sleep(1 * time.Second)
|
|
|
MysteelChemicalRefresh(filePath)
|
|
|
//刷新完成后,清除缓存
|
|
|
- global.Rc.Delete(filePath)
|
|
|
+ //global.Rc.Delete(filePath)
|
|
|
}
|