Git Product home page Git Product logo

play2-scheduled-job-demo's Introduction

Simple Play 2 App with a Job

This example shows how to run a scheduled job in a Play app either in the web process or outside the web process (e.g. an external scheduler like Heroku's Scheduler Addon.

Running Locally

By default, when running the web app locally the Tick runs every second:

./sbt ~run

You should see "tick tock" every second in the STDOUT logs.

To run just a single Tick as a standalone process, run:

./sbt runMain jobs.TickJob

You should only see a single "tick tock" and then the process exits.

Running on Heroku

  1. Deploy on Heroku
  2. Open the Resources tab in your app's dashboard: https://dashboard.heroku.com/apps/YOUR APP NAME/resources
  3. Click on the Heroku Scheduler Add-on
  4. Add a new scheduled task with tick as the command / task name
  5. Check your app's logs to see the scheduled tick: https://dashboard.heroku.com/apps/YOUR APP NAME/logs

play2-scheduled-job-demo's People

Contributors

gabrielcs avatar jamesward avatar mbseid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

play2-scheduled-job-demo's Issues

Application Configuration Not Loaded for Worker Process

It appears that using DefaultApplication in the way presented in this application does not properly load the configuration file. Not sure if this is a bug in Play or just a misuse of the API. Also, I noticed that the DefaultApplication results in a "DefaultGlobal" being used instead of the application's own GlobalSettings which is another potential problem. I might suggest using the pattern suggest by Ivan in the thread: https://groups.google.com/forum/#!topic/play-framework/kI9GWEw44So

Essentially you might want to use StaticApplication rather than DefaultApplication.

Update:
Turns out you have to specify -Dconfig.file=conf/application.conf. The new File("conf/application.conf") argument for DefaultApplication is not related to specifying the app's configuration during runtime but rather appears to be used to specify the application's root path.

[Play 2.2] Classpath on Procfile

Hi James,
For some reason the JAR with the Job class file is not going to target/staged/ but to target/universal/stage/lib/ instead. I suspect this is because I'm using Play 2.2 but I'm not sure.
To make it work I've changed the classpath option on Procfile to:
-cp "target/universal/stage/lib/*"

Global.onStart() is called both when initializing the Application and the TickJob

Hi James,

As you probably already know, Global.onStart() is called both when initializing the Application and the TickJob. I tried to write some code that would check whether it is the main application or the scheduled job that is running by checking the classloader but to no success. It seems like both of them have the same classloader. I've forked your repository and you can find the Global class I've written here: https://github.com/gabrielcs/play2-scheduled-job-demo/blob/master/app/Global.java

This is important since one may want to connect to a cloud database on Global.onStart() only if it's the Application that's being initialized, for example.

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.