|
@@ -3,10 +3,13 @@ package udptask
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io/ioutil"
|
|
"log"
|
|
"log"
|
|
mu "mfw/util"
|
|
mu "mfw/util"
|
|
"net"
|
|
"net"
|
|
|
|
+ "net/http"
|
|
qutil "qfw/util"
|
|
qutil "qfw/util"
|
|
|
|
+ "sync"
|
|
u "util"
|
|
u "util"
|
|
|
|
|
|
// "sync"
|
|
// "sync"
|
|
@@ -15,6 +18,10 @@ import (
|
|
. "tools"
|
|
. "tools"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+var responselock sync.Mutex
|
|
|
|
+
|
|
|
|
+var LastNodeResponse int64
|
|
|
|
+
|
|
func InitUdp() {
|
|
func InitUdp() {
|
|
go func() {
|
|
go func() {
|
|
updport, _ := Config["udpport"].(string)
|
|
updport, _ := Config["udpport"].(string)
|
|
@@ -65,9 +72,10 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
|
|
if key == "" {
|
|
if key == "" {
|
|
key = "udpok"
|
|
key = "udpok"
|
|
}
|
|
}
|
|
- Udpclient.WriteUdp([]byte(key), mu.OP_NOOP, ra)
|
|
|
|
|
|
+ go Udpclient.WriteUdp([]byte(key), mu.OP_NOOP, ra)
|
|
//行业分类开始,更新bidding_processing_ids表dataprocess=5
|
|
//行业分类开始,更新bidding_processing_ids表dataprocess=5
|
|
- if stype == "hangye" { //行业分类控制udp传输的id段顺序
|
|
|
|
|
|
+ if stype == "hangye" {
|
|
|
|
+ LastNodeResponse = time.Now().Unix()
|
|
task.HangyeUdps <- mapInfo
|
|
task.HangyeUdps <- mapInfo
|
|
gtid := mapInfo["gtid"].(string)
|
|
gtid := mapInfo["gtid"].(string)
|
|
lteid := mapInfo["lteid"].(string)
|
|
lteid := mapInfo["lteid"].(string)
|
|
@@ -82,6 +90,8 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
|
|
},
|
|
},
|
|
}
|
|
}
|
|
MgoClass.Update("bidding_processing_ids", query, set, false, false)
|
|
MgoClass.Update("bidding_processing_ids", query, set, false, false)
|
|
|
|
+ } else if stype == "monitor" { //程序监听类型
|
|
|
|
+ fmt.Println("stype :monitor")
|
|
} else if stype != "" {
|
|
} else if stype != "" {
|
|
go UdpTask(stype, mapInfo) //执行分类
|
|
go UdpTask(stype, mapInfo) //执行分类
|
|
} else {
|
|
} else {
|
|
@@ -90,11 +100,8 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
case mu.OP_NOOP: //下个节点回应
|
|
case mu.OP_NOOP: //下个节点回应
|
|
- ok := string(data)
|
|
|
|
- if ok != "" {
|
|
|
|
- log.Println("ok:", ok)
|
|
|
|
- udptaskmap.Delete(ok)
|
|
|
|
- }
|
|
|
|
|
|
+ udptaskmap.Delete(string(data))
|
|
|
|
+ log.Println("下节点回应:", string(data))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -260,3 +267,37 @@ func ExtractByUdp(ra *net.UDPAddr, instanceId ...string) {
|
|
log.Println("分类完成")
|
|
log.Println("分类完成")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//LastUdpJob 处理UDP 没有接受数据
|
|
|
|
+func LastUdpJob() {
|
|
|
|
+ for {
|
|
|
|
+ responselock.Lock()
|
|
|
|
+ if time.Now().Unix()-LastNodeResponse >= 1800 {
|
|
|
|
+ LastNodeResponse = time.Now().Unix() //重置时间
|
|
|
|
+ sendErrMailApi("分类异常", fmt.Sprintf("半小时左右~无新段落数据进入 分类流程...相关人员检查..."))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ responselock.Unlock()
|
|
|
|
+ time.Sleep(300 * time.Second)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//sendErrMailApi 发送邮件
|
|
|
|
+func sendErrMailApi(title, body string) {
|
|
|
|
+ jkmail, _ := Config["jkmail"].(map[string]interface{})
|
|
|
|
+ if jkmail != nil {
|
|
|
|
+ tomail, _ = jkmail["to"].(string)
|
|
|
|
+ api, _ = jkmail["api"].(string)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ log.Println(tomail, api)
|
|
|
|
+ res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", api, tomail, title, body))
|
|
|
|
+
|
|
|
|
+ if err == nil {
|
|
|
|
+ defer res.Body.Close()
|
|
|
|
+ read, err := ioutil.ReadAll(res.Body)
|
|
|
|
+ log.Println("邮件发送成功:", string(read), err)
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("邮件发送失败:", err)
|
|
|
|
+ }
|
|
|
|
+}
|