Reason for skipping AOT?

房东的猫 提交于 2019-12-03 01:11:16

This isn't specific to noir but one scenario you might want to skip AOT for a given namespace is when deploying your code to a PaaS provider such as heroku.

Heroku performs AOT compilation of your code by default so consider this snippet in your server.clj:

(db/connect! (System/getenv "DB_URL"))

(defn start [port]
  (run-jetty app {:port port :join? false :max-threads 100}))

In principle this code seems harmless and will work locally regardless of it being AOT-compiled.

However during compilation on heroku, the environment variable "DB_URL" isn't available yet so the connect! statement above will try to connect to nil and throw an exception.

Skipping AOT compilation of this namespace is one way of preventing this.

Another, and my preferred approach at the moment would be to change it slightly to this:

(defn bootstrap! []
  (db/connect! (System/getenv "DB_URL")))

(defn start [port]
  (bootstrap!)  
  (run-jetty app {:port port :join? false :max-threads 100}))

That way it's a little clearer what your intention is and you avoid attempting a database connection during compilation.

I learned this the hard way and documented it in this blog post.

Hope this is useful.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!