Skip to content

Task scheduler

elandau edited this page Nov 30, 2012 · 9 revisions

Experimental and not yet released !!!

Overview

This is a Quartz like task scheduler where you can register a task class, task metadata and scheduling details. The recipe builds on top of the Durable Message Queue recipe for scheduling the next execution time and persists task details in a separate column family.

Data Model

TODO

Examples

Setting up the scheduler

The first step to using the scheduler is to create a DistributedTaskScheduler instance.

TaskScheduler scheduler = new DistributedTaskScheduler.Builder()
    .withBatchSize(5)
    .withKeyspace(keyspace)
    .withName("TestScheduler")
    .build();

Scheduling a task

First, you must define a task processing class.

public class HelloWorldTask implements Task {
    @Override
    public void execute(TaskInfo task) {
        System.out.println("Hello World!");
    }
}

Next, schedule a task and give it a trigger. This example shows how to create a task that will execute every hour starting from now and will repeat 5 times. The scheduler will also keep a status history of every task execution.

      scheduler.scheduleTask(
          new TaskInfo.Builder()
              .withKey("MyHelloWorld")
              .withClass(HelloWorldTask.class)
              .withHistory(true)
              .build()
          , 
          new RepeatingTrigger.Builder()
              .withInterval(1, TimeUnit.HOURS)
              .withRepeatCount(5)
              .build()
      );

Stopping a task

Resuming a task

Deleting a task

Reading task history

Clone this wiki locally