Scheduled tasks are instances of GridTasks with a predefined task type. These tasks are created by Platform for both time-based workflows and programmatically created schedules.
Time-based workflows allow you to define a workflow that will be executed on a schedule. For more information on creating time-based workflows, refer to the chapter titled Data and Process Modeling in Studio in this user guide.
Similar to time-based workflows, you can create schedules programmatically. These schedules must have their
GroupName and a
The schedule name is used to uniquely identify a schedule within a group. With both the group name and schedule name, you can enable, disable, add, remove, or run a single schedule.
You can specify the class that will run when the scheduled task executes by using the
ScheduleEntry.setRunnableClassName method. The class must implement the
java.lang.Runnable interface and must either have a no-arg constructor or a constructor accepting
JSONObject as its only argument.
This sets up the Example schedule in the Test group. When this schedule runs, it will execute the NoOpRunnable.run() method.
Next, we'll create the scheduler service.
You have a number of options in the way you run the Example schedule:
OnceOnlySchedule - This schedule type will only run once at the specified time. The following example will set Example to run at 11:00 AM on January 1st.
RepeatingSchedule - This schedule type will repeat on a given interval from whenever it starts. The following example will set an example to run every thirty minutes.
ComplexSchedule - This schedule allows you to configure a recurring schedule that will repeat at specific times of the year, month, or day. A ComplexSchedule is comprised of ComplexScheduleElements.
Delayed Execution - In some cases, you may want to delay execution until some time in the future. It is possible to disable an existing schedule. The following example shows how to delay a current schedule until the following day.
In addition to controlling when the schedule runs, you can override the maximum allowed duration and the maximum number of attempts for a schedule.
Refer to the javadoc for ScheduleEntry for more details methods and configuration options.
One caveat you should keep in mind with respect to schedules is that all schedules are created with the same task type, DTBScheduler. If your time-based workflow or schedule Runnable is long-running, it has the potential to starve out other scheduled tasks. In these cases, you can generate a separate GridTask as part of the workflow / Runnable and delegate the work to that task. Alternatively, you can configure the SchedulerConfiguration to suit your needs.