Fachartikel

How to prevent a STEP business rule running in a loop

2023-04-06 Femila Jesline
foryouandyourcustomers icon shows a person running in a loop.

While the usage of loops make coding much easier, there is always the danger of the loop running forever due to a typo or faulty logic.

I was privileged to visit Europe for our company’s Yearly Group Meeting last year. Being in Europe for the first time, we wanted to explore the town before the meeting started. So we started the day early and went for a walk. We took a few turns and saw a beautiful clock tower. Took a few pictures and were on our way again, only to end up in the same place after a few turns. This happened at least five times until one of us discovered a sneaky pathway we missed.

I happened to find myself in a similar situation again recently, except that it was my business rule in Stibo STEP Master Data Management software running in a loop this time. Identifying the issue with the looping business rule was easy, but preventing it from happening without server restarts was the hard part. Fortunately, with our combined expertise at foryouandyourcustomers, we found a way around this problem, and that is what I will be sharing. I hope this helps others to avoid getting stuck in a loop.

Solution

The workaround involves getting the thread ID from the STEP system administrator and then running a business rule that kills the thread.

Below are the steps that need to be followed:

  1. Go to the URL and click on STEP System Administration (under Resources).

  2. In the “Activity” tab, click on “Fetch data”. This will give you the list of all active services running on the server.

  3. Expand the method with the highest duration. Keep expanding until you find a method being run by your user ID, and check if the details resonate with the loop you are running.

  4. Scroll towards the right of the method mentioned in step 3 and hover over the value in the “Active” row. You will see an ellipsis. Click on the ellipsis to show the details of the thread.

  5. Copy the thread value.

  6. Log in to the workbench. (Caution: If you have multiple servers, make sure that you log in to the server detail displayed in step 3.)

  7. Create a business rule with the below code (replace the thread ID with the one copied in step 4):

// Replace the value of  threadToStop with the Thread ID from the adminPortal:

var threadToStop = "qtp122491942-38230";

var console = { log: function (msg) { logger.info(msg); } };

function stopThread(T) 

{

var keyIter = T.keySet().iterator(); // Get thread from the map(stack trace)

while(keyIter.hasNext())

{

var key = keyIter.next();

if(key.toString().indexOf(threadToStop) >= 0)  // If key matches the threadId

{

key.stop();

return "Thread stopped";

}

}

return "Thread not found";

}

console.log(stopThread((java.lang.Thread()).getAllStackTraces())); //Get the map of stack traces for all live threads

Source code example

Please note that in some instances, running this business rule has caused issues. So use caution, and try this only in Dev or QA.

Contact us

Have you encountered similar issues using STEP? How did you solve them?

For help and advice on this and other STEP-related challenges, don't hesitate to reach out to us (melbourne@foryouandyourcustomers.com). We would be happy to help. For more information about what we do, check out this video.