func DeleteTask(w http.ResponseWriter, r *http.Request) { taskList := models.GetTaskList() vars := mux.Vars(r) task, err := taskList.Get(vars["task"]) if err != nil { http.Error(w, err.Error(), http.StatusNotFound) return } taskList.Delete(task.ID()) }
func AddTask(w http.ResponseWriter, r *http.Request) { taskList := models.GetTaskList() payload := unmarshal(r.Body, "name", w) err := taskList.Append(models.Task{payload["name"], ""}) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) return } w.WriteHeader(201) }
func UpdateTask(w http.ResponseWriter, r *http.Request) { taskList := models.GetTaskList() vars := mux.Vars(r) task, err := taskList.Get(vars["task"]) if err != nil { http.Error(w, err.Error(), http.StatusNotFound) return } payload := unmarshal(r.Body, "script", w) t := task.(models.Task) t.Script = payload["script"] taskList.Update(t) }
// Gathers the tasks attached to the given job and executes them. func runnit(j models.Job) { tasksList := models.GetTaskList() runsList := models.GetRunList() id, err := uuid.NewV4() if err != nil { panic(err) } var tasks []models.Task for _, taskName := range j.Tasks { task, err := tasksList.Get(taskName) if err != nil { panic(err) } t := task.(models.Task) tasks = append(tasks, t) } err = runsList.AddRun(id.String(), j, tasks) if err != nil { panic(err) } }
func AddRun(w http.ResponseWriter, r *http.Request) { runsList := models.GetRunList() jobsList := models.GetJobList() tasksList := models.GetTaskList() payload := unmarshal(r.Body, "job", w) job, err := jobsList.Get(payload["job"]) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } j := job.(models.Job) id, err := uuid.NewV4() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } var tasks []models.Task for _, taskName := range j.Tasks { task, err := tasksList.Get(taskName) if err != nil { panic(err) } t := task.(models.Task) tasks = append(tasks, t) } err = runsList.AddRun(id.String(), j, tasks) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } idResponse := make(map[string]string) idResponse["uuid"] = id.String() w.WriteHeader(201) marshal(idResponse, w) }
func ListTasks(w http.ResponseWriter, r *http.Request) { taskList := models.GetTaskList() w.Header().Set("Content-Type", "application/json") w.Write([]byte(taskList.Json())) }