script for Kill schedule jobs running more than 30 mins

Dhanu1
Tera Contributor

Hi All,

Can anyone help me to write script for kill the scheduled jobs running more than 30 mins.

we have option to manually kill but we need to automate by checking the age > 30 mins

Thanks in advance


1 ACCEPTED SOLUTION

Mohan raj
Mega Sage

Hi @Dhanu1,

 

Try this code 

 

var trigger = new GlideRecord('sys_trigger');
trigger.addQuery('state',1)//state is running
trigger.addQuery('processing_duration','<','1800000')//scheduled jobs running more than 30 mins
trigger.query();
while(trigger.next()){
    GlideTransactionManager.kill(current.session_id);
}

 

​If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards

Mohan

View solution in original post

3 REPLIES 3

Mohan raj
Mega Sage

Hi @Dhanu1,

 

Try this code 

 

var trigger = new GlideRecord('sys_trigger');
trigger.addQuery('state',1)//state is running
trigger.addQuery('processing_duration','<','1800000')//scheduled jobs running more than 30 mins
trigger.query();
while(trigger.next()){
    GlideTransactionManager.kill(current.session_id);
}

 

​If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards

Mohan

Pratima G
Tera Contributor

where can we use this script ? can we use it directly into the scheduled job to check if it is running for more that 30 minutes ?

karthick8
Tera Contributor

GlideTransactionManager.kill(session_id);  is not working in script background

.