diff --git a/backend/src/uxbox/fixtures.clj b/backend/src/uxbox/fixtures.clj index d3c65dacc..9b0013a3e 100644 --- a/backend/src/uxbox/fixtures.clj +++ b/backend/src/uxbox/fixtures.clj @@ -67,7 +67,7 @@ returning id;") (def sql:create-icon-library - "insert into icon_library (team_id, name) + "insert into icon_library (team_id, name) values ($1, $2) returning id;") @@ -87,7 +87,7 @@ :num-draft-files-per-profile 10 :num-draft-pages-per-file 3}) -(defn rng-ids +(defn- rng-ids [rng n max] (let [stream (->> (.longs rng 0 max) (.iterator) @@ -99,19 +99,19 @@ #{} stream))) -(defn rng-vec +(defn- rng-vec [rng vdata n] (let [ids (rng-ids rng n (count vdata))] (mapv #(nth vdata %) ids))) -(defn rng-nth +(defn- rng-nth [rng vdata] (let [stream (->> (.longs rng 0 (count vdata)) (.iterator) (iterator-seq))] (nth vdata (first stream)))) -(defn collect +(defn- collect [f items] (reduce (fn [acc n] (p/then acc (fn [acc] @@ -121,7 +121,7 @@ (p/promise []) items)) -(defn run +(defn impl-run [opts] (let [rng (java.util.Random. 1) @@ -269,6 +269,17 @@ (assign-teams-and-profiles conn teams (map :id profiles)) (p/run! (partial create-draft-files conn) profiles))))) +(defn run + [preset] + (let [preset (if (map? preset) + preset + (case preset + (nil "small" :small) preset-small + ;; "medium" preset-medium + ;; "big" preset-big + preset-small))] + (deref (impl-run preset)))) + (defn -main [& args] (try @@ -277,12 +288,7 @@ #'uxbox.db/pool #'uxbox.migrations/migrations}) (mount/start)) - (let [preset (case (first args) - (nil "small") preset-small - ;; "medium" preset-medium - ;; "big" preset-big - preset-small)] - (log/info "Using preset:" (pr-str preset)) - (deref (run preset))) + + (run (first args)) (finally (mount/stop)))) diff --git a/backend/src/uxbox/media_loader.clj b/backend/src/uxbox/media_loader.clj index 0954adf8d..8f42844ac 100644 --- a/backend/src/uxbox/media_loader.clj +++ b/backend/src/uxbox/media_loader.clj @@ -310,8 +310,7 @@ (defn- read-file [path] - (let [path (validate-path path) - reader (java.io.PushbackReader. (io/reader path))] + (let [reader (java.io.PushbackReader. (io/reader path))] [(fs/parent path) (read reader)])) @@ -335,11 +334,16 @@ (p/run! #(process-colors-library conn %) colors) nil))) +(defn run + [path] + (p/let [[basedir data] (read-file path)] + (db/with-atomic [conn db/pool] + (importer conn basedir data)))) + (defn -main [& [path]] - (let [[basedir data] (read-file path)] + (let [path (validate-path path)] (start-system) - (-> (db/with-atomic [conn db/pool] - (importer conn basedir data)) - (p/finally (fn [_ _] - (stop-system)))))) + (-> (run path) + (p/finally (fn [_ _] (stop-system)))))) + diff --git a/docs/03-Backend-Developer-Guide.md b/docs/03-Backend-Developer-Guide.md index 2d3a9f8b9..55506a7e0 100644 --- a/docs/03-Backend-Developer-Guide.md +++ b/docs/03-Backend-Developer-Guide.md @@ -10,9 +10,8 @@ This is a development feature that allows populate the database with a good amount of random content (usually used for just test the application or perform performance tweaks on queries). - In order to load fixtures, enter to the REPL environment executing the -`bin/repl` script, and then execute `(uxbox.fixtures/-main)`. +`bin/repl` script, and then execute `(uxbox.fixtures/run :small)`. You also can execute this as a standalone script with: diff --git a/docs/05-Management-Guide.md b/docs/05-Management-Guide.md index ecd136f87..066111c3a 100644 --- a/docs/05-Management-Guide.md +++ b/docs/05-Management-Guide.md @@ -36,6 +36,18 @@ respective defaults): - `UXBOX_DEBUG_HUMANIZE_TRANSIT=true` +## REPL ## + +The production environment by default starts a server REPL where you +can connect and perform diagnosis operations. For this you will need +`netcat` or `telnet` installed in the server. + +```bash +$ rlwrap netcat localhost 5555 +user=> +``` + + ## Collections import ## This is the way we can preload default collections of images and icons to the @@ -64,3 +76,10 @@ Then, you need to execute: ```bash clojure -Adev -m uxbox.media-loader ../path/to/config.edn ``` + +If you have a REPL access to the running process, you can execute it from there: + +```clojure +(require 'uxbox.media-loader) +@(uxbox.media-loader/run "/path/to/config.edn") +```