Intermittent stalling on event with listener

Great. As a extra test/future monitoring, add a log event to occur when a timeout on jsoup occurs. So you can see in the logs when timeouts occur

Could you provide an example of how to do that in javascript? I’d definitely like to do that, as well as create an incident so I’m notified and can troubleshoot. Not quite sure how to set that up though.

Just print a line to the console. System.out.println. And you can do a search through the logs at a later date

Ok that sounds good. However, how to do I extract the information from the response, showing that there was a timeout?

Here’s the javascript I have so far, which includes a section for creating an incident based on the response code. Where and how would I add the println script based on the occurrence of a timeout?

// http request via jsoup
with (new JavaImporter(org.jsoup))
{

  // configure and send Jsoup http request
  var doc = Jsoup.connect('http://myurl.com/path/to/script.php?var=abc')
      //.method(Java.type('org.jsoup.Connection.Method').GET) // set the http method
      .method(Java.type('org.jsoup.Connection.Method').POST) // set the http method
      .header('Accept', 'application/json') // set the http header
      .header('Content-Type', 'application/json') // set the http content type
      // .data('filterABC', 'subgroup1')
      // .requestBody(JSON.stringify(body)) // set the http body
      .timeout(30000) // set the timeout limit to avoid camunda stalling issue
      .ignoreContentType(true) // This is used because Jsoup "approved" content-types parsing is enabled by default by Jsoup
      .execute() // send the http request

  // get response data into variables
  var resBody = doc.body() // get the response body
  var resStatusCode = doc.statusCode() // get the response status code
  var resStatusMessage = doc.statusMessage() // get the response status message
  var resContentType = doc.contentType() // get the response content type
  var resCharSet = doc.charset() // get the response character set

}

// create a function to 'spinify' so to remove unecessary "/n" characters from response data
function spinify(body)
{
  var parsed = JSON.parse(body)
  var stringified = JSON.stringify(parsed)
  var spin = S(stringified)
  return spin
}

// Process response status code
// take action based on status code
if ( resStatusCode < 200 || resStatusCode >= 300 ) {
  // there is an error, so create a camunda incident
  execution.createIncident("Http POST Failure", execution.getId(),"Http POST received a failure status code from the external script");
} else if ( resStatusCode >= 200 && resStatusCode < 300 ) {
  // no error, so do nothing
} else {
  // there is no status code, so create a camunda incident
  execution.createIncident("Http POST Failure", execution.getId(),"Http POST failed to receive a response status code");
}

You should wrap your jsoup in a Try/catch as the jsoup will throw a error if it times out. You can catch that error and subsequently throw another error after you log it. The second error you throw would be picked up by camunda and re-tried another 2 times as per the job retry system.

1 Like

Great. Would this be an appropriate approach? Not sure whether to throw a text or numeric error, or if that matters at all.

catch(error) {
  // print a line to the console
  System.out.println
  // throw an error
  throw "Jsoup Http POST timed out after 30 seconds"
}

Also, from what I can gather, camunda will create an incident after the 2 job retries end in error. Is that correct?

Sure. You should probably add the error message at the end so you can troubleshoot if needed.

And yes a incident will be created after the third attempt. If you are getting three timeouts in a row you likely have bigger issues going on.

Great, thanks again so much for your help! Things are setup much better now, and I’m learning more about how camunda works.