func (s *Server) stopTask(w http.ResponseWriter, r *http.Request, p httprouter.Params) { id := p.ByName("id") errs := s.mt.StopTask(id) if errs != nil { if strings.Contains(errs[0].Error(), ErrTaskNotFound.Error()) { respond(404, rbody.FromSnapErrors(errs), w) return } respond(500, rbody.FromSnapErrors(errs), w) return } respond(200, &rbody.ScheduledTaskStopped{ID: id}, w) }
func (s *Server) startTask(w http.ResponseWriter, r *http.Request, p httprouter.Params) { id := p.ByName("id") errs := s.mt.StartTask(id) if errs != nil { if strings.Contains(errs[0].Error(), ErrTaskNotFound.Error()) { respond(404, rbody.FromSnapErrors(errs), w) return } if strings.Contains(errs[0].Error(), ErrTaskDisabledNotRunnable.Error()) { respond(409, rbody.FromSnapErrors(errs), w) return } respond(500, rbody.FromSnapErrors(errs), w) return } // TODO should return resource respond(200, &rbody.ScheduledTaskStarted{ID: id}, w) }