Skip to content

Commit 4e41352

Browse files
author
awb99
committed
system logs ordered component key start order
1 parent 6f047a3 commit 4e41352

File tree

6 files changed

+71
-45
lines changed

6 files changed

+71
-45
lines changed

demo/src/demo/super.clj

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
(ns demo.super)
22

33
(println "demo.isuper !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
4+
5+
6+
(def ^:dynamic secret 42)
7+

demo/src/demo/system.clj

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
(ns demo.system
2+
(:require
3+
[juxt.clip.core :as clip]
4+
[demo.super]
5+
[modular.system]
6+
))
7+
8+
(-> 'demo.super/secret requiring-resolve)
9+
10+
(-> 'demo.super/secret requiring-resolve deref)
11+
12+
(defn lookup [s]
13+
(when-let [v (requiring-resolve s)]
14+
(when (var? v)
15+
(deref v))))
16+
17+
(+ 1000000
18+
(lookup 'demo.super/secret)
19+
)
20+
21+
(binding [demo.super/secret 8]
22+
(+ 1000000
23+
(lookup 'demo.super/secret))
24+
)
25+
26+
(def system-config
27+
{:components
28+
{:c {:start '(concat (clip/ref :b) [:c])}
29+
:a {:start {:a 1}}
30+
:b {:start [(clip/ref :a) :b]}
31+
}})
32+
33+
34+
35+
(clip/orderby-start system-config)
36+
37+
(clip/start system-config)
38+
39+
(modular.system/start-system system-config)

src/modular/config.clj

+1-22
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,24 @@
11
(ns modular.config
22
(:require
3-
[taoensso.timbre :refer [debug info warn error]]
43
[modular.config.cprop :refer [load-config-cprop]]
5-
[modular.config.watch :refer [watch-config!]]
6-
[modular.require :refer [resolve-symbol]]
74
[modular.writer :refer [write-edn-private]]))
85

96
(defonce config-atom (atom {}))
107

11-
(defmacro get-in-config-cljs [path]
12-
(get-in @config-atom path))
13-
148
(defn get-in-config [path]
159
(get-in @config-atom path))
1610

17-
;(swap! a assoc :comparator comparator)
18-
19-
;; RESOLVE
20-
21-
(defn resolve-config-key [_ path]
22-
(if-let [s (get-in-config path)]
23-
(if-let [r (resolve-symbol s)]
24-
(swap! config-atom assoc-in path r)
25-
(error "resolve-error: resolve failed in path: " path))
26-
(error "resolve-error: path path not found: " path)))
27-
2811
(defn load-config!
2912
[app-config]
3013
(let [config (load-config-cprop app-config)]
3114
(reset! config-atom config)
32-
(write-edn-private "config" @config-atom)
33-
(watch-config! config-atom)))
15+
(write-edn-private "config" @config-atom)))
3416

3517
(defn add-config [app-config user-config]
3618
(let [app-config (if (vector? app-config) app-config [app-config])
3719
user-config (if (vector? user-config) user-config [user-config])]
3820
(into [] (concat app-config user-config))))
3921

40-
#_(defn get-in [path]
41-
(get-in @config-atom path))
42-
4322
(defn set!
4423
"The config normally gets configured at an application level:
4524
On app start the config(s) get loaded.

src/modular/config/watch.clj

-18
This file was deleted.

src/modular/system.clj

+25-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
(System/exit 0)
2828
;(stop-system {:running-system running-system :system-config system-config})
2929
)
30+
3031
(defn log-uncaught-exceptions []
3132
(Thread/setDefaultUncaughtExceptionHandler
3233
(reify Thread$UncaughtExceptionHandler
@@ -45,8 +46,29 @@
4546

4647
(def system nil)
4748

49+
;; since safely-derive-parts is a private var, we need to extend clip with in-ns
50+
51+
(in-ns 'juxt.clip.core)
52+
53+
(defn orderby-start
54+
([system-config]
55+
(orderby-start system-config (keys (:components system-config))))
56+
([system-config component-ks]
57+
(let [{:keys [components]} system-config
58+
[_ component-chain] (safely-derive-parts components [] component-ks)
59+
component-ks-sorted (map first component-chain)]
60+
component-ks-sorted)))
61+
62+
(in-ns 'modular.system)
63+
64+
(require '[juxt.clip.core :refer [orderby-start]])
65+
66+
(defn orderby-edn [system-config]
67+
(-> system-config :components keys))
68+
4869
(defn start-system [system-config]
49-
(info "starting clip services: " (-> system-config :components keys))
70+
;(info "starting clip services (edn order): " (orderby-edn system-config))
71+
(info "starting clip services (start order): " (orderby-start system-config))
5072
(let [running-system (clip/start system-config)
5173
on-stop (fn []
5274
(stop-system {:system-config system-config
@@ -70,6 +92,7 @@
7092
(read-config aero-opts))) ; opts: :profile :user :resolve
7193

7294
(defn start!
95+
"starts a clip system "
7396
[{:keys [services config profile run]
7497
:or {profile :default}
7598
:as arguments}]
@@ -80,7 +103,7 @@
80103
{:keys [running-system]} (start-system system-config)]
81104
(if run ;(seq arguments)
82105
(run-fn run arguments system-config running-system) ;; application run from the command line with arguments.
83-
@(promise) ;; application run from the command line, no arguments, keep webserver running.
106+
@(promise) ;; application run from the command line, no arguments, keep running.
84107
)))
85108

86109
;; CLI ENTRYPOINT

src/modular/writer.clj

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
(ns modular.writer
22
(:require
33
[clojure.java.io :as io]
4-
[fipp.clojure]
5-
[modular.date :refer [now-str]]))
4+
[fipp.clojure]))
65

76
; fast, but no pretty-print (makes it difficult to detect bugs)
87

98
#_(defn write [filename data]
109
(spit filename (pr-str data)))
1110

1211
(defn write [filename data]
13-
(let [comment (str "; generated by modular on " (now-str) "\r\n")
12+
(let [comment "; auto-generated \r\n"
1413
s (with-out-str
1514
(fipp.clojure/pprint data {:width 60}))
1615
s (str comment s)]

0 commit comments

Comments
 (0)