RE:5 tips to improve usage of the Liferay script console

// In reply to 5 tips to improve usage of the Liferay script console - by Sébastien Le Marchand

Sébastien wrote a very good article about Liferay script console. Here is one more tip in response of the call for sharing at the end of the article. I post it as a sepreate blog entry because I cannot use Gist or format in comment area....


Tip #6: Schedule your script to run as a CRON job

If you want to schedule your script to execute at certain times as a CRON job (One scenario can be: Run the task "deactivate users never logged and created since more than 2 years" every month.), you can use Liferay's Scheduler Engine API, like in the following example:
The following code outputs the string "test" to a file one time per minute in the next 10 minutes:
You can change your job schedule by changing the parameters in CronText constructor.
You will also need to use proper escape characters in the script.
Note that when Liferay Scheduler Engine execute the script, the following predefined variables are not available:
  • out (
  • actionRequest (javax.portlet.ActionRequest)
  • actionResponse (javax.portlet.ActionResponse)
  • portletConfig (javax.portlet.PortletConfig)
  • portletContext (javax.portlet.PortletContext)
  • preferences (javax.portlet.PortletPreferences)
  • userInfo (java.util.Map<String, String>)