In the flowable database (in postgres) I see that processes all have the same start time and end time. When I restart my application, starttimes and endtimes are set to a new value, but still the same for all processes as long as the application runs. Is there anything I can do about that?
I am trying to create a log of processes and activities.
Yes, there are other clock implementations too.
Could you check what is returned from DefaultClockImpl#getCurrentTime method? (or currentCalendar)
If defaultClockImpl current time returns constant time that could cause the issue.
As you wrote, it must be something in process engine config which make the difference. Another problem could be that you are setting time in DefaultClockImpl in your code and after that DefaultClockImpl does not provide system time any more, but always this “constant” value.
You don’t need to select another clock. You need to figure out which piece of your code calls setCurrentTime(Date) or setCurrentCalendar(Calendar) in org.flowable.common.engine.impl.runtime.Clock and fix that.
I’m confused. In my unit test, I don’t call setTime or setCurrentCalendar, and it works fine with proper times. In my application, I don’t setTime or setCurrentCalendar either, but there time remains the same.
Do I have to call setTime? Does time only change when I set it?
DefaultClockImpl provides a way (if (CURRENT_TIME == null)) in which system time is provided. So when CURRENT_TIME is not set, DefaultClockImpl provides system time.
That’s why there are 2 possibilities:
You do not use DefaultClockImpl in your app.
CURRENT_TIME is set to some specific value before the usage.
If you call setTime or setCurrentCalendar then the time would be fixed. Therefore, I would say that you should not call it. If it works in tests, but not in the application then I would put a breakpoint in the clock and check where it is set.
@tangyibo if you want to use your own clock you could do it. However, you don’t really need to do that. You need to figure out why you are calling setTime or setCurrentTime in your application.
@ filiphr ,Thank you very much for your help first, The reason why calling setClock() in function processEngine() ,I only want to use the correct time in database for field START_TIME_; but I still don’t know the best and easy way for it,can you tell me or the code how to write? Thanks!!!
@tangyibowhat you do mean you want to set the correct time in the database field? If you call setClock() the entire process engine would use a fixed time. That is only meant for tests and working with timers, not for production use.
Sorry for the late kick but this doesn’t work for me trying to use a custom clock.
If I create a custom process engine then flowable doesn’t start complaining that “CMMN engine has not been initialized” in CmmnEngineServicesAutoConfiguration. It looks like it expects me to also create a custom CMMN and app engines? This opens a whole can of worms and flowable doesn’t even start.
There was mention of setting CURRENT_TIME but that is quite hacky. It is relying on the fact that setting the time sets a static variable for an object that might have multiple instances.
I want to use a custom clock.
I currently have it working by using reflection to set the clock, variableServiceConfiguration.clock, jobServiceConfiguration.clock field in the beans of ProcessEngineConfiguration, CmmnEngineConfiguration.
This is obviously not ideal. What would be the proper way to use a custom clock in flowable?
My use case is to test - amongst others - timers in an acceptance test environment.