Consitency when querying history instance and variables

I want to provide a rest endpoint that will expose data of a process.
Not all process data needs te be returned, only a few variables and a boolean indicating if the process is completed.

To achieve this I use the HistoryService and query the historic process instance and the required history variables.

The issue is that when a process is still being executed I can have an inconsistency between the data on the historic process instance (state) and the variables because they have to be queried separately.

For instance:

  • the rest service queries the historic process instance and it’s state indicates that the process is still running
  • the process completes it’s final step and a variable X is set
  • the rest service queries the historic variable X and finds the value set in the final step
  • the rest service will now say that the process is running and variable X has been set

Is it possible to query the historic process instance along with all the variables?
Or do you see a better solution for my use case?

If you’re looking for the current values of variables you could contact the runtime instead of the history.

I don’t know in advance if the process is ended or not.

So is the recommended way to solve this

  • try to use the runtime service to get all the variables in 1 go
  • if there is no data (process is completed) use the history service to query historical variables separately

That would work, although it’s not great that you’d need to make 2 calls in some cases. But it does ensure you get the right variable value.