Clojure app does not start with Heroku; Alef + RedisToGo timeout

My clojure noir app works 100% fine and does not work with RedisToGo.

The problem is when I deploy to Heroku (git push heroku master), I get a timeout error:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 

The full magazine is here: https://gist.github.com/1842439

When I remove this redis connection code, it deploys fine:

 (:use [aleph.redis :only (redis-client)]) (def r (redis-client {:host redis-url :password redis-pass :port redis-port})) 

The strange thing is that when I run "runk run lek runen" and paste the above aleph code, it connects to redis fine and I can read / write data.

So, this is something about how the hero downloads an application that breaks the connection with RedisToGo and drags it out.

+4
source share
1 answer

Performing something of the side effect at the top level is very suspicious - this code is executed at compilation as well as at execution, therefore, probably the automatic uberjar Heroku fails because redis is not available at compile time or something like that.

Instead, initialize your redis client after -main has been called, which ensures that you are in a production environment. You can accomplish this in several ways, for example by first defining it to nil and then running alter-var-root in -main . My preferred solution would probably be something like:

 (def r (delay (redis-client ...))) (defn get-stuff [] (let [client @r] ...)) (defn -main [& args] (get-stuff) ...) 

Now the connection code is not executed until someone cancels the client, which they should never do until the application is launched.

+5
source

Source: https://habr.com/ru/post/1396891/


All Articles