Starttime and endtime not set properly

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.

Screenshot%20from%202019-04-29%2009-47-52

Hi Christine,

Could you check process engine configuration, which clock instance is created?

Regards
Martin

I don’t configure a clock explicitely, so it is the DefaultClockImpl. Do I have an alternative?

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.

Martin

What clock implementation do you recommend? I had trouble finding that in the javadoc.

should work as you expect. It would be much easier, if you can reproduce the issue in the jUnit test.

Martin

When I create an instance of DefaultClockImpl it gives me the right time, it does update over time.

I do see that in my unit test, timing works fine. There must be a difference between my configs in test and dev.

This is still an issue for me. It is a blocker in one of the user stories. I’d appreciate help.

Hi Christine.

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.

Regards
Martin

Then how do I select another clock?

Hey @christine,

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.

Cheers,
Filip

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?

I have the same question , After i read the answer of @filiphr , i do follow it like this:

step 1: create a class which impliments org.flowable.common.engine.impl.runtime.Clock

import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import org.flowable.common.engine.impl.runtime.Clock;

public class MyDefaultClock implements Clock {

	@SuppressWarnings("unused")
	private Date currentTime;
	
	@SuppressWarnings("unused")
	private Calendar currentCalendar;

	public MyDefaultClock() {
		this.reset();
	}

	@Override
	public Date getCurrentTime() {
		return new Date();
	}

	@Override
	public Calendar getCurrentCalendar() {
		return Calendar.getInstance();
	}

	@Override
	public Calendar getCurrentCalendar(TimeZone timeZone) {
		return Calendar.getInstance();
	}

	@Override
	public TimeZone getCurrentTimeZone() {
		return TimeZone.getDefault();
	}

	@Override
	public void setCurrentTime(Date currentTime) {
		this.currentTime = currentTime;
	}

	@Override
	public void setCurrentCalendar(Calendar currentTime) {
		this.currentCalendar = currentTime;
	}

	@Override
	public void reset() {
		this.currentTime = new Date();
		this.currentCalendar = Calendar.getInstance();
	}

}

step 2 : before build or create ProcessEngine , set clock object for it , here is the object of class type “MyDefaultClock”,

code like this:

       @Bean
	public ProcessEngine processEngine(SpringProcessEngineConfiguration configuration) throws IOException {
               configuration.setClock(new MyDefaultClock());
               return configuration.buildProcessEngine();
	}

Question is : Is it right that i only do these ?

Hi Christine,

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:

  1. You do not use DefaultClockImpl in your app.
  2. CURRENT_TIME is set to some specific value before the usage.

Regards
Martin

Hi,

If you want to use your own clock implementation, yes that should be enough.

Regards
Martin

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.

Cheers,
Filip

@ 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.

Using flowable 6.4.1

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.