Added error handling to agents.
This commit is contained in:
parent
2f34c6c39a
commit
8a0063040f
|
@ -1,10 +1,10 @@
|
|||
(defproject net.thegeez/clj-browserchannel-jetty-adapter "0.0.3"
|
||||
(defproject net.thegeez/clj-browserchannel-jetty-adapter "0.0.4"
|
||||
:description "Jetty async adapter for BrowserChannel"
|
||||
:url ""
|
||||
:dependencies [[ring/ring-core "1.3.1"]
|
||||
[ring/ring-servlet "1.3.1"]
|
||||
[org.eclipse.jetty/jetty-server "8.1.16.v20140903"];; includes ssl
|
||||
[net.thegeez/clj-browserchannel-server "0.0.7"]]
|
||||
[net.thegeez/clj-browserchannel-server "0.0.8"]]
|
||||
:profiles {:provided
|
||||
{:dependencies
|
||||
[[org.clojure/clojure "1.6.0"]]}})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(defproject net.thegeez/clj-browserchannel-server "0.0.7"
|
||||
(defproject net.thegeez/clj-browserchannel-server "0.0.8"
|
||||
:description "BrowserChannel server implementation in Clojure"
|
||||
:dependencies [[ring/ring-core "1.3.1"]
|
||||
[org.clojure/data.json "0.2.5"]]
|
||||
|
|
|
@ -128,6 +128,14 @@
|
|||
(defn error-response [status-code message]
|
||||
{:status status-code
|
||||
:body (str "<html><body><h1>" message "</h1></body></html>")})
|
||||
|
||||
(defn agent-error-handler-fn
|
||||
"Prints the error and tries to restart the agent."
|
||||
[id]
|
||||
(fn [ag ^Exception e]
|
||||
(println "ERROR:" id "agent threw" e (.getMessage e))
|
||||
(restart-agent ag @ag)))
|
||||
|
||||
;;;;;; end of utils
|
||||
|
||||
;;;; listeners
|
||||
|
@ -136,6 +144,8 @@
|
|||
;; sessionId -> :event -> [call back]
|
||||
;; event: :map | :close
|
||||
(def listeners-agent (agent {}))
|
||||
(set-error-handler! listeners-agent (agent-error-handler-fn "listener"))
|
||||
|
||||
|
||||
(defn add-listener [session-id event-key f]
|
||||
(send-off listeners-agent
|
||||
|
@ -506,6 +516,7 @@
|
|||
;; when the client never connects with a backchannel
|
||||
refresh-session-timeout)
|
||||
session-agent (agent session)]
|
||||
(set-error-handler! session-agent (agent-error-handler-fn (str "session-" (:id session))))
|
||||
(swap! sessions assoc id session-agent)
|
||||
(when-let [notify (:on-session options)]
|
||||
(notify id req))
|
||||
|
|
Reference in a new issue