cancel
Showing results for 
Search instead for 
Did you mean: 

Thread sleep or timer?

jhahn
Champ in-the-making
Champ in-the-making
Hi,

I have a script task that will hit an API to check if a job is finished.
I need to keep checking the API every few minutes and if the job is not finished within an hour, I need to send a notification (but keep checking the API until it's finished).

while (jobNotFinished) {
  hit API.
  if (jobFinished) {
     break;
  } else {
     thread.sleep(5mins);
  }
}

and I'll have a boundary timer event set to jobStartTime + 1hour to send a notification.

Is this the correct way? What would happen on a server restart if it's in the while loop?

I've thought about having an exclusive gateway that will point back to the task but not sure how I would setup a boundary timer so that it doesn't run again when it keeps running the task every 5 mins even after 1hour has past. I could set a variable to mark it as sent, but that doesn't sound "right"?

Any insight would be helpful to this BPMN noob.
1 REPLY 1

yvoswillens
Champ in-the-making
Champ in-the-making
Hi,

I think the describe implementation is correct. As long as the Boundary Timer Event is non interrupting (cancel activity property).
In case of a server restart and the scripttask (and perhaps other steps that are part of that transaction) isn’t finished the transaction will rollback.
So if f.e. the script task is async the process instance will continue there when the server is up.

Regards,

Yvo