Exemple #1
0
func (c Tasks) TaskOperate(id string, task models.Task) revel.Result {
	group := models.SelectTaskGroupListByUserId(c.SessionGetUser().UserId)
	if c.IsGet() {
		if id != "" {
			if task = models.SelectTaskOneById(id); task.TaskId == "" {
				return c.ErrDataBase(MsgSeleteError)
			}
			return c.Render(task, group)
		}
		return c.Render(group)
	} else {
		if task.TaskId != "" {
			task.ValidateUpdate(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(task, group)
			}
			if !models.UpdateTaskOne(&task) {
				return c.ErrDataBase(MsgUpdateError)
			}
		} else {
			task.UserId = c.SessionGetUser().UserId
			task.ValidateInsert(c.Validation)
			if c.Validation.HasErrors() {
				return c.Render(task, group)
			}
			if err := models.DBMap().Insert(&task); err != nil {
				return c.ErrDataBase(MsgInsertError)
			}
		}
		return c.Redirect(routes.Tasks.TaskList(task.GroupId))
	}
}
Exemple #2
0
// 查看log
func (c Tasks) TaskLog(id string) revel.Result {
	taskLog := models.SelectTaskLogOneBy(id)
	if taskLog.TaskLogId == "" {
		return c.ErrDataBase(MsgSeleteError)
	}

	task := models.SelectTaskOneById(taskLog.TaskId)
	if task.TaskId == "" {
		return c.ErrDataBase(MsgSeleteError)
	}

	return c.Render(taskLog, task)
}
Exemple #3
0
// 关闭任务
func (c Tasks) TaskStop(id string) revel.Result {
	task := models.SelectTaskOneById(id)

	if task.TaskId == "" {
		return c.ErrDataBase(MsgSeleteError)
	}

	if jobs.RemoveJob(task.TaskId) {
		revel.INFO.Println("关闭job成功")
		task.Status = 0
		models.UpdateTaskOne(&task)
	}
	return c.Redirect(routes.Tasks.TaskList(""))
}
Exemple #4
0
// 启动任务
func (c Tasks) TaskStart(id string) revel.Result {
	task := models.SelectTaskOneById(id)

	if task.TaskId == "" {
		return c.ErrDataBase(MsgSeleteError)
	}

	job, err := jobs.NewJobFromTask(&task)
	if err != nil {
		return c.ErrInputData("加入任务队列失败")
	}
	if jobs.AddJob(task.CronSpec, job) {
		revel.INFO.Println("加入job成功")
		task.Status = 1
		models.UpdateTaskOne(&task)
	}
	return c.Redirect(routes.Tasks.TaskList(""))
}