|
@@ -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) {
|