Fork me on GitHub
#mount
<
2018-02-08
>
aleksander16:02:26

Do I understand correctly that to pass a parameter to a :start lifecycle function I need to specify it inside another defstate? or have the parameters definied in the namespace? no way to pass the argument to the function directly though?

tolitius16:02:39

@aleksander is it a command line argument?

aleksander16:02:10

no, just a configuration value

aleksander16:02:30

a port on which the web server is supposed to listen on

aleksander16:02:32

ideally I would like to pass that value when starting

tolitius16:02:59

which component starts the app? i.e. is it -main

tolitius16:02:23

usually you would create a config state which reads a config file or reaches out to external configuration service (i.e. consul, etcd, ..)

tolitius16:02:40

this state becomes a map with all the application configuration

tolitius16:02:31

then in other states that need config, such as port, you would do something similar to (config :port)

tolitius16:02:09

it reads config from consul: https://github.com/tolitius/hubble/blob/master/src/clj/hubble/env.clj#L30 but it could also simply read it from a local config file, since it just becomes a map when started

tolitius16:02:59

here is an example of reading a config from a file into a state: https://github.com/tolitius/stater/blob/master/smsio/src/app/conf.clj

aleksander17:02:50

Thanks, I'll go through the examples tomorrow!

aleksander17:02:30

yes, main I was thinking of reading the configuration outside of a mount component

tolitius18:02:02

@aleksander > I was thinking of reading the configuration outside of a mount component if you really do not want to have a config component (why?) instead of (mount/start) you could use (mount/start-with-args args) where args is a map with arguments

aleksander10:02:46

I wanted to explicitly pass the port to the web server component as a parameter, not having it read from other component inside the :start function

aleksander10:02:54

but that doesn't seem to be mount way

aleksander10:02:58

you wouldn't/can't pass parameters to :start functions

aleksander12:02:58

the motivation would be to easier see the dependencies

tolitius13:02:59

> the motivation would be to easier see the dependencies since mount start components in the order they are "used", you would always see config as a dependency:

dev=> (require '[mount.tools.graph :as graph])

dev=> (graph/states-with-deps)
({:name "#'app.conf/config", 
  :order 1, 
  :status #{:started}, 
  :deps #{}}
 {:name "#'app.db/conn",
  :order 2,
  :status #{:started},
  :deps #{"#'app.conf/config"}}
 {:name "#'app.www/nyse-app",
  :order 3,
  :status #{:started},
  :deps #{"#'app.conf/config"}}
 {:name "#'app.example/nrepl",
  :order 4,
  :status #{:started},
  :deps #{"#'app.www/nyse-app" "#'app.conf/config"}})

tolitius18:02:53

later anywhere in state / functions you can access it with (mount/args): i.e.

(get-in (mount/args) [:server :port])