Created
November 20, 2016 15:45
-
-
Save firthh/e7162be0c8555c14c2635cff9af18669 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 with-error-handling [f] | |
(fn [& args] | |
(try | |
(let [res (apply f args)] | |
(if-not res | |
(log/error (str "Had nil returned calling " f " with " args))) | |
res) | |
(catch Exception e | |
(log/error e "An exception was thrown processing: " args) | |
(airbrake/notify config/airbrake e) | |
nil)))) | |
(defn our-comp | |
"Same as `clojure.core/comp` except that the functions will shortcircuit on nil. | |
((comp inc inc) 1) => 3 | |
((comp inc inc) nil) => nil" | |
[& fs] | |
(fn comp-fn | |
([i] (comp-fn i fs)) | |
([i [f & more]] | |
(cond (nil? i) nil | |
(nil? f) i | |
:else (recur (f i) more))))) | |
(def transform | |
(->> [:data | |
transform-1 | |
transform-2 | |
transform-3 | |
transform-4 | |
transform-5 | |
transform-6 | |
transform-7] | |
(map with-error-handling) | |
(apply new-comp)) | |
(defn process-clicks-messages [db-connection objs] | |
(->> objs | |
(map transform) | |
(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