Create Jobs and Freeze application in Netgem

Posted By : Raman Joshi | 26-Sep-2014

Hi Friends in this blog we understand that how we can create the jobs and freeze application in netgem. In this example we have to create myListFormWidget.js file and define the long script which will be execute for several seconds. If you press any key during this time, execution ofkey handling code will be paused untill script finishes. Here we block during 10s.

 for (var i = 0; i < 20; i++) {  
    BlockDuringInMs(500);  
}  
 
 

Now we create the job for which first parameter is name which is usefull to identify it during debug process. For each part of the process, simply add a callback to the JSJob and they will be executed asynchronously. Below is the code for creating the job in which callbackmust return true, else job execution will be stopped.

var job = new JSJob("Test");  
  
for (var i = 0; i < 20; i++) {  
    job.jobAdd(this.jobCallback.bind(this));  
}  
  
job.jobAdd(this.endOfStep2.bind(this));
 
 

The jobCallback function will receive the job as parameter. Callback must have to return false to abort job and true to execute next job.

 MyFormWidget.prototype.jobCallback = function jobCallback(job)  
{  
    BlockDuringInMs(500);  
    return true;  
} 
 
 

Now we create the new job in this array parsing can be easily done with a sepcific listAdd API. The callback is called for each index on the array. When the loop lasts too long, the job is reschedule.

 var job = this.job = new JSJob("Test");  
  
job.listAdd(new Array(20), this.listCallback.bind(this));  
  
job.jobAdd(this.endOfStep4.bind(this)); 
 
 

Function listCallback will receive the current index, current object and job. Callback must have to return false to abort job, true to keep array parsing and "abort" to abort array parsing and execute the next job.

MyFormWidget.prototype.listCallback = function listCallback(index, data, job)  
{  
    NGM.trace("Index = " + index);  
    BlockDuringInMs(500);  
    return true;  
}
 
You can cancel/stop a job any time by this code.
this.job.stop();  
 

This is the example of creating the jobs and freeze application in which you see some of the important functions.

 
Thanks
 

 

About Author

Author Image
Raman Joshi

Raman is a bright web app developer with experience in Java , Groovy and Grails frameworks

Request for Proposal

Name is required

Comment is required

Sending message..