Files
web_ylsa/api_iris/crontab/init.go
2025-07-11 16:54:11 +08:00

41 lines
901 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package crontab
import (
"github.com/robfig/cron/v3"
"github.com/sirupsen/logrus"
"main/database"
"main/model"
)
var MyCron *cron.Cron
func InitAllCron() {
MyCron = cron.New(cron.WithSeconds())
MyCron.Start()
db := database.GetInstance().GetMysqlDb()
var runningCron []model.RunningCrontab
if err := db.Where("deleted_at is null").Delete(&runningCron).Error; err != nil {
logrus.Errorln("sql执行失败", err)
return
}
}
func UpdateCronDb(id int, name string, status bool) {
db := database.GetInstance().GetMysqlDb()
var runningCron model.RunningCrontab
if status {
if err := db.Create(&model.RunningCrontab{
Name: name,
CronId: id,
}).Error; err != nil {
logrus.Errorln("sql执行失败", err)
return
}
} else {
if err := db.Delete(&runningCron, "cron_id = ?", id).Error; err != nil {
logrus.Errorln("sql执行失败", err)
return
}
}
}