{"id":842,"date":"2016-10-07T00:00:00","date_gmt":"2016-10-07T00:00:00","guid":{"rendered":"https:\/\/structr.com\/scheduled-schema-methods\/"},"modified":"2025-03-15T13:07:30","modified_gmt":"2025-03-15T13:07:30","slug":"scheduled-schema-methods","status":"publish","type":"post","link":"https:\/\/structr.com\/en\/blog\/scheduled-schema-methods\/","title":{"rendered":"Scheduled Schema Methods in Structr"},"content":{"rendered":"<p>I recently pushed a small change to the master branch of <a href=\"https:\/\/github.com\/structr\/structr\" target=\"_blank\" rel=\"noopener\">Structr<\/a> that allows you to configure the periodic execution of StructrScript \/ server-side JavaScript methods in structr.conf.<\/p>\n<h4 id=\"cronservice\">CronService<\/h4>\n<p>In case you didn&#8217;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 <code>crontab<\/code> file, hence the name CronService.<\/p>\n<h4 id=\"example\">Example<\/h4>\n<p>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 <code>SchemaMethod<\/code> in the Structr Backend, set a name, and put the desired scripting code in the <code>source<\/code> field.<\/p>\n<p>You can then configure the periodic execution of your method in the <code>structr.conf<\/code> file like this:<\/p>\n<pre># Configure two periodic tasks\r\nCronService.tasks = countUsers createReports\r\n\r\n# Run countUsers every day at 4:00\r\ncountUsers.cronExpression = 0 0 4 * * *\r\n\r\n# Run createReports each hour on Mondays during the first 10 days in April and October\r\ncreateReports.cronExpression = 0 0 * 1-10 4,10 1\r\n<\/pre>\n<h4 id=\"availability\">Availability<\/h4>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently pushed a small change to the master branch of Structr that allows you to configure the periodic execution \u2026<\/p>\n","protected":false},"author":8,"featured_media":2475,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[31,24],"tags":[420,449,494,485,490,475,479,489,486,488,487,405,281,493,491,492],"class_list":["post-842","post","type-post","status-publish","format-standard","hentry","category-announcement","category-structr","tag-automation","tag-backend","tag-configuration","tag-cronservice","tag-crontab","tag-devops","tag-javascript","tag-periodicexecution","tag-scheduling","tag-scripting","tag-server-side","tag-softwaredevelopment","tag-structr","tag-structrscripting","tag-systemadministration","tag-taskautomation"],"acf":[],"_links":{"self":[{"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/posts\/842","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/comments?post=842"}],"version-history":[{"count":3,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/posts\/842\/revisions"}],"predecessor-version":[{"id":2310,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/posts\/842\/revisions\/2310"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/media\/2475"}],"wp:attachment":[{"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/media?parent=842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/categories?post=842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/structr.com\/en\/wp-json\/wp\/v2\/tags?post=842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}