luminus

2018-11-08T10:16:26.008600Z

Hi all, what do people use for scheduled background jobs when using Luminus?

kennethkalmer 2018-11-08T15:32:09.010600Z

Howzit everyone, I have a very peculiar issue that I just managed to reproduce successfully on a test project. It’s related to conman/hugsql (and postgres)

kennethkalmer 2018-11-08T15:33:06.011500Z

if I use clojure expressions in queries.sql, I can’t use (restart-db) in the user namespace anymore, it dies with:

user=> (restart-db)

           java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace
clojure.lang.Compiler$CompilerException: java.lang.ClassCastException: clojure.lang.Symbol cannot be cast to clojure.lang.Namespace, compiling:(null:1:1)

kennethkalmer 2018-11-08T15:34:03.012300Z

switching to the .db.core ns and then binding the connection works just fine

user=> (in-ns 'lumipg.db.core)
#namespace[lumipg.db.core]
lumipg.db.core=> (conman/bind-connection *db* "sql/queries.sql")
{:fns {:clj-expr-single {:fn #<Fn@502dc1a8 conman.core/try_query[fn/fn]>
                         :meta {:command :?
                                :doc ""
                                :file "sql/queries.sql"
                                :line 1
                                :result :1}}}
 :snips {}}

kennethkalmer 2018-11-08T15:34:41.012900Z

and the query is an example straight from the Hugsql docs, so nothing special:

-- :name clj-expr-single :? :1
select
--~ (if (seq (:cols params)) ":i*:cols" "*")
from test
order by id

kennethkalmer 2018-11-08T15:36:00.014300Z

but somehow rebinding *ns* is not doing the trick, and I don’t know where to report the issue. is this a problem with conman or the way the template sets up the restart-db function?

kennethkalmer 2018-11-08T15:36:52.014900Z

sample project is a straight forward lein new luminus lumipg +postgres with 3.10.11

kennethkalmer 2018-11-08T16:44:48.015800Z

I’m stumped, I spent a bit of time just stepping through the execution in IntelliJ and alas I’m none the wiser

kennethkalmer 2018-11-08T16:47:06.016400Z

settled for this inside (restart-db) and seems to work (so far 🤞)

(try
    (in-ns 'lumipg.db.core)
    (conman/bind-connection lumipg.db.core/*db* "sql/queries.sql")

    (finally
      (in-ns 'user)))