BatchJob example


#1
entity type MyJob extends BatchJob<MyJob, MyJobOptions, MyBatch> type key 'my_job' {

  doStart      : ~ js server
  processBatch : ~ js server
  allComplete  : ~ js server
}

Define the job options

type MyJobOptions {
  // fields go here
}

Define the batch

type MyBatch {
  // fields go here MyBatch
}

The implementation of the different functions in MyJob.js

function doStart(job, options) {
  // create instances of MyBatch
  var batches = MyBatch.array();
  ...
  // trigger the processing of those batches
  job.scheduleBatches(batches);
}

function processBatch(batch, job, options){
  // batch logic goes here
}

function allComplete(job, options) {
  // happy ending for all batches, or not?
}