任务调度update
This commit is contained in:
@@ -75,7 +75,7 @@ func (d CronJobDao) Update(config entity.SysCronJob) int64 {
|
||||
return update
|
||||
}
|
||||
|
||||
// Remove 删除数据
|
||||
// Delete 删除数据
|
||||
func (d CronJobDao) Delete(list []int64) bool {
|
||||
session := SqlDB.NewSession()
|
||||
session.Begin()
|
||||
@@ -89,7 +89,7 @@ func (d CronJobDao) Delete(list []int64) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// 通过方法别名获取任务详情
|
||||
// SelectByFuncAlias 通过方法别名获取任务详情
|
||||
func (d CronJobDao) SelectByFuncAlias(funcAlias string) *entity.SysCronJob {
|
||||
config := entity.SysCronJob{}
|
||||
session := d.sql(SqlDB.NewSession())
|
||||
@@ -100,3 +100,15 @@ func (d CronJobDao) SelectByFuncAlias(funcAlias string) *entity.SysCronJob {
|
||||
}
|
||||
return &config
|
||||
}
|
||||
|
||||
// SelectAll 查找所有启用状态的任务
|
||||
func (d CronJobDao) SelectAll() ([]entity.SysCronJob, int) {
|
||||
configs := make([]entity.SysCronJob, 0)
|
||||
session := d.sql(SqlDB.NewSession())
|
||||
err := session.Where("status = ?", 1).Find(&configs)
|
||||
if err != nil {
|
||||
common.ErrorLog(err)
|
||||
return nil, 0
|
||||
}
|
||||
return configs, len(configs)
|
||||
}
|
||||
|
||||
+3
-15
@@ -1,21 +1,9 @@
|
||||
package job
|
||||
|
||||
import (
|
||||
"cutego/core/service"
|
||||
"cutego/pkg/common"
|
||||
)
|
||||
|
||||
// 定时任务: 别名与方法的映射
|
||||
// AliasFuncMap 定时任务: 别名与方法的映射
|
||||
var AliasFuncMap = make(map[string]func())
|
||||
|
||||
// 注册任务
|
||||
func RegisterFunc(aliasName string, f func()) {
|
||||
currentJob := service.CronJobService{}.GetInfoByAlias(aliasName)
|
||||
AliasFuncMap[aliasName] = f
|
||||
common.InfoLogf("注册定时任务 --- %s ---> Success", currentJob.JobName)
|
||||
}
|
||||
|
||||
// 注册方法
|
||||
// 任务注册
|
||||
func init() {
|
||||
RegisterFunc("test1", TestJob)
|
||||
AliasFuncMap["test1"] = TestJob1
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ package job
|
||||
|
||||
import "fmt"
|
||||
|
||||
func TestJob() {
|
||||
fmt.Println("哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈")
|
||||
func TestJob1() {
|
||||
fmt.Println("无参数任务执行中...")
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (s CronJobService) GetInfo(id int64) *entity.SysCronJob {
|
||||
return s.cronJobDao.SelectById(id)
|
||||
}
|
||||
|
||||
// GetInfo 查询数据
|
||||
// GetInfoByAlias 查询数据
|
||||
func (s CronJobService) GetInfoByAlias(funcAlias string) *entity.SysCronJob {
|
||||
return s.cronJobDao.SelectByFuncAlias(funcAlias)
|
||||
}
|
||||
@@ -39,3 +39,8 @@ func (s CronJobService) Edit(config entity.SysCronJob) int64 {
|
||||
func (s CronJobService) Remove(list []int64) bool {
|
||||
return s.cronJobDao.Delete(list)
|
||||
}
|
||||
|
||||
// FindAll 查找所有
|
||||
func (s CronJobService) FindAll() ([]entity.SysCronJob, int) {
|
||||
return s.cronJobDao.SelectAll()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user