Sending status-based variables (like progress) from External Task to Engine periodically (via specific method)

Hello Team.

I hope you are doing well.

Following this post , handling status-based variables is important (between External task and Engine). So we have some ideas for sending new variables from External task client to Engine via dedicated method.

The main goal is to moderate some fields (like Progress and etc) between External tasks and Engine which is used periodically (for example we have a job like recording video 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).

As we describe the point, it will be like a specific method for sending status-based params to the Engine.
According to your contribution structure, the idea is under Community Extensions category.

As @jonathan.lukas has 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