mirror of https://github.com/ouqiang/gocron
删除延时任务
parent
d5eed97595
commit
dcf86e00a3
|
@ -33,6 +33,12 @@ func (host *Host) Delete(id int) (int64, error) {
|
|||
return Db.Id(id).Delete(host)
|
||||
}
|
||||
|
||||
func (host *Host) Find(id int) error {
|
||||
_, err := Db.Id(id).Get(host)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (host *Host) NameExists(name string) (bool, error) {
|
||||
count, err := Db.Where("name = ?", name).Count(host);
|
||||
|
||||
|
|
|
@ -21,7 +21,19 @@ func Index(ctx *macaron.Context) {
|
|||
|
||||
func Create(ctx *macaron.Context) {
|
||||
ctx.Data["Title"] = "添加主机"
|
||||
ctx.HTML(200, "host/create")
|
||||
ctx.HTML(200, "host/host_form")
|
||||
}
|
||||
|
||||
func Edit(ctx *macaron.Context) {
|
||||
ctx.Data["Title"] = "编辑主机"
|
||||
hostModel := new(models.Host)
|
||||
id := ctx.ParamsInt(":id")
|
||||
err := hostModel.Find(id)
|
||||
if err != nil {
|
||||
logger.Errorf("获取主机详情失败#主机id-%d", id)
|
||||
}
|
||||
ctx.Data["Host"] = hostModel
|
||||
ctx.HTML(200, "host/host_form")
|
||||
}
|
||||
|
||||
type HostForm struct {
|
||||
|
|
|
@ -36,7 +36,7 @@ func Register(m *macaron.Macaron) {
|
|||
// 50x错误
|
||||
m.InternalServerError(func(ctx *macaron.Context) {
|
||||
if isGetRequest(ctx) && !isAjaxRequest(ctx) {
|
||||
ctx.Data["Title"] = "500 - SERVER INTERNAL ERROR"
|
||||
ctx.Data["Title"] = "500 - INTERNAL SERVER ERROR"
|
||||
ctx.HTML(500, "error/500")
|
||||
} else {
|
||||
json := utils.JsonResponse{}
|
||||
|
@ -71,6 +71,7 @@ func Register(m *macaron.Macaron) {
|
|||
// 主机
|
||||
m.Group("/host", func() {
|
||||
m.Get("/create", host.Create)
|
||||
m.Get("/Edit", host.Edit)
|
||||
m.Post("/store", binding.Bind(host.HostForm{}), host.Store)
|
||||
m.Get("", host.Index)
|
||||
m.Post("/remove/:id", host.Remove)
|
||||
|
@ -112,7 +113,6 @@ func RegisterMiddleware(m *macaron.Macaron) {
|
|||
// 设置模板共享变量
|
||||
m.Use(func(ctx *macaron.Context) {
|
||||
ctx.Data["URI"] = ctx.Req.RequestURI
|
||||
ctx.Data["StandardTimeFormat"] = "2006-01-02 15:03:04"
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ func Create(ctx *macaron.Context) {
|
|||
ctx.Data["Hosts"] = hosts
|
||||
ctx.Data["FirstHostName"] = hosts[0].Name
|
||||
ctx.Data["FirstHostId"] = hosts[0].Id
|
||||
ctx.HTML(200, "task/create")
|
||||
ctx.HTML(200, "task/task_form")
|
||||
}
|
||||
|
||||
type TaskForm struct {
|
||||
|
@ -88,13 +88,10 @@ func Store(ctx *macaron.Context, form TaskForm) string {
|
|||
|
||||
// 删除任务
|
||||
func Remove(ctx *macaron.Context) string {
|
||||
id, err := strconv.Atoi(ctx.Params(":id"))
|
||||
id := ctx.ParamsInt(":id")
|
||||
json := utils.JsonResponse{}
|
||||
if err != nil {
|
||||
return json.CommonFailure("参数错误", err)
|
||||
}
|
||||
taskModel := new(models.Task)
|
||||
_, err = taskModel.Delete(id)
|
||||
_, err := taskModel.Delete(id)
|
||||
if err != nil {
|
||||
return json.CommonFailure(utils.FailureContent, err)
|
||||
}
|
||||
|
@ -116,13 +113,10 @@ func Disable(ctx *macaron.Context) string {
|
|||
|
||||
// 改变任务状态
|
||||
func changeStatus(ctx *macaron.Context, status models.Status) string {
|
||||
id, err := strconv.Atoi(ctx.Params(":id"))
|
||||
id := ctx.ParamsInt(":id")
|
||||
json := utils.JsonResponse{}
|
||||
if err != nil {
|
||||
return json.CommonFailure("参数错误", err)
|
||||
}
|
||||
taskModel := new(models.Task)
|
||||
_, err = taskModel.Update(id, models.CommonMap{
|
||||
_, err := taskModel.Update(id, models.CommonMap{
|
||||
"Status": status,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue