Skip to content

Commit 6d4cc86

Browse files
committed
Merge pull request #7 from mtkp/add-hook-docstring
misc cleanup
2 parents c05e5fe + 6ef35cd commit 6d4cc86

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Whenever you make an http request, add one or more of the hystrix-clj options to
2424
:hystrix/breaker-request-volume 20
2525
:hystrix/breaker-error-percent 50
2626
:hystrix/breaker-sleep-window-ms 5000
27-
:hystrix/bad-request-pred client-error?}}
27+
:hystrix/bad-request-pred client-error?}}
2828
```
2929
Any values not supplied will be set to their default values as above. Requests with no Hystrix-related keys won't use Hystrix.
3030

src/clj_http_hystrix/core.clj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
:hystrix/threads
2121
:hystrix/queue-size
2222
:hystrix/timeout-ms
23+
:hystrix/breaker-request-volume
24+
:hystrix/breaker-error-percent
25+
:hystrix/breaker-sleep-window-ms
2326
:hystrix/bad-request-pred})
2427

2528
(defn default-fallback [req resp]
@@ -63,10 +66,10 @@
6366
(.withCoreSize threads)
6467
(.withMaxQueueSize (:hystrix/queue-size config 5))
6568
(.withQueueSizeRejectionThreshold (:hystrix/queue-size config 5)))]
66-
(-> (HystrixCommand$Setter/withGroupKey (group-key group))
67-
(.andCommandKey (command-key (:hystrix/command-key config :default)))
68-
(.andCommandPropertiesDefaults command-configurator)
69-
(.andThreadPoolPropertiesDefaults thread-pool-configurator))))
69+
(doto (HystrixCommand$Setter/withGroupKey (group-key group))
70+
(.andCommandKey (command-key (:hystrix/command-key config :default)))
71+
(.andCommandPropertiesDefaults command-configurator)
72+
(.andThreadPoolPropertiesDefaults thread-pool-configurator))))
7073

7174
(defn ^:private log-error [command-name ^HystrixCommand context]
7275
(let [message (format "Failed to complete %s %s" command-name (.getExecutionEvents context))]
@@ -101,7 +104,7 @@
101104
:message "Bad request pred"
102105
:stack-trace (stack-trace)})))
103106
resp))
104-
wrap-exception-reponse (fn [resp] ((http/wrap-exceptions (constantly resp)) (assoc req :throw-exceptions true)))
107+
wrap-exception-response (fn [resp] ((http/wrap-exceptions (constantly resp)) (assoc req :throw-exceptions true)))
105108
^HystrixCommand$Setter configurator (configurator req)
106109
logging-context (or (MDC/getCopyOfContextMap) {})
107110
command (proxy [HystrixCommand] [configurator]
@@ -117,12 +120,13 @@
117120
(assoc :throw-exceptions false)
118121
f
119122
wrap-bad-request
120-
wrap-exception-reponse)))]
123+
wrap-exception-response)))]
121124
(handle-exception #(.execute command) req))
122125
(f req)))
123126

124-
(defn add-hook []
127+
(defn add-hook
125128
"Activate clj-http-hystrix to wrap all clj-http client requests as
126129
hystrix commands."
127-
(when (not (some-> (meta http/request) :robert.hooke/hooks deref (contains? #'wrap-hystrix)))
130+
[]
131+
(when-not (some-> (meta http/request) :robert.hooke/hooks deref (contains? #'wrap-hystrix))
128132
(hooke/add-hook #'http/request #'wrap-hystrix)))

0 commit comments

Comments
 (0)