I have a work like recording video from live tv that length too long. it should be done with an External Task. as it is a very long process, I need a notify progress that shows how much of the video is recorded.
is there a solution that External Task send a progress from current work to Engine?
Hi Mohammad,
a good Ressource for such questions is our REST documentation. Here you can find the one applicable for external tasks: External Task | docs.camunda.org
Apparently there is no thing like an automated status update available out of the box.
Nevertheless you could extend the existing functionality by adding a custom endpoint so it gets possible.
This would require some development in the spring boot Camunda app (in case you are using this approach).
I’d like to make a suggestion that’s tangentially related to the question.
When you’ve got really long services running like this there’s a useful pattern to consider.
While the working is alive and working on the task it can send back an Extend Lock call for another 2 mins.
it should repeat this until the task is complete.
Doing this will give you 2 big benefits.
If the task worker goes down or does some kind of silent failing - the task will be unlocked and potentially picked up by another worker in a reasonable time, so you wont have to wait too long.
The history of the external task can be queried to check long things are taking. You can do a count on the number of times that the extend lock was done and this should give you some indication of progress.
Such a great post, thank you in advance for your proper reply.
We have found the post according to our requirement.
As you have described, we added a new variable (like varName=progressVar) in this api /api/engine/engine/default/process-instance/{processInstanceId}/variables/{varName} and we could get ProcessInstanceId by externalTask.getProcessInstanceId() method.
Following the rules, we think that it could be a specific method (it would be developed on client side like External Task or Services) related to sending progress value to the engine. we have developed the below method for this reason.
/**
* @param processInstanceId is the id of process instance.
* @param varName is the name of variable.
* @param percent is the precent of progress.
* @return the resonse status code.
* @throws IOException
*/
public static String executRest(String processInstanceId, String varName, int percent) throws IOException {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPut request = new HttpPut(String.format("http://localhost:9999/bpms/api/engine/engine/default/process-instance/%s/variables/%s", processInstanceId, varName));
request.addHeader("content-type", "application/json");
StringEntity params = new StringEntity(String.format("{\"type\": \"string\", \"value\": \"%s\", \"valueInfo\": {}}", "% " + percent));
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
return "Set variable for % " + percent + " of doing external task status code is: " + response.getStatusLine().getStatusCode();
}
It’s our pleasure if we can help you with developing the module.
According to the post, it could be such a necessary feature that would be helpful for users.
Let me know if it is good enough for sending a merge request (i mean “pull request”) or any modification will be needed.
I think it can be added via method into External task client module such as extend-lock.
but instead of sending the only progress value, its better to send any variable.