Skip to content

Latest commit

 

History

History
95 lines (55 loc) · 4.05 KB

home.textile

File metadata and controls

95 lines (55 loc) · 4.05 KB

Jobberwocky

Jobberwocky is a module to execute a Play! Job from command line outside of the Play’s web application container. This allows you to reuse all your application logic and models from command line program.

Job executed by Jobberwocky will support Play JPA models and transaction annotations.

Jobberwocky will support both PROD (precompiled) mode and DEV modes.

The Job must have a default constructor and/or a constructor with a single Map argument. A Job with a Map constructor can receive command line arguments.

Usage

There are 3 ways to use the Jobberwocky module to run a job from command line.

The Play Command Extension

Run a job directly using the play jobberwocky:runjob command. See the Commands topic below.

Generate an Executable Script

Use play jobberwocky:posixscript or play jobberwocky:windowscript to generate a POSIX/Unix shell script or Windows batch file to run a job. The scripts are specific to the current environment pathnames. You may modify the script for other environments or make other customizations.

Write Your Own

Use the Jobberwocky library to invoke a Job from your own command-line application. For example:

public static void main(String[] args) {
    try {
      PlayContext context = new PlayContext();
      context.runJob(MyJob.class); 
    }
    catch(Exception e) {...}
    Play.stop();
    System.exit();
}

You must supply your Play application path with -Dapplication.path and the Play framework path with -Dplay.path in the VM argument. Alternatively, they can be supplied into the PlayContext constructor. You may also supply the framework id using the standard -Dplay.id VM argument.

Your command line application classpath must include the play-jobberwocky.jar and all the dependent libraries used by Play Framework, 3rd party libraries from your application, your modules, your application own classes and the /conf directory. Your application classes are located in /tmp/classes in DEV mode and /precompiled/java in PROD mode. If you are unsure, have a look at the classpath by generating a run script using one of jobberwocky:posixscript or jobberwocky:windowscript.

Commands

runjob

Run a job directly from the Play Command:

play jobberwocky:runjob [application] [job] {options}
  • application – Play application name
  • job – Job class name in the application
  • options – optional. Arguments to pass into the Job. The Job must have a constructor with a single Map argument. The argument may also include the Play framework id.

For example:

play jobberwocky:runjob myapp com.mycompany.MyJob --%prod 

posixscript

Generate a POSIX/Unix shell script to run a job

play jobberwocky:posixscript [application] [job] {--%playid}
  • application – Play application name
  • job – Job class name in the application
  • playid – optional. Play framework id using the —% option.

The command will generate a script file to your application /bin directory.

For example:

play jobberwocky:posixscript myapp com.mycompany.MyJob --%prod 

will generate a script file from your application path: /bin/MyJob.sh.

windowscript

Generate a Windows batch file to run a job.

play jobberwocky:windowscript [application] [job] {--%playid}
  • application – Play application name
  • job – Job class name in the application
  • playid – optional. Play framework id using the —% option.

The command will generate a batch file to your application /bin directory.

Misc.

Precompilation

If the application has been precompiled and the /precompiled folder exists, all the Jobs will run with precompiled code.

Return Value

If the Job returns a Number as a return value, the number will be the application return value.