Create a Custom Scheduled Job

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
(adding link to how to add jar files)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A scheduled job is a bit of code that is run on a regular basis by OpenCms.  You can create custom scheduled jobs by creating a java class that implements I_CmsScheduledJob.
+
A scheduled job is a bit of code that is run on a regular basis by OpenCms.  You can create custom scheduled jobs by creating a java class that implements I_CmsScheduledJob. OpenCms itself comes with some classes that do so, like [[CmsPublishJob]].
  
 
Then you add your Java class to OpenCms. You can either create a jar file, or a class file.  Then you add them to your OpenCms installation - your options are on the [[Adding_Jar_Files]] page.
 
Then you add your Java class to OpenCms. You can either create a jar file, or a class file.  Then you add them to your OpenCms installation - your options are on the [[Adding_Jar_Files]] page.
 +
 +
Follows an example of a JSP that gets its parameters from request and does the scheduling, found at this Nabble thread [http://www.nabble.com/Create-a-scheduled-job-from-jsp-to792114.html]:
 +
 +
<code lang="java">
 +
 +
<%@page import="org.opencms.main.*, org.opencms.scheduler.*, org.opencms.file.*, org.opencms.jsp.*, java.util.* "%>
 +
 +
<%
 +
CmsScheduledJobInfo csji = new CmsScheduledJobInfo();
 +
CmsScheduleManager csm = OpenCms.getScheduleManager();
 +
CmsJspBean cjb = new CmsJspBean();
 +
 +
cjb.init(pageContext,request,response);
 +
 +
CmsObject cmsObj = cjb.getCmsObject();
 +
CmsContextInfo cci = new CmsContextInfo(cjb.getRequestContext());
 +
 +
csji.setCronExpression("0 0/1 * * * ?");
 +
csji.setClassName("org.opencms.business.services.NewsLetterCmsScheduledJob");
 +
 +
csji.setActive(true);
 +
csji.setContextInfo(cci);
 +
csji.setJobName("boletin");
 +
 +
SortedMap parametros = new TreeMap();
 +
parametros.put("request",request);
 +
parametros.put("response",response);
 +
 +
csji.setParameters(parametros);
 +
csm.initialize(cmsObj);
 +
 +
csm.scheduleJob(cmsObj,csji);
 +
 +
%>
 +
 +
</code>
 +
 +
[[Category:Extending OpenCms]]

Latest revision as of 22:21, 12 January 2008

A scheduled job is a bit of code that is run on a regular basis by OpenCms. You can create custom scheduled jobs by creating a java class that implements I_CmsScheduledJob. OpenCms itself comes with some classes that do so, like CmsPublishJob.

Then you add your Java class to OpenCms. You can either create a jar file, or a class file. Then you add them to your OpenCms installation - your options are on the Adding_Jar_Files page.

Follows an example of a JSP that gets its parameters from request and does the scheduling, found at this Nabble thread [1]:

<%@page import="org.opencms.main.*, org.opencms.scheduler.*, org.opencms.file.*, org.opencms.jsp.*, java.util.* "%>
 
<%
CmsScheduledJobInfo csji = new CmsScheduledJobInfo();
CmsScheduleManager csm = OpenCms.getScheduleManager();
CmsJspBean cjb = new CmsJspBean();
 
cjb.init(pageContext,request,response);
 
CmsObject cmsObj = cjb.getCmsObject();
CmsContextInfo cci = new CmsContextInfo(cjb.getRequestContext());
 
csji.setCronExpression("0 0/1 * * * ?");
csji.setClassName("org.opencms.business.services.NewsLetterCmsScheduledJob");
 
csji.setActive(true);
csji.setContextInfo(cci);
csji.setJobName("boletin");
 
SortedMap parametros = new TreeMap();
parametros.put("request",request);
parametros.put("response",response);
 
csji.setParameters(parametros);
csm.initialize(cmsObj);
 
csm.scheduleJob(cmsObj,csji);
 
%>
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox