Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
AckHTTPHandler
// AckHTTPHandler provides the HTTP endpoint for acknowledging tasks.
type AckHTTPHandler httpHandler
func (h *AckHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
q, ok := vars["queue"]
if !ok {
http.Error(w, "unkown queue", http.StatusBadRequest)
return
}
t, ok := vars["id"]
if !ok {
http.Error(w, "unkown task", http.StatusBadRequest)
return
}
i, err := strconv.ParseInt(t, 10, 64)
if err != nil {
http.Error(w, fmt.Sprintf("invalid task id: %v", err),
http.StatusBadRequest)
return
}
ctx, cnl := context.WithTimeout(context.Background(), httpTimeout)
defer cnl()
a := Ack{
ID: uint64(i),
Queue: Queue(q),
}
if _, err := h.Hive.Sync(ctx, a); 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.