optional store traffic time
This commit is contained in:
@@ -14,7 +14,7 @@ func NewCronJob() *CronJob {
|
||||
return &CronJob{}
|
||||
}
|
||||
|
||||
func (c *CronJob) Start(loc *time.Location) error {
|
||||
func (c *CronJob) Start(loc *time.Location, trafficAge int) error {
|
||||
c.cron = cron.New(cron.WithLocation(loc), cron.WithSeconds())
|
||||
c.cron.Start()
|
||||
|
||||
@@ -24,7 +24,7 @@ func (c *CronJob) Start(loc *time.Location) error {
|
||||
// Start expiry job
|
||||
c.cron.AddJob("@every 1m", NewDepleteJob())
|
||||
// Start deleting old stats
|
||||
c.cron.AddJob("@daily", NewDelStatsJob())
|
||||
c.cron.AddJob("@daily", NewDelStatsJob(trafficAge))
|
||||
}()
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,14 +7,17 @@ import (
|
||||
|
||||
type DelStatsJob struct {
|
||||
service.StatsService
|
||||
trafficAge int
|
||||
}
|
||||
|
||||
func NewDelStatsJob() *DelStatsJob {
|
||||
return &DelStatsJob{}
|
||||
func NewDelStatsJob(ta int) *DelStatsJob {
|
||||
return &DelStatsJob{
|
||||
trafficAge: ta,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DelStatsJob) Run() {
|
||||
err := s.StatsService.DelOldStats(30)
|
||||
err := s.StatsService.DelOldStats(s.trafficAge)
|
||||
if err != nil {
|
||||
logger.Warning("Deleting old statistics failed: ", err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user