Created
July 22, 2015 00:56
-
-
Save soheilhy/2be5c2e2593fb7f17d51 to your computer and use it in GitHub Desktop.
AckHTTPHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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