main.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. package main
  2. import (
  3. "encoding/json"
  4. "esindex/config"
  5. "esindex/oss"
  6. "fmt"
  7. "github.com/robfig/cron"
  8. "go.uber.org/zap"
  9. "io/ioutil"
  10. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  11. "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
  12. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  13. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  14. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mysqldb"
  15. "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
  16. "net"
  17. "net/http"
  18. "os"
  19. "os/signal"
  20. "sync"
  21. "syscall"
  22. "time"
  23. )
  24. var (
  25. MgoB *mongodb.MongodbSim
  26. MgoP *mongodb.MongodbSim
  27. MgoQ *mongodb.MongodbSim
  28. MgoS *mongodb.MongodbSim
  29. Mysql *mysqldb.Mysql
  30. Es, Es2, Es3 *elastic.Elastic //Es3 迁移华为云新集群地址
  31. //PreEs = make(map[string]*elastic.Elastic, 0) //预处理 索引客户端
  32. UdpClient udp.UdpClient
  33. UdpTaskMap = &sync.Map{}
  34. JyUdpAddr *net.UDPAddr
  35. NeUdpAddr *net.UDPAddr
  36. EsBulkSize = 50 // es批量保存大小
  37. updateBiddingPool = make(chan map[string]interface{}, 5000) //更新bingding数据
  38. updateBiddingSp = make(chan bool, 5)
  39. saveEsPool = make(chan map[string]interface{}, 5000) //保存binding数据到es
  40. saveEsSp = make(chan bool, 5)
  41. saveProjectEsPool = make(chan map[string]interface{}, 5000) //保存project数据到es
  42. saveProjectSp = make(chan bool, 5)
  43. saveEsAllPool = make(chan map[string]interface{}, 5000) //存储单机版es,爬虫采集判重使用
  44. saveEsAllSp = make(chan bool, 5)
  45. saveBiddingAllPool = make(chan map[string]interface{}, 5000) //保存binding数据到es,stype=bidding_all_data
  46. saveBiddingAllBEsSp = make(chan bool, 5)
  47. saveErrBidPool = make(chan map[string]interface{}, 5000)
  48. saveBidSp = make(chan bool, 5)
  49. //detailLength = 50000 // es保存detail长度
  50. fileLength = 200000 // es保存附件文本长度,大于20万 时做一个日志记录
  51. //pscopeLength = 32766 // projectscope长度
  52. specialNames = make(map[string]bool, 0) //存储181 凭安提供的特企,爬虫采购单位
  53. responselock sync.Mutex
  54. BiddingLastNodeResponse int64 //上次节点接受数据时间
  55. ProjectLastNodeResponse int64 //上次节点接受数据时间
  56. )
  57. func init() {
  58. config.InitConf("./common.toml")
  59. InitLog()
  60. InitMysql()
  61. InitMgo()
  62. InitEs()
  63. InitField() //初始化项目数据升索引字段
  64. InitBitmap() //初始化项目名称副标题 bitmap
  65. InitRule() //初始化中国移动定制标签规则
  66. InitEsBiddingField() //初始bidding数据升索引字段
  67. oss.InitOss() // 初始化oss 存储
  68. verifyESFields() //检测es 字段类型
  69. JyUdpAddr = &net.UDPAddr{
  70. IP: net.ParseIP(config.Conf.Udp.JyAddr),
  71. Port: util.IntAll(config.Conf.Udp.JyPort),
  72. }
  73. if config.Conf.Udp.NeAddr != "" {
  74. NeUdpAddr = &net.UDPAddr{
  75. IP: net.ParseIP(config.Conf.Udp.NeAddr),
  76. Port: util.IntAll(config.Conf.Udp.NePort),
  77. }
  78. }
  79. BiddingLastNodeResponse = time.Now().Unix()
  80. ProjectLastNodeResponse = time.Now().Unix()
  81. log.Info("init success")
  82. }
  83. func main() {
  84. //正式环境才执行定时任务
  85. if config.Conf.Env.Stype == 0 {
  86. go LastUdpJob() //监听半小时内有无数据
  87. go checkMapJob() //udp 发送邮件
  88. go task_index() //定时同步更新winner_enterprise、buyer_enterprise ES索引;这个功能很少变动,几乎不需要维护
  89. }
  90. go UpdateBidding() //更新bidding表数据
  91. go SaveEsMethod()
  92. go SaveAllEsMethod()
  93. go SaveProjectEs()
  94. go SaveBiddingAllDataEs()
  95. go SaveBidErr()
  96. //添加预处理函数
  97. //if config.Conf.Env.OpenPre {
  98. // go SavePreEsMethod()
  99. // go dealPreProcess()
  100. //}
  101. UdpClient = udp.UdpClient{Local: config.Conf.Udp.LocPort, BufSize: 1024}
  102. UdpClient.Listen(processUdpMsg)
  103. log.Info("Udp服务监听", zap.String("port:", config.Conf.Udp.LocPort))
  104. //监听异常退出信号;及时保存项目名称副标题数据
  105. signalChan := make(chan os.Signal, 1)
  106. signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
  107. <-signalChan
  108. saveDb()
  109. ch := make(chan bool, 1)
  110. <-ch
  111. }
  112. var pool = make(chan bool, 20)
  113. func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
  114. switch act {
  115. case udp.OP_TYPE_DATA:
  116. var mapInfo map[string]interface{}
  117. err := json.Unmarshal(data, &mapInfo)
  118. log.Info("processUdpMsg", zap.Any("mapInfo:", mapInfo))
  119. if err != nil {
  120. UdpClient.WriteUdp([]byte("err:"+err.Error()), udp.OP_NOOP, ra)
  121. } else if mapInfo != nil {
  122. key, _ := mapInfo["key"].(string)
  123. if key == "" {
  124. key = "udpok"
  125. }
  126. go UdpClient.WriteUdp([]byte(key), udp.OP_NOOP, ra)
  127. //有udp 转发时
  128. if config.Conf.Udp.NeAddr != "" {
  129. go SendUdpMsg(mapInfo, NeUdpAddr)
  130. }
  131. tasktype, _ := mapInfo["stype"].(string)
  132. switch tasktype {
  133. case "index-by-id": //单个索引,更新pici
  134. pool <- true
  135. go func() {
  136. defer func() {
  137. <-pool
  138. }()
  139. biddingTaskById(mapInfo)
  140. }()
  141. case "index_by_id": //单个索引,不更新pici
  142. pool <- true
  143. go func() {
  144. defer func() {
  145. <-pool
  146. }()
  147. biddingTaskById(mapInfo)
  148. }()
  149. case "bidding":
  150. BiddingLastNodeResponse = time.Now().Unix()
  151. pool <- true
  152. go func() {
  153. defer func() {
  154. <-pool
  155. }()
  156. biddingTask(mapInfo)
  157. }()
  158. case "biddingall": //补充存量数据
  159. pool <- true
  160. go func() {
  161. defer func() {
  162. <-pool
  163. }()
  164. biddingAllTask(mapInfo)
  165. }()
  166. case "bidding_all_data": //根据biddingall配置文件,存量迁移数据
  167. pool <- true
  168. go func() {
  169. defer func() {
  170. <-pool
  171. }()
  172. biddingAllDataTask()
  173. }()
  174. case "bidding_history":
  175. pool <- true
  176. go func() {
  177. defer func() {
  178. <-pool
  179. }()
  180. biddingTask(mapInfo)
  181. }()
  182. case "project":
  183. ProjectLastNodeResponse = time.Now().Unix()
  184. pool <- true
  185. go func() {
  186. defer func() {
  187. <-pool
  188. }()
  189. projectTask(data, mapInfo)
  190. }()
  191. case "project_all_data": //存量 projectset 数据
  192. pool <- true
  193. go func() {
  194. defer func() {
  195. <-pool
  196. }()
  197. projectAllData()
  198. }()
  199. case "biddingdata": //es 单机版,采集判重
  200. pool <- true
  201. go func() {
  202. defer func() {
  203. <-pool
  204. }()
  205. biddingDataTask(data, mapInfo)
  206. }()
  207. case "biddingdelbyextracttype": //根据bidding表extracttype=-1,删除es中重复数据
  208. pool <- true
  209. go func() {
  210. defer func() {
  211. <-pool
  212. }()
  213. biddingDelByExtracttype(data, mapInfo)
  214. }()
  215. case "buyer_once": // 采购单位昨天增量数据
  216. pool <- true
  217. go func() {
  218. defer func() {
  219. <-pool
  220. }()
  221. buyerOnce()
  222. }()
  223. case "buyer_all": // 采购单位全量数据
  224. pool <- true
  225. go func() {
  226. defer func() {
  227. <-pool
  228. }()
  229. buyerAll()
  230. }()
  231. case "winner_once": // 中标单位昨天增量数据
  232. pool <- true
  233. go func() {
  234. defer func() {
  235. <-pool
  236. }()
  237. winnerEsTaskOnce()
  238. }()
  239. case "winner_all": // 中标单位存量数据
  240. pool <- true
  241. go func() {
  242. defer func() {
  243. <-pool
  244. }()
  245. winnerEsAll()
  246. }()
  247. case "attachment": // 补充附件采集,对应bidding为bidding_downloadfile_log
  248. pool <- true
  249. go func() {
  250. defer func() {
  251. <-pool
  252. }()
  253. //有单独配置其他操作
  254. if len(config.Conf.Others) > 0 {
  255. if v, ok := config.Conf.Others[tasktype]; ok {
  256. attachmentBiddingTask(mapInfo, v)
  257. }
  258. }
  259. }()
  260. default:
  261. pool <- true
  262. go func() {
  263. defer func() {
  264. <-pool
  265. }()
  266. log.Info("err", zap.Any("mapInfo", mapInfo))
  267. }()
  268. }
  269. }
  270. case udp.OP_NOOP: //下个节点回应
  271. ok := string(data)
  272. if ok != "" {
  273. log.Info("udp re", zap.String("data:", ok))
  274. UdpTaskMap.Delete(ok)
  275. }
  276. }
  277. }
  278. func task_index() {
  279. c := cron.New()
  280. _ = c.AddFunc("0 00 00 * * *", func() { task_winneres() }) //每天凌晨执行一次winner生索引
  281. _ = c.AddFunc("0 00 01 * * *", func() { task_buyeres() }) //每天1点执行一次buyer生索引
  282. c.Start()
  283. }
  284. func task_winneres() {
  285. log.Info("定时任务,winneres")
  286. winnerEsTaskOnce()
  287. }
  288. func task_buyeres() {
  289. log.Info("定时任务,buyeres")
  290. buyerOnce()
  291. }
  292. type UdpNode struct {
  293. data []byte
  294. addr *net.UDPAddr
  295. timestamp int64
  296. retry int
  297. }
  298. // UpdateBidding 更新bidding表数据
  299. func UpdateBidding() {
  300. //arru := make([][]map[string]interface{}, 10)
  301. //indexu := 0
  302. for {
  303. select {
  304. case v := <-updateBiddingPool:
  305. MgoB.UpdateById(config.Conf.DB.MongoB.Coll, v["_id"], map[string]interface{}{"$set": v["set"]})
  306. //arru[indexu] = v
  307. //indexu++
  308. //if indexu == 10 {
  309. // updateBiddingSp <- true
  310. //go func(arru [][]map[string]interface{}) {
  311. // defer func() {
  312. // <-updateBiddingSp
  313. //}()
  314. //MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, arru...)
  315. //}(arru)
  316. //arru = make([][]map[string]interface{}, 10)
  317. //indexu = 0
  318. //}
  319. //case <-time.After(1000 * time.Millisecond):
  320. // if indexu > 0 {
  321. // updateBiddingSp <- true
  322. // go func(arru [][]map[string]interface{}) {
  323. // defer func() {
  324. // <-updateBiddingSp
  325. // }()
  326. // MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, arru...)
  327. // }(arru[:indexu])
  328. // arru = make([][]map[string]interface{}, 200)
  329. // indexu = 0
  330. // }
  331. }
  332. }
  333. }
  334. // SaveBidErr 记录错误信息,暂时记录 附件过长的
  335. func SaveBidErr() {
  336. arru := make([]map[string]interface{}, 200)
  337. indexu := 0
  338. for {
  339. select {
  340. case v := <-saveErrBidPool:
  341. arru[indexu] = v
  342. indexu++
  343. if indexu == 200 {
  344. saveBidSp <- true
  345. go func(arru []map[string]interface{}) {
  346. defer func() {
  347. <-saveBidSp
  348. }()
  349. MgoB.SaveBulk("bidding_es_err_record", arru...)
  350. }(arru)
  351. arru = make([]map[string]interface{}, 200)
  352. indexu = 0
  353. }
  354. case <-time.After(1000 * time.Millisecond):
  355. if indexu > 0 {
  356. saveBidSp <- true
  357. go func(arru []map[string]interface{}) {
  358. defer func() {
  359. <-saveBidSp
  360. }()
  361. MgoB.SaveBulk("bidding_es_err_record", arru...)
  362. }(arru[:indexu])
  363. arru = make([]map[string]interface{}, 200)
  364. indexu = 0
  365. }
  366. }
  367. }
  368. }
  369. // SaveEsMethod 保存bidding数据到es
  370. func SaveEsMethod() {
  371. //arru := make([]map[string]interface{}, EsBulkSize)
  372. //indexu := 0
  373. for {
  374. select {
  375. case v := <-saveEsPool:
  376. id := v["id"]
  377. ids := v["_id"]
  378. Es.Save(config.Conf.DB.Es.IndexB, v)
  379. // 华为云集群1
  380. if config.Conf.DB.Es.Addr2 != "" {
  381. v["id"] = id
  382. v["_id"] = ids
  383. Es2.Save(config.Conf.DB.Es.Indexb2, v)
  384. }
  385. // 华为云新集群2,迁移原来阿里云数据
  386. if config.Conf.DB.Es.Addr3 != "" {
  387. v["id"] = id
  388. v["_id"] = ids
  389. Es3.Save(config.Conf.DB.Es.Indexb3, v)
  390. }
  391. //arru[indexu] = v
  392. //indexu++
  393. //if indexu == EsBulkSize {
  394. // saveEsSp <- true
  395. //go func(arru []map[string]interface{}) {
  396. // defer func() {
  397. //<-saveEsSp
  398. //}()
  399. //if config.Conf.DB.Es.IndexTmp != "" {
  400. // if config.Conf.DB.Es.Addr2 != "" {
  401. // Es2.BulkSave(config.Conf.DB.Es.IndexTmp, arru) // 新集群
  402. // }
  403. // Es.BulkSave(config.Conf.DB.Es.IndexTmp, arru) //老集群
  404. //}
  405. //}(arru)
  406. //arru = make([]map[string]interface{}, EsBulkSize)
  407. //indexu = 0
  408. //}
  409. //case <-time.After(1000 * time.Millisecond):
  410. // if indexu > 0 {
  411. // saveEsSp <- true
  412. // go func(arru []map[string]interface{}) {
  413. // defer func() {
  414. // <-saveEsSp
  415. // }()
  416. // Es.BulkSave(config.Conf.DB.Es.IndexB, arru)
  417. //if config.Conf.DB.Es.IndexTmp != "" {
  418. // if config.Conf.DB.Es.Addr2 != "" {
  419. // Es2.BulkSave(config.Conf.DB.Es.IndexTmp, arru) // 新集群
  420. // }
  421. // Es.BulkSave(config.Conf.DB.Es.IndexTmp, arru)
  422. //}
  423. // if config.Conf.DB.Es.Addr2 != "" {
  424. // Es2.BulkSave(config.Conf.DB.Es.Indexb2, arru)
  425. // }
  426. // }(arru[:indexu])
  427. // arru = make([]map[string]interface{}, EsBulkSize)
  428. // indexu = 0
  429. //}
  430. }
  431. }
  432. }
  433. // SaveAllEsMethod 保存爬虫采集临时数据,保存在华为云上
  434. func SaveAllEsMethod() {
  435. arru := make([]map[string]interface{}, EsBulkSize)
  436. indexu := 0
  437. for {
  438. select {
  439. case v := <-saveEsAllPool:
  440. arru[indexu] = v
  441. indexu++
  442. if indexu == EsBulkSize {
  443. saveEsAllSp <- true
  444. go func(arru []map[string]interface{}) {
  445. defer func() {
  446. <-saveEsAllSp
  447. }()
  448. if config.Conf.DB.Es.Addr2 != "" {
  449. Es2.BulkSave("biddingall", arru)
  450. }
  451. }(arru)
  452. arru = make([]map[string]interface{}, EsBulkSize)
  453. indexu = 0
  454. }
  455. case <-time.After(1000 * time.Millisecond):
  456. if indexu > 0 {
  457. saveEsAllSp <- true
  458. go func(arru []map[string]interface{}) {
  459. defer func() {
  460. <-saveEsAllSp
  461. }()
  462. if config.Conf.DB.Es.Addr2 != "" {
  463. Es2.BulkSave("biddingall", arru)
  464. }
  465. }(arru[:indexu])
  466. arru = make([]map[string]interface{}, EsBulkSize)
  467. indexu = 0
  468. }
  469. }
  470. }
  471. }
  472. // SaveBiddingAllDataEs 保存bidding数据到Es,stype=bidding_all_data 数据
  473. func SaveBiddingAllDataEs() {
  474. arru := make([]map[string]interface{}, EsBulkSize)
  475. indexu := 0
  476. for {
  477. select {
  478. case v := <-saveBiddingAllPool:
  479. arru[indexu] = v
  480. indexu++
  481. if indexu == EsBulkSize {
  482. saveBiddingAllBEsSp <- true
  483. go func(arru []map[string]interface{}) {
  484. defer func() {
  485. <-saveBiddingAllBEsSp
  486. }()
  487. //1.阿里云集群
  488. Es.BulkSave(config.Conf.DB.Es.IndexB, arru)
  489. }(arru)
  490. arru = make([]map[string]interface{}, EsBulkSize)
  491. indexu = 0
  492. }
  493. case <-time.After(1000 * time.Millisecond):
  494. if indexu > 0 {
  495. saveBiddingAllBEsSp <- true
  496. go func(arru []map[string]interface{}) {
  497. defer func() {
  498. <-saveBiddingAllBEsSp
  499. }()
  500. //1.阿里云集群
  501. Es.BulkSave(config.Conf.DB.Es.IndexB, arru)
  502. }(arru[:indexu])
  503. arru = make([]map[string]interface{}, EsBulkSize)
  504. indexu = 0
  505. }
  506. }
  507. }
  508. }
  509. // SaveProjectEs 保存项目索引数据
  510. func SaveProjectEs() {
  511. arru := make([]map[string]interface{}, EsBulkSize)
  512. indexu := 0
  513. for {
  514. select {
  515. case v := <-saveProjectEsPool:
  516. arru[indexu] = v
  517. indexu++
  518. if indexu == EsBulkSize {
  519. saveProjectSp <- true
  520. go func(arru []map[string]interface{}) {
  521. defer func() {
  522. <-saveProjectSp
  523. }()
  524. Es.BulkSave(config.Conf.DB.Es.IndexP, arru)
  525. // 华为云新集群,存储标讯、项目、凭安数据
  526. if config.Conf.DB.Es.Addr3 != "" {
  527. Es3.BulkSave(config.Conf.DB.Es.IndexP, arru)
  528. }
  529. }(arru)
  530. arru = make([]map[string]interface{}, EsBulkSize)
  531. indexu = 0
  532. }
  533. case <-time.After(1000 * time.Millisecond):
  534. if indexu > 0 {
  535. saveProjectSp <- true
  536. go func(arru []map[string]interface{}) {
  537. defer func() {
  538. <-saveProjectSp
  539. }()
  540. Es.BulkSave(config.Conf.DB.Es.IndexP, arru)
  541. // 华为云新集群,存储标讯、项目、凭安数据
  542. if config.Conf.DB.Es.Addr3 != "" {
  543. Es3.BulkSave(config.Conf.DB.Es.IndexP, arru)
  544. }
  545. }(arru[:indexu])
  546. arru = make([]map[string]interface{}, EsBulkSize)
  547. indexu = 0
  548. }
  549. }
  550. }
  551. }
  552. func checkMapJob() {
  553. if config.Conf.Mail.Send {
  554. log.Info("checkMapJob", zap.String("to:", config.Conf.Mail.To))
  555. for {
  556. UdpTaskMap.Range(func(k, v interface{}) bool {
  557. now := time.Now().Unix()
  558. node, _ := v.(*UdpNode)
  559. if now-node.timestamp > 120 {
  560. node.retry++
  561. if node.retry > 5 {
  562. UdpTaskMap.Delete(k)
  563. res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", config.Conf.Mail.Api, config.Conf.Mail.To, "field-sync-send-fail", k.(string)))
  564. if err == nil {
  565. defer res.Body.Close()
  566. read, err := ioutil.ReadAll(res.Body)
  567. log.Info("send mail ...", zap.String("r:", string(read)), zap.Any("err:", err))
  568. }
  569. } else {
  570. log.Info("udp重发", zap.Any("k:", k))
  571. UdpClient.WriteUdp(node.data, udp.OP_TYPE_DATA, node.addr)
  572. }
  573. } else if now-node.timestamp > 10 {
  574. log.Info("udp任务超时中..", zap.Any("k:", k))
  575. }
  576. return true
  577. })
  578. time.Sleep(60 * time.Second)
  579. }
  580. }
  581. }
  582. func task() {
  583. sess := MgoB.GetMgoConn()
  584. defer MgoB.DestoryMongoConn(sess)
  585. ch := make(chan bool, 10)
  586. wg := &sync.WaitGroup{}
  587. query := sess.DB("qfw").C("result_replace_repair_log").Find(nil).Iter()
  588. count := 0
  589. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  590. if count%1000 == 0 {
  591. util.Debug("current ---", count)
  592. }
  593. ch <- true
  594. wg.Add(1)
  595. go func(tmp map[string]interface{}) {
  596. defer func() {
  597. <-ch
  598. wg.Done()
  599. }()
  600. if id := util.ObjToString(tmp["replace_id"]); mongodb.IsObjectIdHex(id) {
  601. biddingTaskById(map[string]interface{}{"infoid": id, "stype": "bidding"})
  602. }
  603. }(tmp)
  604. tmp = make(map[string]interface{})
  605. }
  606. wg.Wait()
  607. util.Debug("over ---", count)
  608. }
  609. // LastUdpJob 处理UDP 没有接受数据
  610. func LastUdpJob() {
  611. for {
  612. responselock.Lock()
  613. if time.Now().Unix()-BiddingLastNodeResponse >= 1800 {
  614. BiddingLastNodeResponse = time.Now().Unix() //重置时间
  615. sendErrMailApi("索引程序异常", fmt.Sprintf("半小时左右 无bidding据进入 ...相关人员检查..."))
  616. }
  617. if time.Now().Unix()-ProjectLastNodeResponse >= 1800 {
  618. ProjectLastNodeResponse = time.Now().Unix() //重置时间
  619. sendErrMailApi("索引程序异常", fmt.Sprintf("半小时左右 无project数据进入 ...相关人员检查..."))
  620. }
  621. responselock.Unlock()
  622. time.Sleep(300 * time.Second)
  623. }
  624. }
  625. // sendErrMailApi 发送邮件
  626. func sendErrMailApi(title, body string) {
  627. var tomail, api string
  628. if config.Conf.Mail.Send {
  629. tomail = config.Conf.Mail.To
  630. api = config.Conf.Mail.Api
  631. }
  632. log.Info("sendErrMailApi", zap.Any(tomail, api))
  633. res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", api, tomail, title, body))
  634. if err == nil {
  635. defer res.Body.Close()
  636. read, err := ioutil.ReadAll(res.Body)
  637. if err != nil {
  638. log.Info("邮件发送成功", zap.String("read", string(read)))
  639. }
  640. } else {
  641. log.Info("sendErrMailApi", zap.String("邮件发送失败", err.Error()))
  642. }
  643. }