Skip to content

Commit

Permalink
Align clean-hard with rest of the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaspazza committed Jan 5, 2024
1 parent a083f45 commit 203fe56
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{:deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}
{:deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.72"}}
:paths []
:tasks {:requires [[automaton-build-app.tasks.launcher.bb-entrypoint :as build-task-bb-entrypoint] [babashka.process :as babahska-process]]
heph-task {:doc "Launch an Hephaistox task"
Expand Down
1 change: 1 addition & 0 deletions build_config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:mermaid-dir "docs/code/"
:publication {:as-lib org.clojars.hephaistox/automaton-core
:branch "main"
:deploy-to :clojars
:jar-path "target/prod/automaton-core.jar"
:major-version "0.0.%d"
:pom-path "target/prod/class/META-INF/maven/org.clojars.hephaistox/automaton-core/pom.xml"
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:aliases {:bb-deps {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}}
:build {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.70"}}}
{:aliases {:bb-deps {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.72"}}}
:build {:extra-deps {org.clojars.hephaistox/automaton-build-app {:mvn/version "0.0.72"}}}
:cljs-deps {:extra-deps {binaryage/devtools {:mvn/version "1.0.7"}
cider/cider-nrepl {:mvn/version "0.30.0"}
thheller/shadow-cljs {:mvn/version "2.26.2"}}
Expand Down
6 changes: 3 additions & 3 deletions src/clj/automaton_core/storage/component.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

(defn start-storage
[]
(try (core-log/info "Starting storage component")
(try (core-log/info "Start storage component")
(let [dc (datomic/make-datomic-client datomic-schema/all-schema)
db-uri (or (conf/read-param [:storage :datomic :url]) (conf/read-param [:storage-datomic-url]))
db-uri (conf/read-param [:storage :datomic :url])
_db-uri-valid? (when-not db-uri (throw (ex-info "Database uri was not found." {})))
conn (storage/connection dc db-uri)
access (datomic/make-datomic-access)]
Expand All @@ -20,7 +20,7 @@
:access access})
(catch Throwable e (core-log/fatal (ex-info "Storage component failed." {:error e})))))

(defstate storage-state :start (start-storage) :stop (.release storage-state))
(defstate storage-state :start (start-storage) :stop (.release (:connection @storage-state)))

(defn upsert [storage update-fn] (core-log/trace "Executed: " update-fn) (storage/upsert (:access storage) (:connection storage) update-fn))

Expand Down
29 changes: 15 additions & 14 deletions src/cljc/automaton_core/configuration/simple_files.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Just like in core configuration, we are not using log nor outside dependencies to comply with the configuration requirements."
(:require #?@(:clj [[clojure.edn :as edn] [clojure.java.io :as io] [automaton-core.adapters.java-properties :as java-properties]]
:cljs [[cljs.reader :as edn] [goog.object :as obj]])
[automaton-core.utils.map :as utils-map]
[automaton-core.configuration.protocol :as core-conf-prot]
[automaton-core.utils.keyword :as utils-keyword]))
[automaton-core.utils.keyword :as utils-keyword]
[automaton-core.utils.map :as utils-map]
[clojure.string :as str]))

#?(:cljs (def ^:private nodejs? (exists? js/require)))

Expand All @@ -23,10 +24,8 @@
_
v)))

(defn str->value
"ENV vars and system properties are strings. str->value will convert:
the numbers to longs, the alphanumeric values to strings, and will use Clojure reader for the rest
in case reader can't read OR it reads a symbol, the value will be returned as is (a string)"
(defn parse-system-env
"Turns string type into number. In case of failure in parsing it's returned in a format sa it was (a string)."
[v]
(cond (re-matches #"[0-9]+" v) (parse-number v)
(re-matches #"^(true|false)$" v) #?(:clj (Boolean/parseBoolean v)
Expand All @@ -39,10 +38,11 @@
v))))

(defn read-system-env
"Reads system env properties and converts to appropriate type."
[]
(->> #?(:clj (System/getenv)
:cljs (zipmap (obj/getKeys (.-env process)) (obj/getValues (.-env process))))
(map (fn [[k v]] [(utils-keyword/keywordize k) (str->value v)]))
(map (fn [[k v]] [(utils-keyword/keywordize k) (parse-system-env v)]))
(into {})))

(defn slurp-file
Expand Down Expand Up @@ -71,12 +71,8 @@

(defn- warn-on-overwrite
[ms]
(doseq [[k kvs] (group-by key (apply concat ms))
:let [vs (map val kvs)]
:when (and (next kvs) (not= (first vs) (last vs)))]
(println "WARNING: configuration keys are duplicated"
{:k k
:vs vs})))
(let [kseq (reduce (fn [acc m] (concat acc (keys m))) [] ms)]
(for [[id freq] (frequencies kseq) :when (> freq 1)] (println "WARNING: configuration keys are duplicated for:" id))))

(defn merge-configs [& m] (warn-on-overwrite m) (apply utils-map/deep-merge m))

Expand All @@ -95,7 +91,12 @@

(def ^{:doc "A map of configuration variables."} conf (memoize read-config))

(defn env-key-path
"Turns key-path into environment type key."
[key-path]
(let [path-str (str/join "-" (map name key-path))] (when-not (str/blank? path-str) (keyword path-str))))

(defrecord SimpleConf []
core-conf-prot/Conf
(read-conf-param [_this key-path] (get-in (conf) key-path))
(read-conf-param [_this key-path] (or (get-in (conf) key-path) (get (conf) (env-key-path key-path))))
(config [_this] (conf)))
4 changes: 2 additions & 2 deletions version.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;Last generated version, note a failed push consume a number
{:major-version "0.0.-1"
:minor-version 26
:version "0.0.26"}
:minor-version 55
:version "0.0.55"}

0 comments on commit 203fe56

Please sign in to comment.