clojure project for Heroku: procfile and organization - heroku

I have a single web application in clojure that is running on Heroku, but I want to create some worker processes. Currently, my procfile says this:
web: java $JVM_OPTS -cp target/myapp-standalone.jar clojure.main -m myapp.web
Am I correct in assuming that I can simply create a new namespace "worker.clj" within the clojure project, and by amending the procfile to the following, that the new class/process would start up on a worker dyno?
web: java $JVM_OPTS -cp target/myapp-standalone.jar clojure.main -m myapp.web
worker: java $JVM_OPTS -cp target/myapp-standalone.jar clojure.main -m myapp.worker
Is this the right approach?

Yes, as long as you have a -main function in your new namespace, this will work.

Related

Procfile - Migration from Heroku to AWS Fargate

I've created a project to migrate from my heroku app to AWS Fargate.
But I couldn't find a solution for multi-module. Is there a way to do it?
In hereoku, there is a file like Procfile and we can easily set the different modules there.
https://devcenter.heroku.com/articles/procfile
web: java -jar web/target/myapp-1.0.0.jar
worker: java -jar worker/target/my-worker-app-1.0.0.jar
Actually I wonder that how can I handle procfile on AWS ECS?

Heroku run Jar file once deployed?

I have deployed my jar file to heroku using:
heroku deploy:jar <filename>.jar --app <appname>
Once deployed, how do I run the jar file with specific params, i.e. locally i would execute:
java -jar <filename>.jar <param1> <param2>
Am i using the Heroku service correctly? In essence I just need to run the Main command within the jar file and get the logs when completed.
Any help would be much appreciated.
heroku deploy:jar <filename>.jar --app <appname>
With this you essentially hardcorded:
jar <filename>.jar
Here is an example where you can configure parameters for your command
https://github.com/NNTin/shell-kun/tree/6b35e4b731bcf500366f60bbceafe076bf969fe1
Note: We are looking here at older software because HEAD no longer has it.
You need Procfile. app.json and the Heroku Deploy (see link in README.md) button are optional. They make deploying easier since you don't have to touch terminal/CLI.
Essentially you extend your Procfile to:
web: jar <filename>.jar $ARGS_AND_FLAGS
worker: jar <filename>.jar $ARGS_AND_FLAGS
web when you are utilizing a $PORT, worker when not.
Now you can modify your command by editing the environment variable ARGS_AND_FLAGS.
In this case the web process is activated and the worker process is deactivated.
After you changed your environment variable you can deactivate and then activate your process.
Create a Procfile in the same directory where you run heroku deploy:jar with the content:
web: java -jar <filename>.jar <param1> <param2>
and redeploy the app.

How to set Procfile in Heroku in PlayFramework

Now I am trying to deploy PlayApplication, but unfortunately my deploy failed. And the error code is H10, so probably I assume the problem is setting files because my database setting must be true as I can connect database by using the created username, password and URL.
And in my understanding, Procfile just shows a command to be run toward dynos and in tutorials, in terms of Java the procfile is like this:
web: java -jar target/helloworld.jar
However, in my application, the Procfile is web: target/start -Dhttp.port=${PORT} ${JAVA_OPTS} -Dconfig.file=conf/application_prod.conf where conf/application_prod.conf is the path to the setting file. Is this Procfile right?
My play version is 2.2.1 and the official document says web: target/universal/stage/bin/retailos -Dhttp.port=${PORT} -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=${DATABASE_URL} is good and I can also use the option -Dconfig.file= and then you can indicate where the setting file is. This means web: target/universal/stage/bin/retailos -Dhttp.port=${PORT} -DapplyEvolutions.default=trueBut -Dconfig.file=conf/application_prod.conf. But it does not work well.
And there are many candidates about the right way being also indicted by How to create play heroku procfile?.
I am really confused. I already have written all DB settings into application_prod.conf, so I prefer to use -Dconfig.file=.
What is exactly the true one?
Thanks.
Using -Dconfig.file and similar is definitely a good idea, you do not need to set all config parameters in your Procfile.
The reason it doesn't work is probably because you're using a file path for your config file, which to my knowledge doesn't work when the application is deployed as a jar. Try this instead:
-Dconfig.resource=application_prod.conf

Brand new Luminus app giving Error: Could not find or load main class clojure.main

I just created a Luminus app by running:
lein new luminus foobar
and when I try to run it with foreman like this:
foreman start
the way the docs describe, I get this error:
Error: Could not find or load main class clojure.main
which is also the same error I get from Heroku. The Procfile that the template created contains this:
web: java $JVM_OPTS -cp target/foobar.jar clojure.main -m foobar.core
What's going on, how do I fix it?
My best guess is that you need to build the project with the command lein uberjar. This sequence works:
$ lein new luminus foobar
Retrieving ...
Generating a Luminus project.
$ cd foobar
$ lein uberjar
Retrieving ...
Compiling foobar.session
Compiling foobar.layout
Compiling foobar.handler
Compiling foobar.routes.home
Compiling foobar.core
Compiling foobar.middleware
Created /home/ba/foobar/target/foobar-0.1.0-SNAPSHOT.jar
Created /home/ba/foobar/target/foobar.jar
$ cat Procfile
web: java $JVM_OPTS -cp target/foobar.jar clojure.main -m foobar.core
$ java $JVM_OPTS -cp target/foobar.jar clojure.main -m foobar.core
2015-Jun-22 06:30:42 -0400 ba INFO [foobar.handler] -
-=[ foobar started successfully nil ]=-
2015-06-22 06:30:42.998:INFO:oejs.Server:jetty-7.x.y-SNAPSHOT
2015-06-22 06:30:43.028:INFO:oejs.AbstractConnector:Started SelectChannelConnector#0.0.0.0:3000
Regarding Luminus and the Procfile,
see this diff.
Fixed upstream but you can fix it in your app by changing your Procfile from:
web: java $JVM_OPTS -cp target/foobar.jar clojure.main -m foobar.core
to:
web: java $JVM_OPTS -cp target/uberjar/foobar.jar clojure.main -m foobar.core

Running clojure project does not compile on Heroku - memoize error

Here's the error I get deploying to Heroku:
Exception in thread "main" java.lang.RuntimeException: No such var: clojure.core.cache/through, compiling:(clojure/core/memoize.clj:52:3)
This project runs fine on my local machine. This particular dependency is for some Compojure middleware.
The way the application is started on heroku, using a Procfile that probably looks like this:
web: java $JVM_OPTS -cp target/helloworld-standalone.jar clojure.main -m hello.world $PORT
May brings slightly different dependency sets.
Make sure you have this in your project.clj
[org.clojure/core.cache "0.6.4"]
You can make sure it works on your machine first using the same classpath by using foreman to control your application on your local machine too.

Resources