Created
August 3, 2010 05:41
-
-
Save zahardzhan/505901 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
(defmacro defhook [name qualifier target args & body] | |
(let [key# (keyword name)] | |
`(add-hook ~qualifier ~target ~key# (fn ~args ~@body)))) | |
(defn run [{:as a :keys [strategy run-atom]}] | |
(when (run? a) (throw (Exception. "Cannot run agent while it is running."))) | |
(when (dead? a) (throw (Exception. "Cannot run dead agent."))) | |
(try (reset! run-atom true) | |
(let [action (strategy a)] | |
(action a)) | |
(finally (reset! run-atom false)))) | |
(defhook log :around #'run [run a] | |
(debug (str "Run " (download-agent-to-str a))) | |
(try (run a) | |
(catch Throwable t | |
(error (str "Fail " (download-agent-to-str a) ": " t)) | |
(throw t)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment