mount

lucian303 2017-03-16T05:32:54.321445Z

i started a new luminus template project and added one sql function and set up my db urls so that everything's working with the db connection itself but i'm getting a CompilerException java.lang.IllegalArgumentException: db-spec mount.core.DerefableState@5759e7ca is missing a required parameter, compiling:(checker.clj:26:34) when i try to compile or run a repl when i try to access that db function from a second namespace. if i run mount.core/start in that second namespace, it works for the repl and with lein run but lein uberjar fails and it seems like that is unnecessary as mount.core/start is called from the function that starts the app. if i remove the call to the db function in that second namespace, it works fine. i also tried requiring this second namespace in the core namespace that starts the app but that didn't seem to have any effect. any ideas?

tolitius 2017-03-16T15:44:06.608762Z

@lucian303 can you share some code? you only need a single (mount/start) for everything to work. In case of an uberjar, usually, a (mount/start) is called from within a -main method in "xyz" namespace. In order for it to work, that "xyz" namespace should (:require [...]) namespaces with states. It does not need to require all of them, as it would find them transitively: i.e. if you require just a namespace a that in turn requires a namespace b, a is all you need.

lucian303 2017-03-16T19:36:35.401807Z

@tolitius i set up a repo here to demonstrate the problem: https://github.com/lucian303/luminus-test ... the only changes i made from lein new luminus testing +swagger +service +mysql are to add the db urls to profiles.clj, my own db function to the sql file and a call to that function in the testing.routes.services namespace to show the problem. i can only start the repl / server if the call to mount in testing.routes.services is there, but that doesn't help the uberjar which throws an exception cause the db is not started. also, as u say, that should be unnecessary since start is called in the testing.core ns ...

tolitius 2017-03-16T20:01:41.777934Z

> and a call to that function in the testing.routes.services namespace

tolitius 2017-03-16T20:02:07.784256Z

the problem is this is a "global" call to the database on the application start

tolitius 2017-03-16T20:02:17.786852Z

i.e. the app should have a chance to start first

tolitius 2017-03-16T20:02:29.790197Z

and then you can call a function with a resource

tolitius 2017-03-16T20:03:17.801924Z

this line: https://github.com/lucian303/luminus-test/blob/master/src/clj/testing/routes/services.clj#L10 calls into a db before the app ( with all its resources ) is started

tolitius 2017-03-16T20:03:35.807025Z

i.e. it is top level, but it should be inside a function

tolitius 2017-03-16T20:04:00.812936Z

I also noticed you did not setup db properties:

(!) read config from file: ".lein-env", but it is empty

Exception one of :jdbc-url, :adapter, :datasource, or :datasource-classname is required to initialize the connection!  conman.core/make-config (core.clj:56)

tolitius 2017-03-16T20:04:10.815313Z

you can ask about these on the #luminus channel

tolitius 2017-03-16T20:07:29.865383Z

as to mount, you can certainly call (db/get-term-names) in REPL or within a function after the initial call to (mount/start)

tolitius 2017-03-16T20:08:09.874828Z

I believe in #luminus this is where the app is started: https://github.com/lucian303/luminus-test/blob/master/src/clj/testing/core.clj#L45

lucian303 2017-03-16T20:14:00.961421Z

@tolitius i updated the code slightly to make the call inside a function (which is how my real code is) but the problem is the same. the repl will not start when i reference anything from the db because the db isn't started by mount

lucian303 2017-03-16T20:15:10.978427Z

the db works and i am getting data out of it so there's no need to worry about those calls

lucian303 2017-03-16T21:43:48.217022Z

@tolitius i figured out my problem was that the call to the db function should be wrapped in a defstate also so it's not global since it depends on the db (and therefore is a service with state). thanks for your help