main.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package main
  2. import (
  3. "app.yhyue.com/data_processing/common_utils/log"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/robfig/cron"
  8. "github.com/spf13/cobra"
  9. "go.mongodb.org/mongo-driver/bson"
  10. "go.uber.org/zap"
  11. "io/ioutil"
  12. "monitor/config"
  13. "net/http"
  14. )
  15. var (
  16. WebUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=45962efc-ca87-4996-9ffa-08bf6608ab7a"
  17. WarningStr = "数据采集bidding_file表数据,已累计%d数据未处理"
  18. )
  19. func init() {
  20. config.Init("./common.toml")
  21. InitLog()
  22. }
  23. func main() {
  24. rootCmd := &cobra.Command{Use: "my cmd"}
  25. rootCmd.AddCommand(biddingFile())
  26. if err := rootCmd.Execute(); err != nil {
  27. fmt.Println("rootCmd.Execute failed", err.Error())
  28. }
  29. }
  30. func biddingFile() *cobra.Command {
  31. cmdClient := &cobra.Command{
  32. Use: "bidding_file",
  33. Short: "Start statistics bidding_file data",
  34. Run: func(cmd *cobra.Command, args []string) {
  35. InitMgo()
  36. taskinfo()
  37. crn := cron.New()
  38. _ = crn.AddFunc("@hourly", func() {
  39. taskinfo()
  40. })
  41. crn.Start()
  42. c := make(chan bool, 1)
  43. <-c
  44. },
  45. }
  46. return cmdClient
  47. }
  48. func taskinfo() {
  49. count := MgoB.Count("bidding_file", bson.M{"moveok": bson.M{"$exists": false}})
  50. if count > 10000 {
  51. SendMsg(fmt.Sprintf(WarningStr, count))
  52. } else {
  53. log.Info("bidding_file", zap.Int("count", count))
  54. }
  55. }
  56. func SendMsg(content string) {
  57. client := &http.Client{}
  58. data := map[string]interface{}{"msgtype": "text", "text": map[string]interface{}{
  59. "content": content, "mentioned_mobile_list": []string{"13373929153", "15090279371", "15639297172"},
  60. }}
  61. bytesData, _ := json.Marshal(data)
  62. req, _ := http.NewRequest("POST", WebUrl, bytes.NewReader(bytesData))
  63. resp, _ := client.Do(req)
  64. body, _ := ioutil.ReadAll(resp.Body)
  65. log.Info("SendMsg", zap.String("resp", string(body)))
  66. }