Merge branch 'master' into 0.1.8

This commit is contained in:
anatoly 2015-12-22 14:46:47 -05:00
commit bb45c14db5
2 changed files with 93 additions and 33 deletions

View file

@ -1,3 +1,13 @@
## 0.1.7
###### Mon Dec 21 20:52:31 2015 -0500
* making mount [boot](https://github.com/boot-clj/boot)'iful
* cljs `:classifier "aot"` is fixed by boot ([#23](https://github.com/tolitius/mount/issues/23))
* refactoring example app: + www
* stopping/cleaning state when its namespace is recompiled ([#22](https://github.com/tolitius/mount/issues/22))
## 0.1.6 ## 0.1.6
###### Thu Dec 10 00:40:18 2015 -0500 ###### Thu Dec 10 00:40:18 2015 -0500

116
README.md
View file

@ -39,6 +39,7 @@ _**Alan J. Perlis** from [Structure and Interpretation of Computer Programs](htt
- [Logging](#logging) - [Logging](#logging)
- [Mount and Develop!](#mount-and-develop) - [Mount and Develop!](#mount-and-develop)
- [Running New York Stock Exchange](#running-new-york-stock-exchange) - [Running New York Stock Exchange](#running-new-york-stock-exchange)
- [New York Stock Exchange Maintenance](#new-york-stock-exchange-maintenance)
- [Web and Uberjar](#web-and-uberjar) - [Web and Uberjar](#web-and-uberjar)
- [Runtime Arguments](#runtime-arguments) - [Runtime Arguments](#runtime-arguments)
- [License](#license) - [License](#license)
@ -476,10 +477,10 @@ that has 3 states:
### Running New York Stock Exchange ### Running New York Stock Exchange
To try it out, clone `mount`, get to REPL and switch to `(dev)`: To try it out, clone `mount`, get to REPL (`boot repl` or `lein repl`) and switch to `(dev)`:
```clojure ```clojure
$ lein repl $ boot repl
user=> (dev) user=> (dev)
#object[clojure.lang.Namespace 0xcf1a0cc "dev"] #object[clojure.lang.Namespace 0xcf1a0cc "dev"]
@ -490,20 +491,20 @@ start/restart/reset everything using `(reset)`:
```clojure ```clojure
dev=> (reset) dev=> (reset)
:reloading (app.config app.nyse app.utils.datomic app dev) :reloading (mount.tools.macro mount.core app.utils.logging app.conf app.db app.utils.datomic app.nyse app.www app.example dev)
15:30:32.412 [nREPL-worker-1] DEBUG mount - >> starting.. app-config INFO app.utils.logging - >> starting.. #'app.conf/config
15:30:32.414 [nREPL-worker-1] INFO app.config - loading config from test/resources/config.edn INFO app.conf - loading config from dev/resources/config.edn
15:30:32.422 [nREPL-worker-1] DEBUG mount - >> starting.. conn INFO app.utils.logging - >> starting.. #'app.db/conn
15:30:32.430 [nREPL-worker-1] INFO app.nyse - conf: {:datomic {:uri datomic:mem://mount}, :h2 {:classname org.h2.Driver, :subprotocol h2, :subname jdbc:h2:mem:mount, :user sa, :password }, :rabbit {:api-port 15672, :password guest, :queue r-queue, :username guest, :port 5672, :node jabit, :exchange-type direct, :host 192.168.1.1, :vhost /captoman, :auto-delete-q? true, :routing-key , :exchange foo}} INFO app.db - conf: {:datomic {:uri datomic:mem://mount}, :www {:port 4242}, :h2 {:classname org.h2.Driver, :subprotocol h2, :subname jdbc:h2:mem:mount, :user sa, :password }, :rabbit {:api-port 15672, :password guest, :queue r-queue, :username guest, :port 5672, :node jabit, :exchange-type direct, :host 192.168.1.1, :vhost /captoman, :auto-delete-q? true, :routing-key , :exchange foo}, :nrepl {:host 0.0.0.0, :port 7878}}
15:30:32.430 [nREPL-worker-1] INFO app.nyse - creating a connection to datomic: datomic:mem://mount INFO app.db - creating a connection to datomic: datomic:mem://mount
15:30:32.430 [nREPL-worker-1] DEBUG mount - >> starting.. nrepl INFO app.utils.logging - >> starting.. #'app.www/nyse-app
INFO app.utils.logging - >> starting.. #'app.example/nrepl
dev=> dev=>
``` ```
everything is started and can be played with: everything is started and can be played with:
```clojure ```clojure
dev=> (create-nyse-schema)
dev=> (add-order "GOOG" 665.51M 665.59M 100) dev=> (add-order "GOOG" 665.51M 665.59M 100)
dev=> (add-order "GOOG" 665.50M 665.58M 300) dev=> (add-order "GOOG" 665.50M 665.58M 300)
@ -512,50 +513,99 @@ dev=> (find-orders "GOOG")
{:db/id 17592186045420, :order/symbol "GOOG", :order/bid 665.50M, :order/qty 300, :order/offer 665.58M}) {:db/id 17592186045420, :order/symbol "GOOG", :order/bid 665.50M, :order/qty 300, :order/offer 665.58M})
``` ```
since there is also a web server running, we can add orders with HTTP POST (from a different terminal window):
```clojure
$ curl -X POST -d "ticker=TSLA&qty=100&bid=232.38&offer=232.43" "http://localhost:4242/nyse/orders"
{"added":{"ticker":"TSLA","qty":"100","bid":"232.38","offer":"232.43"}}
```
```clojure
dev=> (find-orders "TSLA")
({:db/id 17592186045422, :order/symbol "TSLA", :order/bid 232.38M, :order/qty 100, :order/offer 232.43M})
```
once something is changed in the code, or you just need to reload everything, do `(reset)`: once something is changed in the code, or you just need to reload everything, do `(reset)`:
```clojure ```clojure
dev=> (reset) dev=> (reset)
15:32:44.342 [nREPL-worker-2] DEBUG mount - << stopping.. nrepl INFO app.utils.logging - << stopping.. #'app.example/nrepl
15:32:44.343 [nREPL-worker-2] DEBUG mount - << stopping.. conn INFO app.utils.logging - << stopping.. #'app.www/nyse-app
15:32:44.343 [nREPL-worker-2] INFO app.nyse - disconnecting from datomic:mem://mount INFO app.utils.logging - << stopping.. #'app.db/conn
15:32:44.344 [nREPL-worker-2] DEBUG mount - << stopping.. app-config INFO app.db - disconnecting from datomic:mem://mount
INFO app.utils.logging - << stopping.. #'app.conf/config
:reloading (app.config app.nyse app.utils.datomic app dev) :reloading (app.conf app.db app.nyse app.www app.example dev)
15:32:44.371 [nREPL-worker-2] DEBUG mount - >> starting.. app-config INFO app.utils.logging - >> starting.. #'app.conf/config
15:32:44.372 [nREPL-worker-2] INFO app.config - loading config from test/resources/config.edn INFO app.conf - loading config from dev/resources/config.edn
15:32:44.380 [nREPL-worker-2] DEBUG mount - >> starting.. conn INFO app.utils.logging - >> starting.. #'app.db/conn
15:32:44.382 [nREPL-worker-2] INFO app.nyse - conf: {:datomic {:uri datomic:mem://mount}, :h2 {:classname org.h2.Driver, :subprotocol h2, :subname jdbc:h2:mem:mount, :user sa, :password }, :rabbit {:api-port 15672, :password guest, :queue r-queue, :username guest, :port 5672, :node jabit, :exchange-type direct, :host 192.168.1.1, :vhost /captoman, :auto-delete-q? true, :routing-key , :exchange foo}} INFO app.db - conf: {:datomic {:uri datomic:mem://mount}, :www {:port 4242}, :h2 {:classname org.h2.Driver, :subprotocol h2, :subname jdbc:h2:mem:mount, :user sa, :password }, :rabbit {:api-port 15672, :password guest, :queue r-queue, :username guest, :port 5672, :node jabit, :exchange-type direct, :host 192.168.1.1, :vhost /captoman, :auto-delete-q? true, :routing-key , :exchange foo}, :nrepl {:host 0.0.0.0, :port 7878}}
15:32:44.382 [nREPL-worker-2] INFO app.nyse - creating a connection to datomic: datomic:mem://mount INFO app.db - creating a connection to datomic: datomic:mem://mount
15:32:44.387 [nREPL-worker-2] DEBUG mount - >> starting.. nrepl INFO app.utils.logging - >> starting.. #'app.www/nyse-app
INFO app.utils.logging - >> starting.. #'app.example/nrepl
:ready :ready
``` ```
notice that it stopped and started again. notice that it stopped and started again.
In nyse's connection [:stop](https://github.com/tolitius/mount/blob/a63c725dcb6afd7ebb65f8a767d69ee0826921e8/test/app/nyse.clj#L18) In `app.db` connection `:stop` calls a `disconnect` function where a [database is deleted](https://github.com/tolitius/mount/blob/58ca345896e572d7b3fbe8fec21525428f846dd5/dev/clj/app/db.clj#L18). Hence after `(reset)` was called the app was brought its starting point: [database was created](https://github.com/tolitius/mount/blob/58ca345896e572d7b3fbe8fec21525428f846dd5/dev/clj/app/db.clj#L11) by the
function database is deleted. Hence after `(reset)` was called the app was brought its starting point: database was created by the `:start` that calls a `new-connection` function, and db schema is [created](https://github.com/tolitius/mount/blob/58ca345896e572d7b3fbe8fec21525428f846dd5/dev/clj/app/www.clj#L24) by `nyse.app`.
[:start](https://github.com/tolitius/mount/blob/a63c725dcb6afd7ebb65f8a767d69ee0826921e8/test/app/nyse.clj#L11) function,
but no schema again: But again no orders:
```clojure ```clojure
dev=> (find-orders "GOOG") dev=> (find-orders "GOOG")
()
IllegalArgumentExceptionInfo :db.error/not-an-entity Unable to resolve entity: :order/symbol datomic.error/arg (error.clj:57) dev=> (find-orders "AAPL")
()
``` ```
hence the app is in its "clean" state, and ready to rock and roll as right after the REPL started: hence the app is in its "clean" state, and ready to rock and roll as right after the REPL started:
```clojure ```clojure
dev=> (create-nyse-schema) dev=> (add-order "TSLA" 232.381M 232.436M 250)
dev=> (find-orders "GOOG")
()
dev=> (add-order "AAPL" 111.712M 111.811M 250) dev=> (find-orders "TSLA")
({:db/id 17592186045420, :order/symbol "TSLA", :order/bid 232.381M, :order/qty 250, :order/offer 232.436M})
```
dev=> (find-orders "AAPL") ### New York Stock Exchange Maintenance
({:db/id 17592186045418, :order/symbol "AAPL", :order/bid 111.712M, :order/qty 250, :order/offer 111.811M})
Say we want to leave the exchage functioning, but would like to make sure that noone can hit it from the web. Easy, just stop the web server:
```clojure
dev=> (mount/stop #'app.www/nyse-app)
INFO app.utils.logging - << stopping.. #'app.www/nyse-app
{:stopped ["#'app.www/nyse-app"]}
dev=>
```
```bash
$ curl localhost:4242
curl: (7) Failed to connect to localhost port 4242: Connection refused
```
everything but the web server works as before:
```clojure
dev=> (find-orders "TSLA")
({:db/id 17592186045420, :order/symbol "TSLA", :order/bid 232.381M, :order/qty 250, :order/offer 232.436M})
dev=>
```
once we found who `DDoS`ed us on :4242, and punished them, we can restart the web server:
```clojure
dev=> (mount/start #'app.www/nyse-app)
INFO app.utils.logging - >> starting.. #'app.www/nyse-app
{:started ["#'app.www/nyse-app"]}
dev=>
```
```clojure
$ curl localhost:4242
welcome to the mount sample app!
``` ```
## Web and Uberjar ## Web and Uberjar