heroku

2021-03-23T15:58:03.001200Z

Hi fellow clojurians Im deploying clojure deps.edn app to heroku. and it deployed successful. But heroku dyno restart (happens once every day automatically ) fails with

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 150 seconds of launch
Here my Procfile command
web: java -cp ps.jar clojure.main -m reviews.system
and here is my main system file, Locally it takes around 30 seconds to start up server
(ns reviews.system
  (:require [integrant.core :as ig]
            [ring.adapter.jetty :as jetty]
            [reviews.server :as server]
            [migratus.core :as migratus]
            [migrations :as migrations]
            [reviews.db :as db]))

(def system-config
  {:shop/jetty {:handler (ig/ref :shop/handler)
           :port (Integer. (or (System/getenv "PORT") "3000"))}
   :shop/handler {:db (ig/ref :shop/postgres)}
   :shop/migrations {:db (ig/ref :shop/postgres)}
   :shop/postgres nil})

(defmethod ig/init-key :shop/jetty [_ {:keys [handler port] }]
  (println "server running on port 3000")
  (jetty/run-jetty handler {:port port :join? false}))



(defmethod ig/init-key :shop/migrations [_ {:keys [db] }]
  (let [config {:db {:datasource {:datasource db}}}]
    (migratus/migrate migrations/config)))

(defmethod ig/init-key :shop/handler [_ {:keys [db] }]
  (server/create-app db))

(defmethod ig/init-key :shop/postgres [_ _]
  db/spec)

(defmethod ig/halt-key! :shop/jetty [_  jetty]
  (.stop jetty))



(defn -main []
  (println "Running main!")
  (println "PORT: " (Integer. (or (System/getenv "PORT") "3000")))
  (ig/init system-config))

(comment 
  (def system (ig/init system-config))
  (ig/halt! system))

practicalli-john 2021-03-23T18:04:05.009300Z

@umardaraz4747 Starting jetty by itself should be pretty instantaneous, so assume it must be due to the database or what you are doing to the database. If you are on a free plan for Heroku Postgres, check you are not exceeding the 10,000 row limit. Is there anything else in the heroku logs?

heroku logs --app your-heroku-app-name --tail
I would look at the logs and emulate a restart by using the following commands a suitable time apart
heroku ps:stop your-heroku-app-name
heroku ps:stop your-heroku-app-name
All the logs have timestamps, so you should be able to see how long its taking... I would look for issues connecting to the db or perhaps migrations. Perhaps add some printlin or logging expressions to the migrations to see how quickly that is doing something. I am unsure what the Integrant :shop/postgres is doing, perhaps its just defining the JDBC_DATABASE_URL environment variable to connection to the database. I assume its not trying to start/restart the Heroku Postgres database. I would also consider separating out Migrations into its own project and run that as an independant Heroku application, that way your web application server is not dependant on a potentially lengthy database migration step. If you are happy to share a repository of the code, I can try deploying it myself on Heroku and see if I can spot any issues.