js.work.getCheckpoint

From Web Computing Documentation
Revision as of 10:59, 11 July 2011 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Description

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.

Examples

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
}
else
{
    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
    i++;
}

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
Modules