Monday, October 27, 2014

Scheduling a simple logic in Batch

This post shows the steps for executing a simple class in Batch processor.

Step 1 

Create a simple class which extends from "RunBaseBatch" class with following methods.

class Batch4DemoClass extends RunBaseBatch
{
}

public container pack()
{
    return conNull();
}

public void run()
{
    // The purpose of your job.
        info(strFmt("Hello from Batch4DemoClass .executed at %1"
            ,DateTimeUtil ::toStr(
                DateTimeUtil ::utcNow())
            ));
}

public boolean unpack(container packedClass)
{
    return true;
}

Step 2 

Now create a simple job to add the class execution in Batch processor.

BatchHeader     batchHeader;
BatchInfo       batchInfo;
RunBaseBatch    runbasebatchTask;
str             sParmCaption = "My Demonstration (b351)";
    
//Creating Batch4DemoClass object
runbasebatchTask = new Batch4DemoClass();
    
//Assigning BatchInfo from RunBaseBatch task
batchInfo = runbasebatchTask.batchInfo();
batchInfo.parmCaption(sParmCaption);
batchInfo.parmGroupId(""); // The "Empty batch group".
    
//Creating BatchHeader and adding it to BatchQueue
batchHeader = BatchHeader::construct();
batchHeader.addTask(runbasebatchTask);
batchHeader.save();


info(strFmt("'%1' batch has been scheduled.", sParmCaption));





1 comment:

  1. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks...

    ReplyDelete