Quartz is a full-featured, open source job scheduling system that can be integrated with, or used along side virtually any J2EE or J2SE application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components or EJBs. The Quartz Scheduler includes many enterprise-class features, such as JTA transactions and clustering.
Configure a Quartz job:
1. Click on the Quartz Scheduler tool (in the left nav tool list).
2. Click on Jobs (at the top of the pane).
3. Click on New Job.
4. Enter a Job Name.
5. Select a job from the pop up list.
6. Click the "Post" button.
7. In the new job listing, click on the Triggers link.
8. Click on "New Trigger".
9. Create a Trigger Name.
10. Create a Cron Expression. Click the "help" link next to this field for cron expression information. (This "0 0 0/1 * * ?" means fire every hour.)
11. Click on "Post".
12. Click on "Event Log" to watch for your jobs to fire.
(The supplied test jobs write execute or execute2 to standard out.)
To create custom jobs:
There are two methods to create your own jobs. The first and recommended way is to create your jobs and register them with the Quartz Scheduler. This way they can be deployed outside of the jobscheduler component itself, in another tool or source package.
The second method is to modify the jobscheduler source itself to include your own job and modify the existing components.xml to add an entry for your job. Whilst this method may sound easiest at first, you will need to remember to maintain these modifications across upgrades.
Method 1: Creating jobs externally and registering them with the jobscheduler:
This is the preferred method as it will mean less headaches for upgrades - you can create your own package and just drop it into Sakai, rather than having to tinker with the jobscheduler project each time. It also means that any Sakai tool could, theoretically, bundle their own jobs and expose them in the jobscheduler project automatically.
To get started, check-out the following bundle into the root of your Sakai source code:
It's all ready to go with an example HelloWorld job so all you now need to do is build it:
If you get a build failure, you might want to check the pom.xml in the root of the quartz-example to make sure its version number (currently M2) matches the rest of your Sakai tools.
If it all builds fine, restart Sakai, login as an admin user and in the Admin Workspace, configure your Job to run as per the notes above. If you tail catalina.out, and run this job immediately, you can see it outputting a friendly message.
Now you should have a look at the various parts of this package and see how they wire themselves together and start writing your own job!
- quartz-example/scheduler-jobs/src/java/uk/ac/lancs/e_science/jobs/HelloWorld.java for the job
- quartz-example/pack/src/webapp/WEB-INF/components.xml for the registration beans
- quartz-example/scheduler-jobs/pom.xml for any dependencies you might need to include ie Sakai API's
Note, if you use method #1, it seems like you have to use code to auto-register your triggers. In the init method for the bean I used this type of code. These fields have to match up with the values in your xml but will setup the cron trigger for this job. If you use Method 2, you can put it in the xml but it never registered for me from there outside of the scheduler.
Method 2: Modifying the existing jobscheduler to include your own jobs:
1. Use the sample job classes as examples. They're in:
A quartz job is just a class that implements the Job interface. It needs only one method, execute:
Oncourse uses many quartz jobs, feel free to use them as examples:
Also opensymphony has a tutorial on quartz: http://www.opensymphony.com/quartz/wikidocs/Tutorial.html
2. After creating your job class, edit:
and add your job class to the existing qrtzJobs property:
3. Redeploy the Scheduler tool and then following the instructions above on how to configure the Job Scheduler to run your job.
To see the old method of integrating Quartz with Sakai, see this article: Quartz Integration