clojusc / meson

Clojure Client Library for the Mesos HTTP API
Apache License 2.0
9 stars 10 forks source link

Provide Default Handler for Scheduler Events #8

Closed oubiwann closed 8 years ago

oubiwann commented 8 years ago

Tasks:

oubiwann commented 8 years ago

So far:

(defmulti handle-msg
  ""
  (comp :type last vector))

(defmethod handle-msg :subscribed
  [state msg]
  (log/debug "Got SUBSCRIBED message.")
  (log/trace msg))

(defmethod handle-msg :heartbeat
  [state msg]
  (log/debug "Got HEARTBEAT message.")
  (log/trace msg))

(defmethod handle-msg :offers
  [state msg]
  (log/debug "Got OFFERS message.")
  (log/trace msg))

(defmethod handle-msg :default
  [state msg]
  (log/error "Unknown type ...")
  (log/trace msg))

These will be called (at least initially) in the following manner:

(defn read-stream [ch stream]
  (async/go-loop []
    (async/put! ch (recordio/next! stream :json))
    (recur)))

(def response (master/subscribe c framework-info))
(def stream (:body response))
(def ch (async/chan))

(async/reduce handle-msg {:client c :stream stream :channel ch} ch)
(read-stream ch stream)

As such, it might make sense to:

(async/reduce handlers/default {:client c :stream stream :channel ch} ch)