- 新增数据表:cron_task; - 后台新增后台任务模块,支持(创建、编辑、启用/禁用、列表); - 调整项目初始化,使其支持安装后台任务模块; - 调整服务升级指引,1.2.6 -> 1.2.7;
50 lines
1.9 KiB
Go
50 lines
1.9 KiB
Go
package cron_service
|
|
|
|
import (
|
|
"github.com/xinliangnote/go-gin-api/internal/api/repository/db_repo/cron_task_repo"
|
|
"github.com/xinliangnote/go-gin-api/internal/pkg/core"
|
|
)
|
|
|
|
type CreateCronTaskData struct {
|
|
Name string // 任务名称
|
|
Spec string // crontab 表达式
|
|
Command string // 执行命令
|
|
Protocol int32 // 执行方式 1:shell 2:http
|
|
HttpMethod int32 // http 请求方式 1:get 2:post
|
|
Timeout int32 // 超时时间(单位:秒)
|
|
RetryTimes int32 // 重试次数
|
|
RetryInterval int32 // 重试间隔(单位:秒)
|
|
NotifyStatus int32 // 执行结束是否通知 1:不通知 2:失败通知 3:结束通知 4:结果关键字匹配通知
|
|
NotifyType int32 // 通知类型 1:邮件 2:webhook
|
|
NotifyReceiverEmail string // 通知者邮箱地址(多个用,分割)
|
|
NotifyKeyword string // 通知匹配关键字(多个用,分割)
|
|
Remark string // 备注
|
|
IsUsed int32 // 是否启用 1:是 -1:否
|
|
}
|
|
|
|
func (s *service) Create(ctx core.Context, createData *CreateCronTaskData) (id int32, err error) {
|
|
model := cron_task_repo.NewModel()
|
|
model.Name = createData.Name
|
|
model.Spec = createData.Spec
|
|
model.Command = createData.Command
|
|
model.Protocol = createData.Protocol
|
|
model.HttpMethod = createData.HttpMethod
|
|
model.Timeout = createData.Timeout
|
|
model.RetryTimes = createData.RetryTimes
|
|
model.RetryInterval = createData.RetryInterval
|
|
model.NotifyStatus = createData.NotifyStatus
|
|
model.NotifyType = createData.NotifyType
|
|
model.NotifyReceiverEmail = createData.NotifyReceiverEmail
|
|
model.NotifyKeyword = createData.NotifyKeyword
|
|
model.Remark = createData.Remark
|
|
model.IsUsed = createData.IsUsed
|
|
model.CreatedUser = ctx.UserName()
|
|
|
|
id, err = model.Create(s.db.GetDbW().WithContext(ctx.RequestContext()))
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return
|
|
}
|