scheduled job running status

svani
Tera Contributor

Hi All,

 

I am running the scheduled job we have 1lakh+ records from the 3rd party to fetch so we are using rest message and calling in scheduled job but the issue is it is taking 3 hours to fetch all the records so it that okay to make schedule to run daily basis/weekly or anything we can do in order to reduce the processing time as i guess it may affect the other scheduled jobs.

 

only way i am getting is run in weekly basis on weekends

 

thanks,

Vidyashree

2 REPLIES 2

OlaN
Giga Sage
Giga Sage

Hi,

The scheduled jobs runs on separate nodes, so in most scenarios a long running job is not ideal, but it will not stop or hinder other jobs from getting processed.

A thing to look into, is if it would be possible to set up some other way of retrieving these records. A data source import might be faster than processing them with REST.

There might be other things you can do to optimize the processing the records, but all that would be guessing at this point since you haven't provided so much detail.

svani
Tera Contributor

Hi @OlaN ,

 

we are getting all open issues from JIRA through API so created a customized table in ServiceNow and puling project wise issues in to our table used below script for it.

var projid='';
var projName='';
var proKey='';
var proj=new GlideRecord('sn_jira_spoke_jira_to_servicenow_projects');
//proj.setLimit(5);
proj.orderBy('u_jira_project_name');
proj.query();
while(proj.next())
{
projid=proj.u_jira_project_id;
projName=proj.u_jira_project_name;
proKey=proj.u_jira_project_key;
gs.log("project name is"+proj.u_jira_project_name,"welcome");

var startat=0;
var r1 = new sn_ws.RESTMessageV2('JIRA-INCIDENT', 'GET Filter Issues');
r1.setStringParameterNoEscape('projID', proKey);
r1.setStringParameterNoEscape('startat', startat);
var response = r1.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

var parseBody = JSON.parse(responseBody);
//gs.log("response body" + responseBody,"welcome");
var total=parseBody.total;
//gs.log("total is"+parseBody.total,"welcome");
//var len = parseBody.issues.length;
//var inttotal=parseInt(total);*/
if(total != 0 || total != 'undefined')
{
for(var l=0; l<total; l=l+50)
{
//gs.log("going inside total length is" +l, "welcome");
var r = new sn_ws.RESTMessageV2('JIRA-INCIDENT', 'GET Filter Issues');
 r.setStringParameterNoEscape('projID', proKey);
 r.setStringParameterNoEscape('startat', startat);
 //r.setStringParameterNoEscape('startat', '0');
 var response1 = r.execute();
var responseBody1 = response1.getBody();
//gs.log("response body is"+responseBody1,"welcome");
var httpStatus1 = response1.getStatusCode();
var parseBody1 = JSON.parse(responseBody1);
var len1 = parseBody1.issues.length;
for (var a = 0; a < parseBody1.issues.length; a++)
{
 var resKey=parseBody1.issues[a].key.toString();
    var iss = new GlideRecord('u_all_issues_from_project');
    iss.addEncodedQuery('u_project_issue_key='+parseBody1.issues[a].key + '^u_proj_id='+projid);
    iss.query();
   if (!iss.next()) {
        iss.initialize();
        //gs.log("value of resKey"+resKey,"welcome");
        iss.u_project_issue_id = parseBody1.issues[a].id.toString();
        iss.u_project_issue_key = resKey;
        //gs.log("value of resKey"+iss.u_project_issue_key,"working");
       iss.u_project_name_issue_jira = projName;
       iss.u_proj_id = projid;
        iss.u_project_issue_summary = parseBody1.issues[a].fields.summary.toString();
        //gs.log("value of summary"+ parseBody1.issues[a].fields.summary.toString(),"welcome");
        iss.insert();
}
else{
    //do nothing
}
}
startat=startat+50;
}
}
else{
    //do nothing
}
}

as i increment to 50 because we will get 50 issues per result and also we need to loop through total length

and also facing issue like scheduled job is stopping after some time it is running properly