OpenCms allows jobs to be run at a certain date and time, or to repeat jobs at a certain interval. A whole set of useful jobs is already predefined and can be configured. But you can also write, configure and schedule your own jobs. We describe how to schedule an already defined job and provide a short description of the already predefined jobs.
Many actions you may want to take place instantly. But for some actions there are good reasons to perform them at a certain time or date, or to automatically repeat them at a specified time interval. For example:
The reason for executing a task scheduled for one-time execution may have two different reasons. Either the task's result should not appear before a certain date, or the task is resource intensive and should be performed at a time when your website is not visited too often, e.g., overnight.
In the administration view, you'll find the "Scheduled Jobs" administraion. When you click it, the "Scheduled Jobs Management" opens.
The "Scheduled Jobs Management"-view provides options to create a new job and to view the list of existing jobs.
The list's colums show:
Using the "Search" option, you can filter jobs in the list by their name. By the options on the right-hand side above the list, you can show or hide information about the context and the parameters configured for a job, or show a printable version of the job list.
For adding a new job or editing an existing job, a form appears. It has two pages, where on the first page you provide information necessary for every job, and on the second page you can set parameters handed over to the Java class that executes the job.
On the first page of the dialog for editing jobs, as shown in Figure [edit_scheduled_job], you first get displayed the current server time and then you can fill out the following options for the job.
Name of the job used in the job list.
Java class that executes the job. The class has to implement
org.opencms.scheduler.I_CmsScheduledJob. There are several classes shipped with OpenCms. They can be selected via a drop-down list.
A cron expression that specifies when the job should be executed. See below for the syntax of cron expressions.
If checked, an instance of the class executing the job is created only when the job is executed the first time. The instance is then used for all repetitions of the job. If unchecked, the job is performed by a new instance each time.
If checked the job performed at the specified dates (see the cron expression). If unchecked, the job is still listed, but not performed.
In another box, you have to provide context information. Each job performed in OpenCms must be performed in a context, i.e., by a user, in a project, for a locale, etc. The context specific settings are:
Name of the user that is used to execute the job.
Project in which the job is executed
The site root to which URLs are relative. By default this is "
The requested URI set in the context used when the job is executed. By default it is "
The locale set in the context used when the job is executed. By default it is "
The character encoding set in the request context used to execute the job. By default it is "
The remote address set in the request context used to execute the job. By default it is "
The parameters configured at the second page depend only on the Java class that executes the job. So look the available parameters up at the respective classes.
OpenCms already ships with classes to perform typical jobs. Here's a brief description of the classes. For further information consult the JavaDoc.
Checks internal relations and sends the result via email.
Supports time based publishing of a project.
Creates a complete static export of a site.
Checks external links (resource type "pointer").
Writes information about the server's memory usage to the OpenCms log-file.
Rebuilds search indexes.
Sends notification emails to responsible users if content has not changed in a certain time period or is released or expired.
Checks the size of all images in the OpenCms VFS and downscales them if configured.
Clears the image cache for scaled images that exceed a specified age.
Clears the file history.
Deletes expired resources.
Unsubscribes deleted resources.
The configuration of scheduled jobs is saved in the
opencms-system.xml. Instead of using the graphical user interface in the administration view, you could also directly write the job configurations into
opencms-system.xml. Here's an example configuration:
<scheduler> <job> <name>Search index</name> <class>org.opencms.search.CmsSearchManager</class> <reuseinstance>false</reuseinstance> <active>true</active> <cronexpression>0 15 1 * * ?</cronexpression> <context> <user>Guest</user> <project>Online</project> <siteroot>/sites/default/</siteroot> <requesteduri>/</requesteduri> <locale>en</locale> <encoding>UTF-8</encoding> <remoteaddr>127.0.0.1</remoteaddr> </context> </job> </scheduler>
If necessary, you can write your own job classes. The class must implement the interface
org.opencms.scheduler.I_CmsScheduledJob, which specifies the method
that is called with an CmsObject, instantiated according to the context specified for the job and a map containing all the specified parameters and their values.