|
@@ -1,25 +1,38 @@
|
|
|
package services
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"fmt"
|
|
|
"hongze/mysteel_watch/global"
|
|
|
- "hongze/mysteel_watch/utils"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
// the service for log
|
|
|
func AutoRefresh() {
|
|
|
+ sub := global.Redis.Subscribe(context.TODO(), "autoRefresh")
|
|
|
+
|
|
|
defer func() {
|
|
|
+ sub.Close()
|
|
|
if err := recover(); err != nil {
|
|
|
fmt.Println("[AutoRefresh]", err)
|
|
|
}
|
|
|
}()
|
|
|
+ i := 0
|
|
|
for {
|
|
|
- global.Rc.Brpop(utils.REFRESH_INDEX, func(b []byte) {
|
|
|
- filePath := string(b)
|
|
|
- IndexHandle(filePath)
|
|
|
- })
|
|
|
+ i++
|
|
|
+ fmt.Println(i)
|
|
|
+ msg, err := sub.ReceiveMessage(context.TODO())
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("sub err:" + err.Error())
|
|
|
+ }
|
|
|
+ IndexHandle(msg.Payload)
|
|
|
+
|
|
|
+ //global.Rc.Brpop(utils.REFRESH_INDEX, func(b []byte) {
|
|
|
+ // filePath := string(b)
|
|
|
+ // fmt.Println("filePath:", filePath)
|
|
|
+ // IndexHandle(filePath)
|
|
|
+ //})
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -31,15 +44,7 @@ func IndexHandle(filePath string) {
|
|
|
filePath = strings.Replace(filePath, `"`, ``, -1)
|
|
|
fmt.Println("开始刷新文件:", filePath)
|
|
|
time.Sleep(1 * time.Second)
|
|
|
- if global.CONFIG.Serve.SystemType == "custom" {
|
|
|
- MysteelChemicalRefresh(filePath)
|
|
|
- } else {
|
|
|
- if global.CONFIG.Serve.Frequency != "周度" && !strings.Contains(filePath, "week") {
|
|
|
- MysteelChemicalRefresh(filePath)
|
|
|
- } else {
|
|
|
- MysteelChemicalRefresh(filePath)
|
|
|
- }
|
|
|
- }
|
|
|
+ MysteelChemicalRefresh(filePath)
|
|
|
//刷新完成后,清除缓存
|
|
|
- //global.Rc.Delete(filePath)
|
|
|
+ global.Rc.Delete(filePath)
|
|
|
}
|