1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package access_log
- import (
- "gd_access_log/apis"
- "gd_access_log/errors"
- "github.com/astaxie/beego/orm"
- "time"
- )
- func deleteAccessOldMinute(o orm.Ormer, nowMinute int64) {
- o.Raw("delete from t_gd_access_log_day where timestamp < ?", nowMinute).Exec()
- }
- func deleteThirdOldMinute(o orm.Ormer, nowMinute int64) {
- o.Raw("delete from t_gd_thirdpart_log_day where timestamp < ?", nowMinute).Exec()
- }
- func DeleteLogDayTask() {
- go func() {
- o := orm.NewOrm()
- t := time.NewTicker(1 * time.Hour)
- for {
- select {
- case <-t.C:
- now := time.Now()
- if now.Hour() == 6 {
- deleteMinute := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).AddDate(0, 0, -2).Unix()
- deleteAccessOldMinute(o, deleteMinute)
- deleteThirdOldMinute(o, deleteMinute)
- }
- }
- }
- }()
- }
- func writeLogDay(accessLog *apis.AccessLog, thirdLog []*apis.ThirdpartLog, o orm.Ormer) error {
- tab := apis.AccessLogDay{}
- tab.AccessLog = *accessLog
- tab.Id = 0
- accessId, err := o.Insert(&tab)
- if err != nil {
- return errors.DataBaseError
- }
- for _, v := range thirdLog {
- tab := apis.ThirdpartLogDay{}
- tab.ThirdpartLog = *v
- tab.Id = 0
- tab.AccessId = accessId
- _, err := o.Insert(&tab)
- if err != nil {
- return errors.DataBaseError
- }
- }
- return nil
- }
|