AnsweredAssumed Answered

Wait for a certain Task to finish without polling

Question asked by luckybtard on Feb 3, 2015
Latest reply on Feb 4, 2015 by luckybtard

i have the following Scenario:

There is a relatively complex Process i implemented using the Activitiengine. it consists of roughly 12 Tasks. Lets assume they are all in sequence for simplicity.

1) A User requests POST to the RESTfull Webservice at: "/rest/start".
2) The Servlet starts a Processinstance with the parameters supplied.
3) The User is obviously waiting for a reply from the Webserver, this reply can be formed right after Task #3 of the 12 is finished.

My implementation at the moment is:
Insert a Usertask after Task #3 that consists of a Form with the reply-parameters, all read-only. (Task #1-#3 are input-checks of sorts)
The Servlet that started the Process, polls the Engine for this Task with the given Businesskey (ever 100ms it checks if the Task "Userreply" is present in the Processinstance with given Businesskey).
If the Task is present, the values are read and the reply for the User is built and sent. Then the Servlet submits the Form and the Process continues.

I do not like this solution, because i don't like the look of Thread.sleep(100), it is unclean, error prone and bound to result in all sorts of wierd raceconditions, once the Service goes online.

My Question is:
Are there any ideas on how to solve this without polling the Engine? Even a type of http-like "Long-polling" would be an improvement for me, unfortunately i don't know how to do it with Activiti

My ideas so far:
1) let the Client poll a status resource for the wanted results, but this only shift the polling to another location.
2) handle Task #1-#3 outside the Processengine, which would take the advantage of the engine

Thanks for any further input!