You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

Periodic command scheduling

Structr provides a service for periodic command scheduling: the CronService.

The CronService is a background service that can be configured in the structr.conf configuration file to schedule the execution of periodic tasks. Tasks in this context are either names of schema methods, or fully qualified Java class names of a class implementing the Task interface from the Structr Java API.

The main configuration key for tasks is CronService.tasks. It accepts a whitespace-separated list of schema method names or java class names.

CronService.tasks = cleanUpMethod1 org.structr.example.PeriodicExampleTask exampleMethod

For each of the entries in the above line, you can configure an execution time and date similar to crontab entries in Unix-based operating systems.

The cronExpression in Structr can be configured as <methodName>.cronExpression = <s> <m> <h> <dom> <m> <dow>.
Structr will then run the specified tasks with the configured frequency as the admin user.

Field Explanation
<methodName> name of the global schema method
<s> seconds of the minute
<m> minute of the hour
<h> hour of the day
<dom> day of the month
<m> month of the year
<dow> day of the week

Examples

# Run every 30 minutes
cleanUpMethod1.cronExpression = 0 0,30 * * * *

# Run every 15 minutes
cleanUpMethod2.cronExpression = 0 */15 * * * *

# Run every day at 4:00
org.structr.example.PeriodicExampleTask.cronExpression = 0 0 4 * * *

# Run each hour on Mondays during the first 10 days in April and October
exampleMethod.cronExpression = 0 0 * 1-10 4,10 1

Search results for "Periodic command scheduling"

We could not find anything matching "Periodic command scheduling" in our documentation. Please rephrase your search.

You can also ask your questions in the Structr Google Group or create a free account in the Structr Support Portal.
Click here to send feedback to the Structr team.