Skip to content

Commit

Permalink
agent: switch to env-config
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Oct 29, 2016
1 parent 1eb5fec commit dd96ff8
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/agent/dirac/agent/config.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
(ns dirac.agent.config
(:require [dirac.lib.utils :refer [assoc-env-val deep-merge-ignoring-nils]]))
(:require [dirac.lib.utils :refer [deep-merge-ignoring-nils read-env-config]]))

(def env-config-prefix "dirac-agent")

; you can override individual config keys via ENV variables, for example:
; DIRAC_AGENT/LOG_LEVEL=debug or DIRAC_AGENT/NREPL_SERVER/PORT=7777
;
; see https://github.com/binaryage/env-config
(def default-config
{:log-level "WARN" ; OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL
:max-boot-trials 10
Expand All @@ -12,25 +18,10 @@
:nrepl-tunnel {:host "localhost"
:port 8231}})

; -- environment ------------------------------------------------------------------------------------------------------------

(defn get-environ-config []
(-> {}
(assoc-env-val [:log-level] :dirac-agent-log-level)
(assoc-env-val [:log-out] :dirac-agent-log-out)
(assoc-env-val [:skip-logging-setup] :dirac-agent-skip-logging-setup :bool)
(assoc-env-val [:max-boot-trials] :dirac-agent-max-boot-trials :int)
(assoc-env-val [:initial-boot-delay] :dirac-agent-initial-boot-delay :int)
(assoc-env-val [:delay-between-boot-trials] :dirac-agent-delay-between-boot-trials :int)
(assoc-env-val [:nrepl-server :host] :dirac-nrepl-server-host)
(assoc-env-val [:nrepl-server :port] :dirac-nrepl-server-port :int)
(assoc-env-val [:nrepl-tunnel :host] :dirac-agent-host)
(assoc-env-val [:nrepl-tunnel :port] :dirac-agent-port :int)))

; -- config evaluation ------------------------------------------------------------------------------------------------------

(defn get-effective-config* [& [config]]
(let [environ-config (get-environ-config)]
(or (deep-merge-ignoring-nils default-config environ-config config) {})))
(let [env-config (read-env-config env-config-prefix)]
(deep-merge-ignoring-nils default-config env-config config)))

(def ^:dynamic get-effective-config (memoize get-effective-config*)) ; assuming environ-config is constant
(def ^:dynamic get-effective-config (memoize get-effective-config*)) ; assuming env-config is constant

0 comments on commit dd96ff8

Please sign in to comment.