// 编辑任务 func (this *TaskController) Edit() { id, _ := this.GetInt("id") task, err := models.TaskGetById(id) if err != nil { this.showMsg(err.Error()) } if this.isPost() { task.TaskName = strings.TrimSpace(this.GetString("task_name")) task.Description = strings.TrimSpace(this.GetString("description")) task.GroupId, _ = this.GetInt("group_id") task.Concurrent, _ = this.GetInt("concurrent") task.CronSpec = strings.TrimSpace(this.GetString("cron_spec")) task.Command = strings.TrimSpace(this.GetString("command")) task.Notify, _ = this.GetInt("notify") task.Timeout, _ = this.GetInt("timeout") notifyEmail := strings.TrimSpace(this.GetString("notify_email")) if notifyEmail != "" { tmp := strings.Split(notifyEmail, "\n") emailList := make([]string, 0, len(tmp)) for _, v := range tmp { v = strings.TrimSpace(v) if !libs.IsEmail([]byte(v)) { this.ajaxMsg("无效的Email地址:"+v, MSG_ERR) } else { emailList = append(emailList, v) } } task.NotifyEmail = strings.Join(emailList, "\n") } if task.TaskName == "" || task.CronSpec == "" || task.Command == "" { this.ajaxMsg("请填写完整信息", MSG_ERR) } if _, err := libcron.Parse(task.CronSpec); err != nil { this.ajaxMsg("cron表达式无效", MSG_ERR) } if err := task.Update(); err != nil { this.ajaxMsg(err.Error(), MSG_ERR) } this.ajaxMsg("", MSG_OK) } // 分组列表 groups, _ := models.TaskGroupGetList(1, 100) this.Data["groups"] = groups this.Data["task"] = task this.Data["pageTitle"] = "编辑任务" this.display() }
// 任务列表 func (this *TaskController) List() { page, _ := this.GetInt("page") if page < 1 { page = 1 } groupId, _ := this.GetInt("groupid") filters := make([]interface{}, 0) if groupId > 0 { filters = append(filters, "group_id", groupId) } result, count := models.TaskGetList(page, this.pageSize, filters...) list := make([]map[string]interface{}, len(result)) for k, v := range result { row := make(map[string]interface{}) row["id"] = v.Id row["name"] = v.TaskName row["cron_spec"] = v.CronSpec row["status"] = v.Status row["description"] = v.Description e := jobs.GetEntryById(v.Id) if e != nil { row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s") row["prev_time"] = "-" if e.Prev.Unix() > 0 { row["prev_time"] = beego.Date(e.Prev, "Y-m-d H:i:s") } else if v.PrevTime > 0 { row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s") } row["running"] = 1 } else { row["next_time"] = "-" if v.PrevTime > 0 { row["prev_time"] = beego.Date(time.Unix(v.PrevTime, 0), "Y-m-d H:i:s") } else { row["prev_time"] = "-" } row["running"] = 0 } list[k] = row } // 分组列表 groups, _ := models.TaskGroupGetList(1, 100) this.Data["pageTitle"] = "任务列表" this.Data["list"] = list this.Data["groups"] = groups this.Data["groupid"] = groupId this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("TaskController.List", "groupid", groupId), true).ToString() this.display() }
func (this *GroupController) List() { page, _ := this.GetInt("page") if page < 1 { page = 1 } list, count := models.TaskGroupGetList(page, this.pageSize) this.Data["pageTitle"] = "分组列表" this.Data["list"] = list this.Data["pageBar"] = libs.NewPager(page, int(count), this.pageSize, beego.URLFor("GroupController.List"), true).ToString() this.display() }