应用集成平台服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
893 B

2 years ago
package scheduledtask
import (
"fmt"
"time"
"github.com/robfig/cron/v3"
)
/*
*
@ 作者: 秦东
@ 时间: 2023-08-17 10:13:56
@ 功能: 定时任务模块 跟随主函数一起启动执行周期性任务操作
@ 参数
#
@ 返回值
#
@ 方法原型
#
*/
func TimeTask() {
fmt.Println("------------准备启动定时任务--------------")
go func() {
c := cron.New(cron.WithSeconds()) //声明定时任务启动器
/*
加载任务场景
AddFunc("任务时间格式","执行的任务")
*/
c.AddFunc("0 0 2 * * *", func() {
fmt.Printf("执行定时任务--同步试卷数据---->%v\n", time.Now().UTC())
// maptostruct.TestPageTimeTask()
2 years ago
}) //每3秒执行一个任务
c.Start() //启动
defer c.Stop() //设定全部执行后,最后关闭定时任务
select {}
}()
fmt.Printf("定时任务启动成功!TIME:%v\n", time.Now().UTC())
}