Long Running Transaction

Kalaiarasan Pus
Giga Sage

This is question related to transactions which for some reason gets stuck and runs in the background utilizing system resources and slowing the instance down....

 

Whenever the instance is slow, i tend to check "All Active Transactions" menu and manually kill the transaction (ofcourse on the Developement instance)....

 

But I am just curious if anybody has some automated script or something that we can use to kill the long running transaction rather than manually going to the menu and killing it ....

1 ACCEPTED SOLUTION

Actually I created a UI page for this and have it on my home page on our development instance ... You have a script and a UI page in this ... Hope this helps ...



Script include:


var ScriptUtils= Class.create();




ScriptUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  killOldTransactions : function(){


  try


  {


  var transactionCount = 0;


  var getTransaction = new GlideRecord('v_transaction');


  getTransaction.addEncodedQuery("age>javascript:gs.getDurationDate('0 0:10:0')");


  getTransaction.query();


  while(getTransaction.next()) {


  transactionCount++;


  GlideTransactionManager.kill(getTransaction.session_id.toString());


  }



  if(transactionCount == 0)


  {


  return 'No Transaction Were Cancelled';


  }


  else


  {


  return transactionCount + ' Transactions were cancelled';


  }


  }


  catch(err)


  {


  return 'Error While Cancelling Transaction-'+err;


  }


  }



});




Ui page:


HTML:


<html>


<head>


</head>


<body>


<TABLE>


<TR>


<TD colspan='2' align="center"><input type="button" value="Cancel" onclick="cancelTransaction()"/> </TD>


</TR>


</TABLE>


</body>


</html>




Client Script of UI page:


function cancelTransaction(){


  var cancelTrasaction = new GlideAjax("ScriptUtils");


  cancelTrasaction.addParam('sysparm_name','killOldTransactions');


  cancelTrasaction.getXMLWait();


  alert(cancelTrasaction.getAnswer());


}


View solution in original post

6 REPLIES 6

AdityaTW
Mega Contributor

I am not sure if I would want to automate this type of activity. There needs to be some kind of manual review and analysis in place before we kill a transaction. Just my opinion


agree.. but I need this only for development instance


Kalaiarasan Pus
Giga Sage

i managed to write a simple script and reused the code of kill button ..... will post the solution later once I get time...


mitzaka
Mega Guru

Could you share that please?:)


I am just in the process of running some background scripts which clean the cmdb_rel_ci table and the are taking quite a while (considering my table has over 2 million records in it)...



Thanks in advance!