From Web Computing Documentation
Jump to: navigation, search


Retrieves the latest checkpoint data from the persistent storage. If checkpoint data is present it returns the checkpoint object, otherwise it returns null.

js.work.getCheckpoint( state )

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

The function retrieves the state object and the output streams from the persistent storage. You can use js.work.setCheckpoint to save 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.getCheckpoint without any particular setup simply by calling it with an object in its argument. By doing this the object checkpoint and all streams are restored from the persistent storage.

Personal tools