start.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package crons
  2. import (
  3. "fmt"
  4. "time"
  5. "bet24.com/profile"
  6. "github.com/robfig/cron"
  7. )
  8. var (
  9. cpuProfile interface {
  10. Stop()
  11. }
  12. memProfile interface {
  13. Stop()
  14. }
  15. )
  16. func Run() {
  17. c := cron.New()
  18. //秒(Seconds) 0-59
  19. //分(Minutes) 0-59
  20. //小时(Hours) 0-23
  21. //一个月中的某一天(Day of month) 1-31
  22. //月(Month) 1-12 or JAN-DEC
  23. //星期几(Day of week) 0-6 or SUN-SAT
  24. c.AddFunc("0 0/30 * * * ? ", profSample)
  25. //c.AddFunc("0/5 * * * * ?",public_transaction.CheckLonghuTax)
  26. c.Start()
  27. }
  28. /**
  29. 生成性能分析图,没30分钟执行一次
  30. */
  31. func profSample() {
  32. if cpuProfile != nil {
  33. cpuProfile.Stop()
  34. }
  35. if memProfile != nil {
  36. memProfile.Stop()
  37. }
  38. //路径可以改为从配置文件获取, ./2019-05-18/17.30/
  39. path := "./dump/"
  40. now := time.Now()
  41. date := now.Format("2006-01-02")
  42. path = fmt.Sprintf("%s/%d.%d", path+date, now.Hour(), now.Minute())
  43. cpuProfile = profile.Start(profile.CPUProfile, profile.ProfilePath(path), profile.NamePrefix("webcenter_"))
  44. memProfile = profile.Start(profile.MemProfile, profile.ProfilePath(path), profile.NamePrefix("webcenter_"))
  45. }