2019-06-05 03:26:05 -05:00
|
|
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
;;
|
2022-09-20 16:23:22 -05:00
|
|
|
;; Copyright (c) KALEIDOS INC
|
2019-06-05 03:26:05 -05:00
|
|
|
|
|
|
|
(ns user
|
2019-11-18 05:52:57 -05:00
|
|
|
(:require
|
2022-02-07 06:00:26 -05:00
|
|
|
[app.common.data :as d]
|
2021-02-15 07:14:05 -05:00
|
|
|
[app.common.exceptions :as ex]
|
2023-05-19 12:37:53 -05:00
|
|
|
[app.common.fressian :as fres]
|
2022-01-12 14:23:25 -05:00
|
|
|
[app.common.geom.matrix :as gmt]
|
2022-09-28 16:26:31 -05:00
|
|
|
[app.common.logging :as l]
|
2022-01-12 14:23:25 -05:00
|
|
|
[app.common.perf :as perf]
|
2022-09-06 09:52:51 -05:00
|
|
|
[app.common.pprint :as pp]
|
2023-05-19 12:37:53 -05:00
|
|
|
[app.common.schema :as sm]
|
|
|
|
[app.common.schema.desc-js-like :as smdj]
|
|
|
|
[app.common.schema.desc-native :as smdn]
|
|
|
|
[app.common.schema.generators :as sg]
|
2022-11-28 10:47:27 -05:00
|
|
|
[app.common.spec :as us]
|
2022-01-12 14:23:25 -05:00
|
|
|
[app.common.transit :as t]
|
2023-07-27 17:18:38 -05:00
|
|
|
[app.common.types.file :as ctf]
|
2022-10-06 10:03:36 -05:00
|
|
|
[app.common.uuid :as uuid]
|
2023-10-23 12:31:41 -05:00
|
|
|
[app.config :as cf]
|
2020-12-24 08:32:19 -05:00
|
|
|
[app.main :as main]
|
2023-07-27 17:18:38 -05:00
|
|
|
[app.srepl.helpers :as srepl.helpers]
|
2022-10-06 10:03:36 -05:00
|
|
|
[app.srepl.main :as srepl]
|
2021-03-08 07:14:52 -05:00
|
|
|
[app.util.blob :as blob]
|
2022-01-12 14:23:25 -05:00
|
|
|
[app.util.json :as json]
|
2020-12-24 08:32:19 -05:00
|
|
|
[app.util.time :as dt]
|
2022-01-12 14:23:25 -05:00
|
|
|
[clj-async-profiler.core :as prof]
|
|
|
|
[clojure.contrib.humanize :as hum]
|
2020-12-24 08:32:19 -05:00
|
|
|
[clojure.java.io :as io]
|
2021-03-08 07:14:52 -05:00
|
|
|
[clojure.pprint :refer [pprint print-table]]
|
2020-12-24 08:32:19 -05:00
|
|
|
[clojure.repl :refer :all]
|
2019-11-26 07:34:37 -05:00
|
|
|
[clojure.spec.alpha :as s]
|
2022-11-28 10:47:27 -05:00
|
|
|
[clojure.stacktrace :as trace]
|
2020-12-24 08:32:19 -05:00
|
|
|
[clojure.test :as test]
|
2023-03-18 04:32:26 -05:00
|
|
|
[clojure.test.check.generators :as tgen]
|
2019-11-18 05:52:57 -05:00
|
|
|
[clojure.tools.namespace.repl :as repl]
|
|
|
|
[clojure.walk :refer [macroexpand-all]]
|
2022-10-06 10:03:36 -05:00
|
|
|
[criterium.core :as crit]
|
2022-11-28 10:47:27 -05:00
|
|
|
[cuerdas.core :as str]
|
2022-01-12 14:23:25 -05:00
|
|
|
[datoteka.core]
|
2023-05-19 12:37:53 -05:00
|
|
|
[integrant.core :as ig]
|
|
|
|
[malli.core :as m]
|
|
|
|
[malli.dev.pretty :as mdp]
|
|
|
|
[malli.error :as me]
|
|
|
|
[malli.generator :as mg]
|
|
|
|
[malli.registry :as mr]
|
|
|
|
[malli.transform :as mt]
|
2023-07-27 17:18:38 -05:00
|
|
|
[malli.util :as mu]
|
|
|
|
[promesa.exec :as px]))
|
2020-12-24 08:32:19 -05:00
|
|
|
|
|
|
|
(repl/disable-reload! (find-ns 'integrant.core))
|
2021-12-21 09:25:21 -05:00
|
|
|
(set! *warn-on-reflection* true)
|
2020-12-24 08:32:19 -05:00
|
|
|
|
|
|
|
(defonce system nil)
|
2019-06-05 03:26:05 -05:00
|
|
|
|
2022-09-06 09:52:51 -05:00
|
|
|
;; --- Benchmarking Tools
|
|
|
|
|
|
|
|
(defmacro run-quick-bench
|
|
|
|
[& exprs]
|
2022-10-06 10:03:36 -05:00
|
|
|
`(crit/with-progress-reporting (crit/quick-bench (do ~@exprs) :verbose)))
|
2022-09-06 09:52:51 -05:00
|
|
|
|
|
|
|
(defmacro run-quick-bench'
|
|
|
|
[& exprs]
|
2022-10-06 10:03:36 -05:00
|
|
|
`(crit/quick-bench (do ~@exprs)))
|
2022-09-06 09:52:51 -05:00
|
|
|
|
|
|
|
(defmacro run-bench
|
|
|
|
[& exprs]
|
2022-10-06 10:03:36 -05:00
|
|
|
`(crit/with-progress-reporting (crit/bench (do ~@exprs) :verbose)))
|
2022-09-06 09:52:51 -05:00
|
|
|
|
|
|
|
(defmacro run-bench'
|
|
|
|
[& exprs]
|
2022-10-06 10:03:36 -05:00
|
|
|
`(crit/bench (do ~@exprs)))
|
2022-09-06 09:52:51 -05:00
|
|
|
|
2019-06-05 03:26:05 -05:00
|
|
|
;; --- Development Stuff
|
|
|
|
|
2020-01-13 09:14:29 -05:00
|
|
|
(defn- run-tests
|
2022-11-08 04:40:19 -05:00
|
|
|
([] (run-tests #"^backend-tests.*-test$"))
|
2019-06-05 03:26:05 -05:00
|
|
|
([o]
|
2020-02-03 16:29:59 -05:00
|
|
|
(repl/refresh)
|
2019-06-05 03:26:05 -05:00
|
|
|
(cond
|
|
|
|
(instance? java.util.regex.Pattern o)
|
|
|
|
(test/run-all-tests o)
|
|
|
|
|
|
|
|
(symbol? o)
|
|
|
|
(if-let [sns (namespace o)]
|
|
|
|
(do (require (symbol sns))
|
|
|
|
(test/test-vars [(resolve o)]))
|
|
|
|
(test/test-ns o)))))
|
2020-02-24 09:29:12 -05:00
|
|
|
|
2020-12-24 08:32:19 -05:00
|
|
|
(defn- start
|
|
|
|
[]
|
2022-11-28 10:47:27 -05:00
|
|
|
(try
|
|
|
|
(alter-var-root #'system (fn [sys]
|
|
|
|
(when sys (ig/halt! sys))
|
2023-10-23 12:31:41 -05:00
|
|
|
(-> main/system-config
|
|
|
|
(cond-> (contains? cf/flags :backend-worker)
|
|
|
|
(merge main/worker-config))
|
2022-11-28 10:47:27 -05:00
|
|
|
(ig/prep)
|
|
|
|
(ig/init))))
|
|
|
|
:started
|
|
|
|
(catch Throwable cause
|
|
|
|
(ex/print-throwable cause))))
|
2020-12-24 08:32:19 -05:00
|
|
|
|
|
|
|
(defn- stop
|
|
|
|
[]
|
|
|
|
(alter-var-root #'system (fn [sys]
|
|
|
|
(when sys (ig/halt! sys))
|
|
|
|
nil))
|
2022-10-04 08:03:08 -05:00
|
|
|
:stopped)
|
2020-12-24 08:32:19 -05:00
|
|
|
|
|
|
|
(defn restart
|
|
|
|
[]
|
|
|
|
(stop)
|
|
|
|
(repl/refresh :after 'user/start))
|
|
|
|
|
|
|
|
(defn restart-all
|
|
|
|
[]
|
|
|
|
(stop)
|
|
|
|
(repl/refresh-all :after 'user/start))
|
2021-03-08 07:14:52 -05:00
|
|
|
|
|
|
|
(defn compression-bench
|
|
|
|
[data]
|
2022-10-06 10:03:36 -05:00
|
|
|
(let [humanize (fn [v] (hum/filesize v :binary true :format " %.4f "))
|
|
|
|
v1 (time (humanize (alength (blob/encode data {:version 1}))))
|
|
|
|
v3 (time (humanize (alength (blob/encode data {:version 3}))))
|
|
|
|
v4 (time (humanize (alength (blob/encode data {:version 4}))))
|
|
|
|
v5 (time (humanize (alength (blob/encode data {:version 5}))))
|
|
|
|
v6 (time (humanize (alength (blob/encode data {:version 6}))))
|
|
|
|
]
|
2021-12-21 09:25:21 -05:00
|
|
|
(print-table
|
2022-10-06 10:03:36 -05:00
|
|
|
[{
|
|
|
|
:v1 v1
|
|
|
|
:v3 v3
|
|
|
|
:v4 v4
|
|
|
|
:v5 v5
|
|
|
|
:v6 v6
|
2021-12-21 09:25:21 -05:00
|
|
|
}])))
|
|
|
|
|
2021-12-24 06:40:44 -05:00
|
|
|
(defonce debug-tap
|
|
|
|
(do
|
|
|
|
(add-tap #(locking debug-tap
|
|
|
|
(prn "tap debug:" %)))
|
|
|
|
1))
|
2023-03-18 04:32:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
(sm/def! ::test
|
|
|
|
[:map {:title "Foo"}
|
|
|
|
[:x :int]
|
|
|
|
[:y {:min 0} :double]
|
|
|
|
[:bar
|
|
|
|
[:map {:title "Bar"}
|
|
|
|
[:z :string]
|
|
|
|
[:v ::sm/uuid]]]
|
|
|
|
[:items
|
|
|
|
[:vector ::dt/instant]]])
|
|
|
|
|
|
|
|
(sm/def! ::test2
|
|
|
|
[:multi {:title "Foo" :dispatch :type}
|
|
|
|
[:x
|
|
|
|
[:map {:title "FooX"}
|
|
|
|
[:type [:= :x]]
|
|
|
|
[:x :int]]]
|
|
|
|
[:y
|
|
|
|
[:map
|
|
|
|
[:type [:= :x]]
|
|
|
|
[:y [::sm/one-of #{:a :b :c}]]]]
|
|
|
|
[:z
|
|
|
|
[:map {:title "FooZ"}
|
|
|
|
[:z
|
|
|
|
[:multi {:title "Bar" :dispatch :type}
|
|
|
|
[:a
|
|
|
|
[:map
|
|
|
|
[:type [:= :a]]
|
|
|
|
[:a :int]]]
|
|
|
|
[:b
|
|
|
|
[:map
|
|
|
|
[:type [:= :b]]
|
|
|
|
[:b :int]]]]]]]])
|