1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package services
- import (
- "context"
- "fmt"
- "hongze/mysteel_watch/global"
- "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 {
- 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)
- //})
- }
- }
- func IndexHandle(filePath string) {
- //err := UpdateComment(filePath)
- //if err != nil {
- // go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+filePath, 3)
- //}
- filePath = strings.Replace(filePath, `"`, ``, -1)
- fmt.Println("开始刷新文件:", filePath)
- time.Sleep(1 * time.Second)
- MysteelChemicalRefresh(filePath)
- //刷新完成后,清除缓存
- global.Rc.Delete(filePath)
- }
|