Scheduled Schema Methods in Structr

I recently pushed a small change to the master branch of Structr that allows you to configure the periodic execution of StructrScript / server-side JavaScript methods in structr.conf.

CronService

In case you didn't know, Structr has a built-in scheduling service that can execute periodic tasks. It is configurable with a syntax very similar to the one of the UNIX crontab file, hence the name CronService.

Example

With this change, the CronService gains the ability to execute scripts stored in a SchemaMethod instance. To use that feature, create a new object of type SchemaMethod in the Structr Backend, set a name, and put the desired scripting code in the source field.

You can then configure the periodic execution of your method in the structr.conf file like this:

# Configure two periodic tasks
CronService.tasks = countUsers createReports

# Run countUsers every day at 4:00
countUsers.cronExpression = 0 0 4 * * *

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

Availability

You will find the new feature in the current master branch on GitHub, or in the next snapshot of Structr 2.1.0 which will be released shortly.

Share this post

Comments