The CreatorCon Call for Content is officially open! Get started here.

Does gs.sleep() have any significant impact on the instance especially with other concurrent jobs?

Rain Vaine
Kilo Sage

Hello experts,

Do any of you have any idea on the significant impact of gs.sleep() method on the instance. We are planning to use gs.sleep to introduce a stopper for our script so that the loop would only run after every 5 minutes.
Sample below is our application of gs.sleep():

 

for (var count = 0; count < 5; count++)
{
gs.sleep(60000);

var diag = new Diagnostics();

while (diag.nextNode()) {
var diagNode = diag.getNode();
var nodeName = diagNode.name;
var usedMemory = diagNode.stats['system.memory.in.use'];
var totalMemory = diagNode.stats['system.memory.total'];
var detectDate = gs.nowDateTime();
var freeMemory = totalMemory - usedMemory;

//code for storing values into custom table
var grStoreMemory = new GlideRecord('u_store_memory_info');
grStoreMemory.initialize();
grStoreMemory.u_used_memory = usedMemory;
grStoreMemory.u_total_memory = totalMemory;
grStoreMemory.u_free_memory = freeMemory;
grStoreMemory.u_detected_date = detectDate;
grStoreMemory.u_node_name = nodeName;
grStoreMemory.insert();
}
gs.info(count+1 + 'minute has passed');
}

 

Will these method have significant impact on our instance especially on concurrent jobs, or other transactions. I actually tried running this in the background and while it is running I cannot do other tasks on my PDI. If I ever migrated this script in either script actions or scheduled job, will these have an effect?

Thanks,

Vaine

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Rain Vaine 

first you need to decide if gs.sleep() is actually required as part of your code?

What's your business requirement?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

We need to need to create a certain script action that will execute 5 times with 1 minute interval. We decided to use gs.sleep so that we can set a delay of 1 minute for it to run again 5 times. Do you know of any signifant impact it can cause on other scheduled job?

 

RainVaine_0-1678842406438.png

 

As you could see in the script action there is no settings that can be set for the script to run 5 times at 1 minute interval.

Do you know of any alternative to gs.sleep that can be used to make the script only run after every minute?

@Rain Vaine 

you can use gs.eventQueueScheduled() and schedule 5 events and time span of those 5 will be 1 min apart.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader