Brightspot CMS Developer Guide

Repeating tasks


Although the base Task class provides methods to schedule tasks to run with periodic delays, the com.psddev.dari.util.RepeatingTask class provides enhanced interval control. A subclass of Task, RepeatingTask adds interval-control methods based on Joda Time. For example, you can call methods to run an implementation every minute, hour, or day. You can also adjust intervals at run time based on conditional testing.

A repeating task requires that you implement calculateRunTime and doRepeatingTask. calculateRunTime determines the run time intervals of the repeating task. Passed a Joda DateTime object representing the current time, calculateRunTime returns a DateTime object representing the run time interval, such as minute, hour, or day. The doRepeatingTask method implements the task logic.

When a repeating task instance is created, the Dari framework calls the concrete RepeatingTask#doTask method, which controls the run-and-delay intervals of the implementation. doTask first calls calculateRunTime. Based on the DateTime object returned, doTask evaluates whether the implementation should delay or execute. If doTask evaluates to execute, it passes the DateTime object to the doRepeatingTask method. After doRepeatingTask executes, the framework increments the task’s run count by one and returns control to doTask.

The following snippet implements the data migration as a repeating task. Called automatically by the framework, the constructor sets the name and the category of the task that displays in the Task Status tool.

The calculateRunTime implementation simply specifies that the task repeat execution every minute. However, calculateRunTime can be implemented to test run time conditions and adjust execution intervals if need be.

ublic class MigrationTask extends RepeatingTask {

    public MigrationTask() {
        super("Migration", "Migration Task");
    }

    @Override
    public DateTime calculateRunTime(DateTime currentTime) {
        return everyMinute(currentTime);
    }

    @Override
    public void doRepeatingTask(DateTime currentTime) throws Exception {

        /* Do processing here. */
    }
}

Previous Topic
Schedule tasks
Next Topic
Recalculation tasks
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News