Skip to content

Instantly share code, notes, and snippets.

@jpfuentes2
Created April 16, 2014 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpfuentes2/10938858 to your computer and use it in GitHub Desktop.
Save jpfuentes2/10938858 to your computer and use it in GitHub Desktop.
(invoke! [this test op]
(try+
(case (:f op)
:read (try (let [value (json/parse-string (:body (consul-get client)) true)
seriousValue (-> (first value)
:Value
base64/decode
Integer.)
index (-> (first value) :Index)]
(assoc op :type :ok :value seriousValue :index index))
(catch Exception e
(warn e "Read failed")
; Since reads don't have side effects, we can always
; pretend they didn't happen.
(assoc op :type :fail)))
:write (do (->> (:value op)
json/generate-string
(consul-put client))
(assoc op :type :ok))
:cas (let [[value value'] (:value op)
index (:index op)
ok? (consul-cas client index
(json/generate-string value)
(json/generate-string value'))]
(assoc op :type (if ok? :ok :fail))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment