Creating a background task


The com.psddev.dari.util.Task class is the base task class. It contains basic execution control and status methods. For example, you can schedule start times, run once or repeatedly with periodic delays, pause and resume execution, and display status.

You can create a background task by extending the abstract Task class and implementing your task logic in the Task#doTask method. For example, in the following snippet for an anonymous class, a new MigrationTask is created, appearing in the Migration category of the Task Status tool. For each execution of the doTask method, the system increments the task’s run count by one.

public MigrationTask() { 
    task.submit();
}

Task task = new Task("Migration", "Migration Task") { 
    @Override
    public void doTask() throws Exception {
        boolean done = false;
        while(!done && shouldContinue()) {
        /* Do processing here */
        }
    }
}
  • Constructor that runs the submit method. This method starts the task immediately and runs it one time.
  • Anonymous class that implements the doTask method. It is a best practice to call shouldContinue on each iteration of the loop to determine if the task has stopped or paused in the Task Status tool.

As an alternative to the submit method, you can schedule a task to run repeatedly in periodic intervals. For details, see Schedule tasks.

The elements that get you up and running in a matter of days, from pre-built content types, to modules, to landing pages.

Content types
Modules
Landing pages
Everything you need to manage and administer content within Brightspot CMS.

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

Field types
Content modeling
Rich-text elements
Images
A guide for configuring different integrations to support a multitude of use cases.

Google Analytics
Shopify
Apple News