log_day.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package crontab
  4. import (
  5. "context"
  6. "gd_crontab/rpc_apis"
  7. "gd_crontab/rpc_apis/gd_management"
  8. "time"
  9. "github.com/astaxie/beego/orm"
  10. )
  11. func deleteAccessOldMinute(o orm.Ormer, nowMinute int64) {
  12. o.Raw("delete from t_gd_access_log_day where timestamp < ?", nowMinute).Exec()
  13. }
  14. func deleteThirdOldMinute(o orm.Ormer, nowMinute int64) {
  15. o.Raw("delete from t_gd_thirdpart_log_day where timestamp < ?", nowMinute).Exec()
  16. }
  17. func deleteProviderOldCount() {
  18. now := time.Now()
  19. old := now.AddDate(0, 0, -2)
  20. date := old.Format("2006-01-02")
  21. mreq := gd_management.ManagementDelProviderOldCountReq{
  22. Date: date,
  23. }
  24. rpc_apis.Management.ManagementDelProviderOldCount(context.Background(), &mreq)
  25. }
  26. /*
  27. func deleteWarningMailLog() {
  28. accessDB := warning.GetWarningMongoDb()
  29. collection := mongo.Session.DB(accessDB).C("mail_log")
  30. timestamp := time.Now().AddDate(0, 0, -1).Unix()
  31. collection.RemoveAll(bson.M{"timestamp": bson.M{"$lte": timestamp}})
  32. }*/
  33. func DeleteLogDayTask() {
  34. go func() {
  35. o := orm.NewOrm()
  36. t := time.NewTicker(1 * time.Hour)
  37. for {
  38. select {
  39. case <-t.C:
  40. now := time.Now()
  41. if now.Hour() == 6 {
  42. deleteProviderOldCount()
  43. deleteMinute := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).AddDate(0, 0, -2).Unix()
  44. deleteAccessOldMinute(o, deleteMinute)
  45. deleteThirdOldMinute(o, deleteMinute)
  46. //deleteWarningMailLog()
  47. }
  48. }
  49. }
  50. }()
  51. }