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

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());


}


Thanks, that's useful!