Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-9374

Fix TemporalExpressions.Frequency to avoid moving job start times away from given freqCount raster

    Details

    • Flags:
      Patch

      Description

      If a job is scheduled using TemporalExpressions.Frequency the start time of the job will gradually move forward when the excecution of the job is delayed by one or more units of the frequency type.

      Example: Job is set up to start at 2017-01-01 00:00:00 and run every ten minutes. One month later due to some circumstances the job starts at 2017-02-01 00:01:01 which results in the next execution to be scheduled at 2017-02-01 01:11:00 in stead of 2017-02-01 01:10:00.

      The reason behind this behaviour is the TemporalExpressions.Frequency#prepareCal function. It has the purpose to jump from the first starting time to the latest possible execution of the job. But instead it just sets it to the current time (with the precision of the chosen frequency type) and calculates the next execution time from this point.

      Frequencies.java
              protected Calendar prepareCal(Calendar cal) {
                  // Performs a "sane" skip forward in time - avoids time consuming loops
                  // like incrementing every second from Jan 1 2000 until today
                  Calendar skip = (Calendar) cal.clone();
                  skip.setTime(this.start);
                  long deltaMillis = cal.getTimeInMillis() - this.start.getTime();
                  if (deltaMillis < 1000) {
                      return skip;
                  }
                  long divisor = deltaMillis;
                  if (this.freqType == Calendar.DAY_OF_MONTH) {
                      divisor = 86400000;
                  } else if (this.freqType == Calendar.HOUR) {
                      divisor = 3600000;
                  } else if (this.freqType == Calendar.MINUTE) {
                      divisor = 60000;
                  } else if (this.freqType == Calendar.SECOND) {
                      divisor = 1000;
                  } else {
                      return skip;
                  }
                  float units = deltaMillis / divisor;
                  units = (units / this.freqCount) * this.freqCount;
                  skip.add(this.freqType, (int)units);
                  while (skip.after(cal)) {
                      skip.add(this.freqType, -this.freqCount);
                  }
                  return skip;
              }
      

      The error is at units = (units / this.freqCount) * this.freqCount;. This is no operation. What should have been done (and to me it looks like this was the intention), is a substraction of the remainder of an integer division of units and this.freqCount to get the number of units of the frequency type that have passed since the first start time.

        Attachments

        1. OFBIZ-9374.patch
          0.8 kB
          Tobias Laufkötter

          Activity

            People

            • Assignee:
              mbrohl Michael Brohl
              Reporter:
              tlaufkoetter Tobias Laufkötter
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: