As I am currently still a beginner in using camunda I would like to know what is the best practice to share a variable through multiple process instances using camunda and BPMN workflows. An example Workflow would look like this:
The workflow contains a lookup for products within a specific time period. The period is not given at the start of the process, as it is a timer-based startup. The period for the lookup has to be stored and provided to the process scope.
In Detail, the first task gets a timestamp of the latest successful execution and provides it as a parameter to the workflow. The second task checks for new products based on the timestamp of the last successful execution. The third task does something with the products and the last task stores the newest success timestamp.
A spring boot application [Version:2.3.4] is build around camunda [Version:7.14.0], until now, I only have the camunda data base and would like to store the value with the given functionality.
What is the best way to store the value and make it available to all process instances?
For the general requirement to share data across process instances, you could implement a REST service which owns the data. Camunda uses JAX-RS (Jersey). However, you can also use Spring or another option to create the REST service.
Spring Data example including data model and persistence in same H2 DB Camunda uses:
https://github.com/rob2universe/rest-account-service
JAX-RS (Jersey) example, only showing how to add a REST service to the Camunda API:
https://github.com/rob2universe/camunda-custom-rest-endpoint
However, your requirement here is not really sharing business data across multiple process instances. You just want to know when an instance of your process ran for the last time. This is something you could easily figure out by running a process instance query. Something similar to:
var list = engine.getHistoryService().createHistoricProcessInstanceQuery()
.processDefinitionKey(PD_KEY)
.orderByProcessInstanceEndTime()
.list();
With this approach you can retrieve the information when needed from the Camunda history without explicitly storing and reading the data in a separate table.