Brightspot CMS Developer Guide

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.

Previous Topic
Tasks
Next Topic
Schedule 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