Configurable duration on Timer boundary event

I have some boundary timer events in my BPMN diagrams which should be configured for different durations based on environment(different for testing and production for example). I configure all of these things via property files, but I have no idea how to do that for the timer duration.
The duration can contain expression, but it can apparently only refer to a process variable: Timer Events | docs.camunda.org

What would be the best way to have this configurable? Is there some other way than using process variable? If not, how would I set it? The variable cannot be set after the process starts, because the engine checks if the expression can be resolved on process start. I can modify the value in the raw XML using parse listener, but that doesn’t seem very safe.

1 Like

Hey @neplatnyudaj,

Have you considered doing a Java Delegate Service Task before your Task with the Timer Boundary event?

From there you could extract information from your properties files and set a process variable.

Something like this?

This way you can make sure your process variable in your timer configuration has a value before it is needed. This approach is perfectly fine and gives you visibility to what your process is doing instead of hiding things.

Have a try at it and let me know how it goes? :slight_smile:

Regards,

Thanks for reply. This kind of works, but I need to set some arbitrary duration before the process starts, otherwise it fails on parsing the bpmn and creating process instance. So I set some value and then overwrite it in the Set Timer delegate. So it seems to be more obscure than visible(I have to set the value two times). If I won’t find better solution, I guess I’ll have to use it.

Hey @neplatnyudaj,

What does your Set Timer Service Task configuration look like? Mine looks like this.

My Java Class path looks like this

image

There is no need to set the variable twice for the timer process variable.

Let me know if you have any questions.

Regards,

Did you try starting an instance of that process? Because for me it fails as soon as I start the process without providing the process variable.

org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${expirationDate}. Cause: Cannot resolve identifier 'expirationDate'
at org.camunda.bpm.engine.impl.el.JuelExpression.getValue(JuelExpression.java:63) ~[camunda-engine-7.11.0.jar:7.11.0]
...
at org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl.execute(ProcessInstantiationBuilderImpl.java:132) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.ProcessInstantiationBuilderImpl.execute(ProcessInstantiationBuilderImpl.java:128) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:115) ~[camunda-engine-7.11.0.jar:7.11.0]

Hi @neplatnyudaj,

you can use a spring bean that returns the required configuration: https://docs.camunda.org/manual/7.11/user-guide/process-engine/expression-language/#external-context-variables-with-spring-and-cdi

Just put the method into the expression like ${myBean.calculateTime(). Here you can access your configuration properties.

Hope this helps, Ingo

2 Likes

Wonderful, it works like a charm.
That was my initial idea, but from the online documentation I got the idea that I can only use process variables for specifying duration: 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.

So right now I’m using ${configurationResolver.getValue(‘expirationDuration’)} and reading the property from file.

Thanks!