Эх сурвалжийг харах

fix(internal): 优化全局限制查询和任务调度

- 移除了全局限制查询中的冗余条件 state = false
- 将任务调度频率从每分钟改为每天凌晨1 点执行
fusu 2 долоо хоног өмнө
parent
commit
22c6b7fc3b

+ 1 - 1
internal/repository/globallimit.go

@@ -67,7 +67,7 @@ func (r *globalLimitRepository) UpdateGlobalLimitByHostId(ctx context.Context, r
 
 func (r *globalLimitRepository) IsGlobalLimitExistByHostId(ctx context.Context, hostId int64) (bool, error) {
 	var count int64
-	err := r.DB(ctx).Model(&model.GlobalLimit{}).Where("host_id = ? AND state = false", hostId).Count(&count).Error
+	err := r.DB(ctx).Model(&model.GlobalLimit{}).Where("host_id = ?", hostId).Count(&count).Error
 
 	if err != nil {
 		return false, err

+ 4 - 4
internal/server/task.go

@@ -76,7 +76,7 @@ func (t *TaskServer) Start(ctx context.Context) error {
 
 
 
-	_, err := t.scheduler.Cron("* * * * *").Do(func() {
+	_, err := t.scheduler.Cron("1 * * * *").Do(func() {
 		err := t.wafTask.SynchronizationTime(ctx)
 		if err != nil {
 			t.log.Error("同步到期时间失败", zap.Error(err))
@@ -86,7 +86,7 @@ func (t *TaskServer) Start(ctx context.Context) error {
 		t.log.Error("同步到期时间注册任务失败", zap.Error(err))
 	}
 
-	_, err = t.scheduler.Cron("* * * * *").Do(func() {
+	_, err = t.scheduler.Cron("1 * * * *").Do(func() {
 		err := t.wafTask.StopPlan(ctx)
 		if err != nil {
 			t.log.Error("停止套餐失败", zap.Error(err))
@@ -97,7 +97,7 @@ func (t *TaskServer) Start(ctx context.Context) error {
 	}
 
 
-	_, err = t.scheduler.Cron("* * * * *").Do(func() {
+	_, err = t.scheduler.Cron("1 * * * *").Do(func() {
 		err := t.wafTask.RecoverRecentPlan(ctx)
 		if err != nil {
 			t.log.Error("续费失败", zap.Error(err))
@@ -108,7 +108,7 @@ func (t *TaskServer) Start(ctx context.Context) error {
 	}
 
 
-	_, err = t.scheduler.Cron("* * * * *").Do(func() {
+	_, err = t.scheduler.Cron("1 * * * *").Do(func() {
 		err := t.wafTask.CleanUpStaleRecords(ctx)
 		if err != nil {
 			t.log.Error("续费失败", zap.Error(err))