External Task send Progress to Engine periodically

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).

Hopefully this helps!
Best,
Thomas

2 Likes

Hi @Mohammad_Hasan_Saffa ,

one idea would be to set a variable inside the process instance of which you are handling a task via REST API.
You could give this a try.

Jonathan

1 Like

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.

  1. When you fetch and lock the task - you should only lock it for a short time like 2 minutes
  2. While the working is alive and working on the task it can send back an Extend Lock call for another 2 mins.
  3. it should repeat this until the task is complete.

Doing this will give you 2 big benefits.

  1. 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.
  2. 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.

Hope that helps.

2 Likes

Hi @jonathan.lukas ,

You mean that I set a variable with REST API inside the External Task server and send that to Engine?

Hi @Mohammad_Hasan_Saffa ,

yes, that is how I imagine it. You use the this endpoint to modify variables inside the engine:

https://docs.camunda.org/manual/7.15/reference/rest/process-instance/variables/

As you can see, all kinds of CRUD operations are available here.

Jonathan

2 Likes

Hi @jonathan.lukas

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.

Thank you in advance
Best,
Taha Arian

2 Likes

Hi

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.

Thanks

2 Likes

Hi @vahid_saffari

Yes, I agree with you.
it could be as a general module and will be compatible with all kinds of variables.

I hope that we could make related module

thanks to you
Best,
Taha Arian

Hello @tahaarian and @vahid_saffari ,

for contribution, please read here: How to Contribute - Camunda

I would like to leave this topic as it is. Please open a new Topic to discuss your extension idea.

Jonathan

2 Likes

Hello again @jonathan.lukas

OK, great.

I will suppose in a new topic.

Thanks
Best,
Taha Arian