Example #1
0
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)
}
Example #2
0
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)
}
Example #3
0
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)
}
Example #4
0
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)
}
Example #5
0
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)
}