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.

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

        Activity

        Hide
        mbrohl Michael Brohl added a comment -

        Thanks Tobias,

        you patch is in

        trunk r1796047
        release16.11 r1796049
        release15.12 r1796050
        release14.12 r1796052

        Show
        mbrohl Michael Brohl added a comment - Thanks Tobias, you patch is in trunk r1796047 release16.11 r1796049 release15.12 r1796050 release14.12 r1796052
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Hi Michael,

        We don't use the "Released versions" in the "Fix Version/s" field for the pending release but the corresponding one in "Unreleased versions". So I changed from "Release Branch R16.11" to "16.11.03"

        I know the rules are a bit complicated, I tried to explain them here https://cwiki.apache.org/confluence/display/OFBADMIN/OFBiz+Committers+Roles+and+Responsibilities#OFBizCommittersRolesandResponsibilities-ManageJIRA%27sissues

        To complete: last exchange with Jacopo about it https://s.apache.org/awBU

        Thanks

        Show
        jacques.le.roux Jacques Le Roux added a comment - Hi Michael, We don't use the "Released versions" in the "Fix Version/s" field for the pending release but the corresponding one in "Unreleased versions". So I changed from "Release Branch R16.11" to "16.11.03" I know the rules are a bit complicated, I tried to explain them here https://cwiki.apache.org/confluence/display/OFBADMIN/OFBiz+Committers+Roles+and+Responsibilities#OFBizCommittersRolesandResponsibilities-ManageJIRA%27sissues To complete: last exchange with Jacopo about it https://s.apache.org/awBU Thanks
        Hide
        mbrohl Michael Brohl added a comment - - edited

        Thank you, Jacques Le Roux for the reminder. I'm still getting confused and will try consider your how-to next time.

        Show
        mbrohl Michael Brohl added a comment - - edited Thank you, Jacques Le Roux for the reminder. I'm still getting confused and will try consider your how-to next time.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Hi Michael, I did my best but if you find a way feel free to improve the howto

        Show
        jacques.le.roux Jacques Le Roux added a comment - Hi Michael, I did my best but if you find a way feel free to improve the howto

          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:

              Development