From Web Computing Documentation
Jump to: navigation, search


Creates a checkpoint on the persistent storage.

js.work.setCheckpoint( state )

state An arbitrary object containing data necessary to continue the workunit.

The function saves the state object and the output streams to the persistent storage. You can use js.work.getCheckpoint to retrieve the checkpoint.


var i;                                         //input parameter of the calculation
var partialResult;
var checkpoint = js.work.getCheckpoint();      //retrieving potential checkpoint
if(checkpoint != null)
    i = checkpoint.i;                          //there was a previous checkpoint, loading i
    i = 0;                                     //no previous checkpoint starting from 0
    checkpoint = {};
while(i < 100)
    partialResult = Calculate(i);              //our function doing the calculations
    js.output.writeLine("myOutputStream", partialResult);
    checkpoint.i = i;
    js.work.setCheckpoint(checkpoint);         //saving checkpoint

The example demonstrates the usage of the checkpointing feature. You can use js.work.setCheckpoint without any particular setup simply by calling it with an object in its argument. By doing this the object checkpoint and the stream myOutputStream are saved to the persistent storage. If you use other streams in other parts of your code those will be saved as well.

The next time js.work.getCheckpoint is called it will return the object saved previously while restoring the output streams.

Personal tools