Fork me on GitHub

hey folks, could anyone point me at how to make lein repl start up with a particular version of clojure from a non-project directory? I think the place to set this may be ~/.lein/profiles.clj ... I know I can specify that a project use a particular version of clojure by setting :dependencies in its project.clj but I haven't found docs that tell me how to do this when running lein repl


@thott not sure myself, but if you don't get an answer here consider asking in #leiningen

Chris Bidler01:08:53

I haven’t done that with lein, but I know that for boot that is exactly the approach you take - you can set the Clojure version in and the version of that file in ~/.boot is respected if there isn’t one in .

Chris Bidler01:08:58

you can probably also learn by experiment - throw [org.clojure/clojure "1.5.2"] in the :dependencies map of ~/.lein/profiles.clj and see what blows up! 😄


Thanks @donyorm @chris_johnson .. I've tried adding :dependencies [[org.clojre/clojure "1.9.0-alpha17"]] to both the :user and the top-level entry in my ~/.lein/profiles.clj. I'll ask the folks in #leiningen and report back !


How would I go about starting another process alongside my clojure api backend to constantly process another job?


Say I want another process that constantly reads messages out of an external queue and places them in the database


Do you mean a background thread that runs while you main process is also running? (i.e., shuts down when your main process shuts down)


Not necessarily, they can be independent.


I guess that would mean I could just start two separate clojure programs?


But I would like to keep this worker in the same codebase for simplicity’s sake.


In elixir I would just start a separate gen-server alongside the main application if anyone’s familiar with that.


I understand that in a single core processor my worker thread will steal attention from the backend app.


I just need it to play nice, i.e. don’t hold the whole processor to itself


You can start a -main in any namespace in your code so you can have multiple processes in one code base.


So I could just have another worker.clj file and somehow instruct lein to start it alongside core.clj?


java -jar path/to/uberjar.jar -m my.main.namespace


I don't use lein but I suspect you can tell it which namespace to run the -main in...


you can also just put your worker in eg. a future, you just have to negotiate it exiting properly when you need to exit


lein run -m my.main.namespace apparently 🙂


you can even tell it to run a function that isn't -main: lein run -m my.main.namespace/different-function


Great, I’ll dig deeper with that lead, thanks!


@noisesmith I guess in this case, since its independent of the backend thread I would rather not launch it from a future in said backend app.


But I’ll keep that in mind


I've never even thought to consider my clojure process as a single thread


I don't see the advantage of loading up the memory and context switching overheads of two clojure jvms on one machine personally


anyway, if the job needs to be scheduled, you can look at ScheduledThreadPoolExecutor or a wrapper on that like At-At


I hadn’t thought about that


It’s a toy project to familiarize myself with clojure and deploy something


I’ll have a worker that reads messages of a website and stores them in a pg database.


or, I guess to be realistic, I see the stability benefit of a separate process (in the abstract) but in practice for me clojure is so stable I don't see that as worth the other tradeoffs


I have clojure processes that stay running for months


An a web frontend/backend that allows you to receive notifications when a keyword appears in said messages.


i.e. A user will be able to specify keywords like lisp, clojure, racket and the backend will notify the user when a message with said keyword is found


so a small pub/sub


cool - check out sente for websockets


you can do all of that in one server, no need to explicitly manage a separate thread


just send messages to the socket connection objects that care about them, when they are relevant


under the hood the web server will use a thread pool and maybe an async dispatch model on top of that, you shouldn't need to worry about managing those threads by hand at a scale below hundreds of clients


so one way to do it is sente, upgrade connections to websocket, then use sente's collection of open sockets plus some in memory tracking to figure out where to send messages as they show up


but there are other options of course


That sounds great, I think I’ll do that for a second iteration, to get familiar with websockets.


even without the sockets, the http server should be able to manage all the threads you need for that on its own without you needing to do much


For now though, I just want to store a couple days worth of messages from a website in the database, run a cron job that queries said messages for the keywords and stores matches for the user


so then the user can log in and see a summary of the matches for his interests


ScheduledThreadPoolExecutor is very easy to set up for that (at first I thought you meant the messages would also come in via the same webserver maybe from other clients)


I’m pulling messages constantly from hacker news api so I thought that would interfere with the webserver


I come from nodejs 😅


no, clojure uses actual real threads


as long as the threads are in the hundreds to thousands, not thousands to tens of thousands, you are not going to need to worry too much about the mechanics of thread usage (unless you opt into an async model like core.async, but that's optional)


Alright, good to know


Thanks I’ll get coding


Hi all! Does anyone have a good way to ‘mock’ out a http function in a clojurescript test? I tried using with-redefs, but it doesn’t seem to work inside an async go macro.. I just want to replace the http response with a map containing test values. Am I going at this the wrong way?


I try to put my side-effecty fns behind a protocol and use a different impl for isolated tests


@donaldball thanks, I'll look into that 😊


I'm failing to deploy a project to Heroku that runs fine locally. I've got too many moving pieces, and I'm not sure how to tackle debugging. It's not actually a Heroku problem. I can see problems even with a local lein run. I'm pretty sure that the problem is in project.clj. Or, in reality, in one of my project.clj files. The project includes two new libraries of mine too. The most obvious first error is that I get:

$ lein uberjar
Picked up _JAVA_OPTIONS: -Xmx2g
Compiling ClojureScript...
WARNING: no :cljsbuild entry found in project definition.
WARNING: your :cljsbuild configuration is in a deprecated format.  It has been
automatically converted it to the new format, which will be printed below.
It is recommended that you update your :cljsbuild configuration ASAP.
{:builds []}
I don't know what this is trying to tell me. The main project is, and sure seems to have a cljsbuild. The two suspicious library projects are sodium and re-frame-firebase. Or, though less likely, re-frame-storage-fx. Less likely, because I've used that in other deployed projects. Links:,, and I'm truly sorry to be dumping this mess on the channel, but I'm tired and frustrated. Any help much appreciated.


@deg IIRC, those warnings don’t necessarily mean that there’s any sort of blocking problem with your project. Does seem like it would be a good call to fix those first, though. This page has a description and some good examples of what your :cljsbuild should look like:


It wouldn’t shock me if Heroku was being stricter than lein is locally, and insisting on a valid :cljsbuild.


Oh, I see the link to yours now, I’ll see if anything jumps out at me, although it’s been a while since I’ve written one.


Thanks, I know that page. My project does work under dev/figwheel/etc. The error is not being caused by Heroku. I also get it locally, with a simple lein run. It looks like it is not including my clojurescript code. I started each of the libraries with different templates (mies and re-frame-template) and I don't even know where my problem is. (and it is nearly 2am here; not helping my mood much. 😞 )


Right, I get that the error isn’t caused by Heroku — just thinking that while lein locally is autoconverting the invalid data, Heroku might be being stricter & refusing to autoconvert, & hence not deploying.


Caveat: I’ve never deployed a clj/s project to Heroku, so that’s pure guesswork.


Nope, I had hoped that, which is why I tried the local test. But the local fails.... it does start the server, but when I load the web page, my main namespace is not found.

Chris Bidler22:08:14

So I haven’t used lein cljsbuild in anger, and therefore this might be garbage, but when I compare your project.clj and the one here:


And, no other errors or warnings.

Chris Bidler22:08:29

I notice that yours is shaped like this:

Chris Bidler22:08:16

:builds { [ {:id "an id" ...} ... ] }

Chris Bidler22:08:49

and the example is shaped differently: :builds { :id { ... } }

Chris Bidler22:08:36

and that difference might be causative of the project compiler complaining about “legacy format” and “here make this empty map instead”

Chris Bidler22:08:15

but the example could be out of date too, like I said, I haven’t used lein cljsbuild, just trying to help apply more eyes


Hmm, you are right. I'll try changing that. But, I think this may be a red herring. Mine was generated by the re-frame-template template.


Oh, actually, almost certainly a red herring. I forgot to mention one key clue: I tried running an early commit of my project, and it did work. It already had the the template-generated project.clj, but did not have my dependencies.


I also notice that neither re-frame-firebase nor re-frame-storage-fx has a :cljsbuild in its project.clj. I’m not entirely certain that you cause problems, but it might be worth checking. Possibly you started those with clj-only templates?


So, I think the problem lies in one of my libraries. Each of them has its own wonkiness --- one comes from Mies, which is beautiful and simple, but uses Dave Nolen's hand-crafted tools that don't use cljsbuild.


The other (Sodium) has cljsbuild, but seems to be missing the production build. I forget which template that came from.... one sec....


My 1st instinct would be to start by making a trivial new project & try adding deps for one of those libs & requiring & using it, and then for the other, and at each step verify that you can still build & deploy.


(ie still build/deploy the trivial containing project)


But, I'm going to wait until after a night's sleep. I'm running on fumes now, which is the major reason I vented here.


I hear that. Good for you recognizing it; I always have a really hard time stopping when I’m frustrated/exhausted 🙂


Hmm, just tired enough to chuckle hysterically at the mixed metaphor of fumes and venting. I better get some sleep.


Thanks for your help!


LOL. Take care 🙂

Chris Bidler22:08:16

You’ll wake up and the answer will leap off the screen and bite you when you sit down to code again.

Chris Bidler22:08:25

that’s how it usually is for me


Yeah, I hope so. And it usually is so.


The underlying problem here is that I've not found a good template for creating cljs library projects


That is: projects that are only intended to be included in other cljs projects, yet still have some real complexity like macros and .cljc.


And, of course, the usual dreadfulness of Clojure error messages.


anyway, good night and thanks