I would like for my timer values to be pulled from environment variables. For example, we have a process with a timer cycle start event. We want this value to be determined dynamically based on the environment, that is, dev, test, prod, etc. Any help is much appreciated.
@crirvine You can utilize the same variable across environments and configure the value according to the environments.
From docs, Timer Events | docs.camunda.org
You can use expressions for the timer event definitions. By doing so you can influence the timer definition based on process variables. The process variables must contain the ISO 8601 (or cron for cycle type) string for the appropriate timer type.
<bpmn:startEvent id="StartProcess" name="Start Process">
<bpmn:outgoing>Flow_15xrtnn</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_1x4ezt3">
<bpmn:timeDuration xsi:type="bpmn:tFormalExpression">${duration}</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:startEvent>
I was aware that I would provide an expression for the time duration. What I don’t understand is how you import the variable “duration” and its value from what ever environment you happen to be running in.
Bind the environment variable to a spring property, and then use the property in the timer definition. This assumes that you use spring.
There is a caveat though. The expression is only evaluated on a real model deployment. If you just change the env variable and redeploy the unchanged process model the new schedule will NOT take effect. This was discussed recently here in the forums, with solutions.
Ok. I’ll try that approach. I understand your caveat. Thanks
Hi @crirvine I’ve tried this approach, just try this.
Here’s a code that can be used in expression:
@Component
public class CamundaUtility {
@Value("${timer.duration:PT5M}")
private String duration;
public String getTimerDuration() {
return this.duration;
}
}
For different environments you can set this field timer.duration
in jvm args according to the environment and with default value.
JVM args for various environments looks like:
For DEV environment:
-Dtimer.duration=PT1M
For TEST environment:
-Dtimer.duration=PT2M
For PROD environment:
-Dtimer.duration=PT3M
Then deploy this bpmn file and test: timerTest.bpmn (8.1 KB)
From below, the intermediate timer catching event also uses expression but this time it refers from process variable duration
which is set from previous user task.
Deploy this bpmn file and test: timerTest.bpmn (8.3 KB)
Wow. What a generous reply. Thanks so much. This will be very helpful I’m sure.