Showing posts with label Liferay Scheduling. Show all posts
Showing posts with label Liferay Scheduling. Show all posts

Wednesday, August 7, 2013

Liferay Scheduler -- Simple/Cron Setup

This is a small post but very important for those who want to learn scheduling and who works on batch, automated tasks. Here, I am explaining how you can use liferay's simple & easy scheduling framework to automate your tedious day2day tasks.

I'm not kidding you can easily schedule your task with Liferay inbuilt Quartz scheduler with below mentioned 5 simple steps:

1) Create a sample Liferay portlet where you want to implement your scheduler. You can create Generic,MVC or Spring.Scheduler is independent of the framework.

2) Make the following change in "liferay-portlet.xml" file.

3) Define the scheduler time in "simple-trigger-value" or "cron-trigger-value" tag.

4) Implement a scheduler class in your src folder. You can implement the method in your normal class  also but I would prefer creating a separate class. Implement "MessageListener" interface of Liferay and implement the unimplemented method of that interface.
"com.liferay.portal.kernel.messaging.MessageListener"
Paste the below code in your scheduler implementation class:
 

5) Deploy and scheduler will run at the defined time.

See, all is done in simple 5 steps.

Now, lets take them one by one. Creating a portlet is simple and an IDE do that for you easily.

Next, we created an entry in "liferay-portlet.xml". In this entry we are telling liferay about our scheduler class and which method to trigger.
Don't change the name of method from "receive" to something else.I wrote "receive" because I implemented Liferay's MessageListener interface which handles scheduler call.

At Last, we are telling liferay that whether we are using Cron job or simple job.
For Cron, I would recommend you to read about Cron implementation from Cron Tutorial.
In Simple job, we simple defined our task time-interval along with the unit (seconds,minute or hours).

Visit below link to create your own Cron expression with a user friendly interface: Cron Maker

Feel free to post your questions and doubts. Happy Learning :)