Skip to content

Instantly share code, notes, and snippets.

@soheilhy
Created July 22, 2015 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soheilhy/2be5c2e2593fb7f17d51 to your computer and use it in GitHub Desktop.
Save soheilhy/2be5c2e2593fb7f17d51 to your computer and use it in GitHub Desktop.
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