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

Merge branch 'debug' of http://8.136.199.33:3000/eta_mini/eta_mini_crm into bzq/dev_confict

zqbao 10 сар өмнө
parent
commit
edd795040c
2 өөрчлөгдсөн 24 нэмэгдсэн , 27 устгасан
  1. 15 27
      scheduler/task.go
  2. 9 0
      utils/config.go

+ 15 - 27
scheduler/task.go

@@ -1,62 +1,50 @@
 package scheduler
 
 import (
+	"context"
 	"eta/eta_mini_crm/models"
 	"eta/eta_mini_crm/utils"
 	"fmt"
 	"time"
 
+	"github.com/beego/beego/v2/task"
 	"github.com/rdlucklib/rdluck_tools/paging"
-	"github.com/robfig/cron/v3"
 )
 
 func InitJob() {
 	fmt.Println("消息推送任务开启。。。")
-	c := cron.New(cron.WithSeconds())
 
 	// 每天凌晨1点检测, 发送消息
-	_, err := c.AddFunc("0 0 1 * * *", CheckUserTime)
-	if err != nil {
-		utils.ApiLog.Info("cron CheckUserTime task err: %s", err.Error())
-	}
+	tk1 := task.NewTask("CheckUserPermission", "0 0 1 * * *", CheckUserTime)
+	task.AddTask("CheckUserPermission", tk1)
 	// 每天凌晨1点检测, 修改用户状态
-	_, err = c.AddFunc("0 0 1 * * *", ModifyUser)
-	if err != nil {
-		utils.ApiLog.Info("cron ModifyUser task err: %s", err.Error())
-	}
-	c.Start()
+	tk2 := task.NewTask("ModifyUserStatus", "0 0 1 * * *", ModifyUser)
+	task.AddTask("ModifyUserStatus", tk2)
+	task.StartTask()
+	defer task.StopTask()
+
 }
 
-func CheckUserTime() {
-	retryCount := 10
+func CheckUserTime(ctx context.Context) error {
 	var err error
 	defer func() {
 		if err != nil {
 			utils.ApiLog.Warn("userPermission 定时任务出错,Err: %s", err.Error())
 		}
 	}()
-	for i := 0; i <= retryCount; i++ {
-		err = CheckUserPermissionTime()
-		if err == nil {
-			break
-		}
-	}
+	err = CheckUserPermissionTime()
+	return err
 }
 
-func ModifyUser() {
-	retryCount := 10
+func ModifyUser(ctx context.Context) error {
 	var err error
 	defer func() {
 		if err != nil {
 			utils.ApiLog.Warn("userPermission 定时任务出错,Err: %s", err.Error())
 		}
 	}()
-	for i := 0; i <= retryCount; i++ {
-		err = ModifyUserStatus()
-		if err == nil {
-			break
-		}
-	}
+	err = ModifyUserStatus()
+	return err
 }
 
 func ModifyUserStatus() (err error) {

+ 9 - 0
utils/config.go

@@ -34,6 +34,15 @@ func init() {
 	}
 	RunMode = tmpRunMode
 	fmt.Println("RunMode:", RunMode)
+	if RunMode == "" {
+		RunMode = "debug"
+		configPath := `/home/code/config/eta_mini_crm/conf/app.conf`
+		fmt.Println("configPath:", configPath)
+		err = web.LoadAppConfig("ini", configPath)
+		if err != nil {
+			fmt.Println("web.LoadAppConfig Err:" + err.Error())
+		}
+	}
 
 	config, err := web.AppConfig.GetSection(RunMode)
 	if err != nil {