Starttime and endtime not set properly

#1

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

#2

Hi Christine,

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

Regards
Martin

#3

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

#4

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

#5

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

#6

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

Martin

#7

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

#8

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

#9

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

#10

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

#11

Then how do I select another clock?

#12

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

#13

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?

#14

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 ?

#15

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

#16

Hi,

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

Regards
Martin

#17

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