12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package main
- import (
- "app.yhyue.com/data_processing/common_utils/log"
- "bytes"
- "encoding/json"
- "fmt"
- "github.com/robfig/cron"
- "github.com/spf13/cobra"
- "go.mongodb.org/mongo-driver/bson"
- "go.uber.org/zap"
- "io/ioutil"
- "monitor/config"
- "net/http"
- )
- var (
- WebUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=45962efc-ca87-4996-9ffa-08bf6608ab7a"
- WarningStr = "数据采集bidding_file表数据,已累计%d数据未处理"
- )
- func init() {
- config.Init("./common.toml")
- InitLog()
- }
- func main() {
- rootCmd := &cobra.Command{Use: "my cmd"}
- rootCmd.AddCommand(biddingFile())
- if err := rootCmd.Execute(); err != nil {
- fmt.Println("rootCmd.Execute failed", err.Error())
- }
- }
- func biddingFile() *cobra.Command {
- cmdClient := &cobra.Command{
- Use: "bidding_file",
- Short: "Start statistics bidding_file data",
- Run: func(cmd *cobra.Command, args []string) {
- InitMgo()
- taskinfo()
- crn := cron.New()
- _ = crn.AddFunc("@hourly", func() {
- taskinfo()
- })
- crn.Start()
- c := make(chan bool, 1)
- <-c
- },
- }
- return cmdClient
- }
- func taskinfo() {
- count := MgoB.Count("bidding_file", bson.M{"moveok": bson.M{"$exists": false}})
- if count > 10000 {
- SendMsg(fmt.Sprintf(WarningStr, count))
- } else {
- log.Info("bidding_file", zap.Int("count", count))
- }
- }
- func SendMsg(content string) {
- client := &http.Client{}
- data := map[string]interface{}{"msgtype": "text", "text": map[string]interface{}{
- "content": content, "mentioned_mobile_list": []string{"13373929153", "15090279371", "15639297172"},
- }}
- bytesData, _ := json.Marshal(data)
- req, _ := http.NewRequest("POST", WebUrl, bytes.NewReader(bytesData))
- resp, _ := client.Do(req)
- body, _ := ioutil.ReadAll(resp.Body)
- log.Info("SendMsg", zap.String("resp", string(body)))
- }
|