浏览代码

调整批量任务时间

boweniac 2 天之前
父节点
当前提交
e56c929643
共有 2 个文件被更改,包括 17 次插入11 次删除
  1. 11 10
      crontask/contact_form.go
  2. 6 1
      crontask/init.go

+ 11 - 10
crontask/contact_form.go

@@ -131,17 +131,18 @@ func (l *CronTask) analyze() {
 	predicates = append(predicates, usagedetail.AppIn(1, 3, 4, 5))
 	//yesterdayStart := time.Now().AddDate(0, 0, -1).Truncate(24 * time.Hour)
 	//yesterdayEnd := yesterdayStart.Add(24 * time.Hour)
-	loc, _ := time.LoadLocation("Asia/Shanghai")
-	now := time.Now().In(loc)
-	yesterdayEnd := now.Truncate(24 * time.Hour)
-	yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
-	predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
-	predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
 
-	//todayStart := time.Now().AddDate(0, 0, 0).Truncate(24 * time.Hour)
-	//todayEnd := todayStart.Add(24 * time.Hour)
-	//predicates = append(predicates, usagedetail.CreatedAtGTE(todayStart))
-	//predicates = append(predicates, usagedetail.CreatedAtLT(todayEnd))
+	//loc, _ := time.LoadLocation("Asia/Shanghai")
+	//now := time.Now().In(loc)
+	//yesterdayEnd := now.Truncate(24 * time.Hour)
+	//yesterdayStart := yesterdayEnd.AddDate(0, 0, -1)
+	//predicates = append(predicates, usagedetail.CreatedAtGTE(yesterdayStart))
+	//predicates = append(predicates, usagedetail.CreatedAtLT(yesterdayEnd))
+
+	todayStart := time.Now().AddDate(0, 0, 0).Truncate(24 * time.Hour)
+	todayEnd := todayStart.Add(24 * time.Hour)
+	predicates = append(predicates, usagedetail.CreatedAtGTE(todayStart))
+	predicates = append(predicates, usagedetail.CreatedAtLT(todayEnd))
 
 	data, err := l.svcCtx.DB.UsageDetail.Query().Where(predicates...).All(l.ctx)
 	logx.Info("usageDetails: ", data)

+ 6 - 1
crontask/init.go

@@ -49,8 +49,13 @@ func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
 	//	syncWx.syncWx()
 	//})
 
+	//contactForm := NewCronTask(context.Background(), serverCtx)
+	//c.AddFunc("1 0 * * *", func() {
+	//	contactForm.analyze()
+	//})
+
 	contactForm := NewCronTask(context.Background(), serverCtx)
-	c.AddFunc("1 0 * * *", func() {
+	c.AddFunc("@every 10m", func() {
 		contactForm.analyze()
 	})