예제 #1
0
func AddTriggerToJob(w http.ResponseWriter, r *http.Request) {
	jobList := models.GetJobList()

	vars := mux.Vars(r)
	job, err := jobList.Get(vars["job"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}
	j := job.(models.Job)

	payload := unmarshal(r.Body, "trigger", w)

	j.AppendTrigger(payload["trigger"])
	triggerList := models.GetTriggerList()
	t, err := triggerList.Get(payload["trigger"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	executor.AddTrigger(t.(models.Trigger))
	jobList.Update(j)

	w.WriteHeader(201)
}
예제 #2
0
func DeleteTrigger(w http.ResponseWriter, r *http.Request) {
	triggerList := models.GetTriggerList()

	vars := mux.Vars(r)

	triggerList.Delete(vars["trigger"])
}
예제 #3
0
func AddTrigger(w http.ResponseWriter, r *http.Request) {
	triggerList := models.GetTriggerList()

	payload := unmarshal(r.Body, "name", w)

	trigger := models.Trigger{Name: payload["name"]}
	triggerList.Append(trigger)
	w.WriteHeader(201)
}
예제 #4
0
func GetTrigger(w http.ResponseWriter, r *http.Request) {
	triggerList := models.GetTriggerList()

	vars := mux.Vars(r)
	trigger, err := triggerList.Get(vars["trigger"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	marshal(trigger, w)
}
예제 #5
0
func UpdateTrigger(w http.ResponseWriter, r *http.Request) {
	triggerList := models.GetTriggerList()

	vars := mux.Vars(r)
	trigger, err := triggerList.Get(vars["trigger"])
	if err != nil {
		http.Error(w, err.Error(), http.StatusNotFound)
		return
	}

	payload := unmarshal(r.Body, "cron", w)

	t := trigger.(models.Trigger)
	t.Schedule = payload["cron"]
	executor.AddTrigger(t)
	err = triggerList.Update(t)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}
예제 #6
0
func ListTriggers(w http.ResponseWriter, r *http.Request) {
	triggerList := models.GetTriggerList()

	w.Header().Set("Content-Type", "application/json")
	w.Write([]byte(triggerList.Json()))
}