mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 05:12:32 +08:00
发布v2.11.5版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/simple"
|
||||
"hotgo/utility/validate"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type sSysCron struct{}
|
||||
@@ -90,7 +89,16 @@ func (s *sSysCron) Edit(ctx context.Context, in *sysin.CronEditInp) (err error)
|
||||
}
|
||||
|
||||
// 新增
|
||||
_, err = dao.SysCron.Ctx(ctx).Data(in).Insert()
|
||||
in.SysCron.Id, err = dao.SysCron.Ctx(ctx).Data(in).InsertAndGetId()
|
||||
if err != nil || in.SysCron.Id < 1 {
|
||||
return
|
||||
}
|
||||
|
||||
if in.SysCron.Status == consts.StatusEnabled {
|
||||
simple.SafeGo(ctx, func(ctx context.Context) {
|
||||
_ = cron.Start(&in.SysCron)
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -163,6 +171,10 @@ func (s *sSysCron) List(ctx context.Context, in *sysin.CronListInp) (list []*sys
|
||||
mod = mod.WhereLike("name", "%"+in.Name+"%")
|
||||
}
|
||||
|
||||
if in.GroupId > 0 {
|
||||
mod = mod.Where("group_id", in.GroupId)
|
||||
}
|
||||
|
||||
if in.Status > 0 {
|
||||
mod = mod.Where("status", in.Status)
|
||||
}
|
||||
@@ -210,7 +222,22 @@ func (s *sSysCron) OnlineExec(ctx context.Context, in *sysin.OnlineExecInp) (err
|
||||
err = gerror.New("定时任务不存在")
|
||||
return
|
||||
}
|
||||
|
||||
newCtx := context.WithValue(gctx.New(), consts.ContextKeyCronArgs, strings.Split(data.Params, consts.CronSplitStr))
|
||||
return cron.Once(newCtx, data)
|
||||
return cron.Once(gctx.New(), data)
|
||||
}
|
||||
|
||||
// DispatchLog 查看指定任务的调度日志
|
||||
func (s *sSysCron) DispatchLog(ctx context.Context, in *sysin.DispatchLogInp) (res *sysin.DispatchLogModel, err error) {
|
||||
var data *entity.SysCron
|
||||
if err = dao.SysCron.Ctx(ctx).Where(dao.SysCron.Columns().Id, in.Id).Scan(&data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if data == nil {
|
||||
err = gerror.New("定时任务不存在")
|
||||
return
|
||||
}
|
||||
|
||||
res = new(sysin.DispatchLogModel)
|
||||
res.Log, err = cron.DispatchLog(data)
|
||||
return
|
||||
}
|
||||
|
@@ -107,6 +107,17 @@ func (s *sSysCronGroup) List(ctx context.Context, in *sysin.CronGroupListInp) (l
|
||||
if err = mod.Page(in.Page, in.PerPage).Order("id desc").Scan(&list); err != nil {
|
||||
err = gerror.Wrap(err, consts.ErrorORM)
|
||||
}
|
||||
|
||||
for _, v := range list {
|
||||
if v.Pid < 1 {
|
||||
continue
|
||||
}
|
||||
name, err := dao.SysCronGroup.Ctx(ctx).Fields("name").WherePri(v.Pid).Value()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
v.SupName = name.String()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.9.3
|
||||
// @AutoGenerate Version 2.11.5
|
||||
package sys
|
||||
|
||||
import (
|
||||
|
Reference in New Issue
Block a user