Fork me on GitHub
#leiningen
<
2020-05-22
>
Pavel Klavík16:05:41

Hi, after adding [org.immutant/scheduling "2.1.10"] dependency, lein run works fine but lein uberjar gets stuck on lein compile prep-task forever, no output or errors:

:uberjar {:source-paths   ["env/prod/clj"]
             :omit-source    true
             :main           orgpad.server.core
             :aot            [orgpad.server.core]
             :uberjar-name   "orgpad.jar"
             :prep-tasks     ["clean"
                              ["run" "-m" "orgpad.build/release"]
                              "compile"
                              ["garden" "once"]]
             :resource-paths ["env/prod/resources"]}

Pavel Klavík16:05:06

Any tips how to debug this or what could be causing the problem?

Pavel Klavík16:05:10

It seems to be caused by calling this code:

(s/schedule #(reset! metrics (compute-metrics))
            {:id    "recompute-metrics"
             :in    [15 :seconds]
             :every [15 :minutes]})

noisesmith17:05:15

@pavel.klavik if you use Control-\ or jstack <PID> or kill with signal 3 you'll get a trace of all running threads

noisesmith17:05:31

one of them will be doing something "suspicious" most of the time, and usually it's the longest trace

noisesmith17:05:11

@pavel.klavik also - I would expect that call (at the top level or inside def) to be a problem

noisesmith17:05:41

clojure doesn't have a "compile mode", when you compile a file, all top level forms are run, and if they have side effects those side effects happen right then

noisesmith17:05:12

the typical fix here is to have a function that calls s/schedule and invoke it from main, or use a delay or component config to arrange for it to run later as needed

Pavel Klavík17:05:57

thx, makes sense, I moved into a function called from main and it works now

Pavel Klavík17:05:35

why does this work with lein run?

noisesmith17:05:05

usually because when you use lein run you want the process to stay running until you explicitly shut it down

noisesmith17:05:46

the hanging during compile is literally just the server running, meaning the vm doesn't shut down

noisesmith17:05:45

it's sitting around waiting to do its task in 15 minutes

Pavel Klavík17:05:30

I see, thx for the explanation