Search code examples
javaherokuplayframework-1.xworker

heroku worker job java playframework


After reading all the articles I could not find a solution to my problem.

  1. I have a java play web-app running good on Heroku. With a web: xxx process in the Procfile
  2. In the same app, I have defined some Jobs.
    • I have MyJob class which extends play.Job
    • I have a Main class while(true) wait and execute MyJob.

my Procfile looks like this.

web:    play run --http.port=$PORT $PLAY_OPTS
worker: java -cp target/classes;target/dependency/* jobs.MyJob

I understand that since this is not a maven project classes and dependency directories dont exists.

But then, how shall I set the worker: java xxxx command?


Solution

  • Are you annotating your Job classes? To start a job when Play starts, just do:

    @OnApplicationStart
    public class Bootstrap extends Job {
    

    Or use the @Every or @On annotations:

    @On("0 0 12 * * ?")
    public class Bootstrap extends Job {
    
    @Every("1h")
    public class Bootstrap extends Job {