Created
July 22, 2015 00:55
-
-
Save soheilhy/b240ecfdce800a538a17 to your computer and use it in GitHub Desktop.
DeQHTTPHandler
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
// 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