Skip to content

Instantly share code, notes, and snippets.

@soheilhy soheilhy/queue.go
Created Jul 22, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.