Skip to content

Instantly share code, notes, and snippets.

@soheilhy soheilhy/queue.go
Last active Aug 29, 2015

What would you like to do?
type httpHandler struct {
Hive beehive.Hive // Hive represents the hive our handler is registered on.
// EnQHTTPHandler provides the HTTP endpoint for enqueuing tasks.
type EnQHTTPHandler httpHandler
func (h *EnQHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
q, ok := mux.Vars(r)["queue"]
if !ok {
http.Error(w, "unkown queue", http.StatusBadRequest)
b, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, "cannot read request body", http.StatusBadRequest)
e := Enque{
Task: Task{
Queue: Queue(q),
Body: b,
ctx, cnl := context.WithTimeout(context.Background(), httpTimeout)
defer cnl()
if _, err := h.Hive.Sync(ctx, e); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
fmt.Fprintf(w, "task enqueued\n")
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.