I have a microservice written in Scala that primarily runs scheduled jobs. It's not a play app. The main function just sets up the scheduled jobs. For example
import cronish.dsl._
object workers {
def main(args: Array[String]) : Unit = {
val payroll: CronTask = task {
println("Syncing Payroll...")
}
payroll executes "every 5 minutes"
}
}
I deployed this to Heroku and while the job begins to run as expected, Heroku kills it every single time after 60 seconds.
Syncing Payroll...
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed
I've followed the official Heroku documentation. Here is what my build.sbt looks like
name := "AppName"
version := "0.1"
scalaVersion := "2.11.9"
enablePlugins(JavaServerAppPackaging)
libraryDependencies += "com.smartsheet" % "smartsheet-sdk-java" % "2.2.2"
libraryDependencies += "com.github.philcali" %% "cronish" % "0.1.3"
libraryDependencies += "org.scalaj" %% "scalaj-http" % "2.3.0"
....
and I've added both of the Heroku plugins to the plugins.sbt file as well
addSbtPlugin("com.heroku" % "sbt-heroku" % "2.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.1")
It runs totally fine on development if I use sbt run. I'm thinking that Heroku is expecting this service to be a web server so it keeps trying to attach it to an open port however since this service is not a web-server it can't do that. Is it possible to deploy such microservices to Heroku? Do it need to use a custom build pack?
Your Procfile
should use worker:
instead of web:
. For example:
worker: target/universal/stage/bin/{myAppName}
Then scale up the "worker" dynos by running:
$ heroku ps:scale worker=1
You can name the process anything you want (doesn't have to be "worker"), but "web" dynos are treated specially. Heroku expects them to bind to a port and serve web requests.