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

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 ?

Amit Gujarathi
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.');
}