Created
November 20, 2016 16:22
-
-
Save firthh/200b74738339ae9dfbcbc388ba2e5d50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn m-error-handling [f] | |
(fn [& args] | |
(try | |
(let [res (apply f args)] | |
(if res | |
(right res) | |
(left {:message (str "nil returned calling " f " with " args)}))) | |
(catch Exception e | |
(left {:exception e :message (str "Exception thrown calling " f " with " args)}))))) | |
(defn transform [click] | |
(let [m-fs (->> [:data | |
transform-1 | |
transform-2 | |
transform-3 | |
transform-4 | |
transform-5 | |
transform-6 | |
transform-7] | |
(map util/m-error-handling))] | |
(m/foldm (fn [current-val m-f] (m-f current-val)) click m-fs))) | |
(defn process-errors! [m-v] | |
(if (left? m-v) | |
(let [{:keys [exception message]} @m-v] | |
(when exception (airbrake/notify config/airbrake exception)) | |
(log/error message)) | |
@m-v)) | |
(defn process-clicks-messages [db-connection objs] | |
(->> objs | |
(map transform) | |
(map process-errors!) | |
(remove nil?) | |
(run! (partial db/save-objects! db-connection)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment