Automate killing of long running scheduled job

Pratima G
Tera Contributor

Hi all,

 

We have a requirement from customer that if scheduled Job is running for more than an hour , it should be stopped automatically.
Is there any way to automate this procedure ? if so, where can we add the required steps ?

 

Thanks,

PG.

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Pratima G 

 

https://www.servicenow.com/community/developer-forum/how-to-cancel-a-scheduled-job-that-is-currently...

 

https://www.servicenow.com/community/developer-forum/how-to-cancel-a-schedule-job-that-is-running/m-...

 

https://www.servicenow.com/community/developer-forum/kill-the-scheduled-job/m-p/1989129

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hey Atulya,

 

Thank for the links.

However if I want to automate this code , how can I do it ? I tried with a flow designer but i could not find any element which connects from executed scheduled job and the active transaction table.
How can we query a particular scheduled job transaction in Active Transactions ?

Hi @Pratima G 

 

Sorry I am not a pro here, may be you can see:

 

https://docs.servicenow.com/bundle/vancouver-platform-administration/page/administer/platform-perfor...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Amit Gujarathi
Giga Sage
Giga Sage

HI @Pratima G ,
I trust you are doing great.
Please find the code as given below

var gr = new GlideRecord('sys_trigger');
gr.addQuery('next_action', '<', 'javascript&colon;gs.minutesAgo(60)');
gr.addEncodedQuery('state=0^name= Reminder CDB datapurge admin^next_action<javascript&colon;gs.beginningOfCurrentHour()');
gr.query();
while (gr.next()) {
    // Logic to determine if the job is still running and needs to be stopped
    // Implement your stopping mechanism here

    // Log or notify
    gs.info('Job ' + gr.name + ' has been running for more than an hour and was stopped.');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi