Skip to content

Instantly share code, notes, and snippets.

@soheilhy
Created July 22, 2015 00:55
Show Gist options
  • Save soheilhy/b240ecfdce800a538a17 to your computer and use it in GitHub Desktop.
Save soheilhy/b240ecfdce800a538a17 to your computer and use it in GitHub Desktop.
DeQHTTPHandler
// DeQHTTPHandler provides the HTTP endpoint for dequeuing tasks.
type DeQHTTPHandler httpHandler
func (h *DeQHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
q, ok := mux.Vars(r)["queue"]
if !ok {
http.Error(w, "unkown queue", http.StatusBadRequest)
return
}
ctx, cnl := context.WithTimeout(context.Background(), httpTimeout)
defer cnl()
d := Deque{
Queue: Queue(q),
}
v, err := h.Hive.Sync(ctx, d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err = json.NewEncoder(w).Encode(v.(Task)); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment