I’m facing a process that has a long running task.
This task save a variable indicating the progress value.
List by http request the processInstance variables while the task is still alive doesn’t give me the progress value.
When the task ends, and process continue to another task, variable is returned by the same http request.
Why this ? I suppose it’s due to transactional behaviour
Is there any way to recover variable value on task while execution still running ?
/**
* Update or create a variable for an execution.
*
* <p>
* The variable is set according to the algorithm as documented for {@link VariableScope#setVariable(String, Object)}.
*
* @param executionId
* id of execution to set variable in, cannot be null.
* @param variableName
* name of variable to set, cannot be null.
* @param value
* value to set. When null is passed, the variable is not removed, only it's value will be set to null.
* @throws FlowableObjectNotFoundException
* when no execution is found for the given executionId.
* @see VariableScope#setVariable(String, Object) {@link VariableScope#setVariable(String, Object)}
*/
void setVariable(String executionId, String variableName, Object value);
org.flowable.engine.TaskService#setVariable
/**
* set variable on a task. If the variable is not already existing, it will be created in the most outer scope. This means the process instance in case this task is related to an execution.
*/
void setVariable(String taskId, String variableName, Object value);
@Component
class CustomTaskBehavior(
private val componentAsyncTaskService: ComponentAsyncTaskService,
private val componentAsyncTaskRunner: ComponentAsyncTaskRunner
) : JavaDelegate, TriggerableActivityBehavior {
override fun execute(execution: DelegateExecution) {
runtimeService.setVariable(execution.id, "ProgressEvents", "InProgress")
}
override fun trigger(execution: DelegateExecution, signalEvent: String?, signalData: Any?) {
logger().info("Trigger $execution")
}
}
It works but my progress variable is only avalable after 5 days using REST API (GET /process-api/runtime/process-instances/{{processInstanceId}}/variables)
I want it to be available by REST API even if my custom task is not finished yet, i.e triggered.
I did not understand you question.
I would expect triggerable service task is executed and associated execution waits on the trigger after that. You description is different.
Could you reproduce the issue in the jUnit test pls?
You’re right, the example I give you is not complete and maybe don’t help you understand my question.
In my CustomTaskBehavior#execute(), I do a bit more operations than just set a variable. I run operations and block the current thread until operations completion.
If I don’t block the current thread, the transaction is committed and I can see my variable from the REST API. In the same way if I update this runtime variable from my long running task, I also see the new value.