func listJobs(jm job.JobManager, r *http.Request, w http.ResponseWriter) { jobs, err := jm.ListAll() if err != nil { handleErr(err, w) return } json.NewEncoder(w).Encode(jobs) }
func getJob(jm job.JobManager, r *http.Request, w http.ResponseWriter) { jobID := mux.Vars(r)["jobid"] j, err := jm.GetByID(jobID) if err != nil { handleErr(err, w) return } json.NewEncoder(w).Encode(j) }
func deleteJob(jm job.JobManager, r *http.Request, w http.ResponseWriter) { jobID := mux.Vars(r)["jobid"] j, err := jm.GetByID(jobID) if err != nil { handleErr(err, w) return } err = jm.Delete(j) if err != nil { handleErr(err, w) return } w.WriteHeader(http.StatusNoContent) }
func getJobLog(jm job.JobManager, r *http.Request, w http.ResponseWriter) { jobID := mux.Vars(r)["jobid"] indexQuery := querystringValue(r, "index") index, err := strconv.Atoi(indexQuery) if err != nil { index = 0 } j, err := jm.GetByID(jobID) if err != nil { handleErr(err, w) return } log, err := jm.GetLog(j, index) if err != nil { handleErr(err, w) return } json.NewEncoder(w).Encode(log) }
func createJob(jm job.JobManager, r *http.Request, w http.ResponseWriter) { j := &job.Job{} err := json.NewDecoder(r.Body).Decode(j) if err != nil { handleErr(err, w) return } err = jm.Create(j) if err != nil { handleErr(err, w) return } go func() { if err := jm.Execute(j); err != nil { log.Error(err) } }() w.WriteHeader(http.StatusCreated) json.NewEncoder(w).Encode(j) }