29 lines
567 B
Go
29 lines
567 B
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/robfig/cron/v3"
|
|
"hepa-calc-api/api/crontab"
|
|
)
|
|
|
|
func StartCron() {
|
|
c := cron.New(cron.WithSeconds())
|
|
|
|
// 系统优惠卷过期
|
|
//_, err := c.AddFunc("* * * * * *", crontab.SystemCouponExpire)
|
|
//if err != nil {
|
|
// panic("定时器启动失败:" + err.Error())
|
|
//}
|
|
|
|
// 用户优惠卷过期
|
|
_, err := c.AddFunc("0 0 0 * * *", crontab.UserCouponExpire)
|
|
if err != nil {
|
|
panic("定时器启动失败:" + err.Error())
|
|
}
|
|
|
|
// 启动定时任务调度器
|
|
c.Start()
|
|
|
|
fmt.Println("初始化定时器成功......")
|
|
}
|