main.go 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package main
  2. import (
  3. "customer_project/config"
  4. "fmt"
  5. "github.com/robfig/cron/v3"
  6. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  7. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  8. "net"
  9. "net/http"
  10. "net/rpc"
  11. "os"
  12. )
  13. var (
  14. updatePool chan []map[string]interface{}
  15. updateSp chan bool
  16. saveSize int
  17. )
  18. func init() {
  19. config.Init("./common.toml")
  20. InitLog()
  21. InitMysql()
  22. }
  23. func main() {
  24. loadData()
  25. go RpcService()
  26. taskProject()
  27. crn := cron.New()
  28. _, _ = crn.AddFunc("*/10 * * * *", func() {
  29. log.Info("start...")
  30. taskProject()
  31. })
  32. crn.Start()
  33. ch := make(chan bool, 1)
  34. <-ch
  35. }
  36. func RpcService() {
  37. rpc.Register(new(JyService)) // 注册rpc服务
  38. rpc.HandleHTTP() // 采用http协议作为rpc载体
  39. util.Debug(config.Conf.Serve.RpcServer)
  40. lis, err := net.Listen("tcp", config.Conf.Serve.RpcServer)
  41. if err != nil {
  42. util.Debug("fatal error: ", err)
  43. }
  44. _, _ = fmt.Fprintf(os.Stdout, "%s\n", "start connection")
  45. _ = http.Serve(lis, nil)
  46. }