Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-14772

Repeating interval with start date instantiates too often

    • Icon: Bug Report Bug Report
    • Resolution: Unresolved
    • Icon: L3 - Default L3 - Default
    • None
    • 7.17.0
    • engine
    • None

      Environment (Required on creation):

      Any Camunda environment.

      Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):

      While creating a process definition with a repeating interval and a start date (example R2/2022-07-18T09:18:00Z/PT1M), the Camunda engine will instantiate one more process instance compared to the repeating interval number specified (3 instead of 2 in the example).

      Steps to reproduce (Required on creation):

      Execute the test included in this PR:
      https://github.com/camunda/camunda-bpm-platform/pull/1968

      or the test submitted by krisdacoder:

        @Test
        public void shouldNotExceedNumberPeriodsWithTimeCycle() throws Exception {
          ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
          DurationHelper dh = new DurationHelper("R2/1970-01-01T00:30:00/PT2M");
          assertEquals(parse("19700101-00:30:00"), dh.getDateAfter());
      
          // simulate some execution time of 10 seconds
          ClockUtil.setCurrentTime(parse("19700101-00:30:10"));
          assertEquals(parse("19700101-00:31:00"), dh.getDateAfter());
      
          // simulate some execution time of 10 seconds
          ClockUtil.setCurrentTime(parse("19700101-00:31:10"));
          assertNull("There must not be more than 2 repetitions",   dh.getDateAfter());
        }
      

      or create a process definition with a repeating interval including a start date e.g., "R2/2022-07-18T09:18:00Z/PT1M".

      Observed Behavior (Required on creation):

      The number of process instances instantiated is equal to the number of repetitions + 1.

      Expected behavior (Required on creation):

      The number of process instances instantiated should be equal to the number of repetitions.

      Root Cause (Required on prioritization):

      This loop which calculates the next date calculates the repeats based on the start date. When the start date is part of the expression though this leads to the timer firing once when the start date is reached and then n times to match the expression of Rn repeats.

      Solution Ideas (Optional):

      Hints (optional):

        This is the controller panel for Smart Panels app

            [CAM-14772] Repeating interval with start date instantiates too often

            Kristjan Demiri created issue -
            Miklas Boskamp made changes -
            Assignee New: Miklas Boskamp [ miklas.boskamp ]
            Miklas Boskamp made changes -
            Link New: This issue is related to CAMTEAM-249 [ CAMTEAM-249 ]
            Miklas Boskamp made changes -
            Description Original: h3. Environment (Required on creation):

            Using camunda engine integrated in a spring boot based service.
            h3. Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):

            While creating a process definition with a repeating interval (example R2/2022-07-18T09:18:00Z/PT1M), camunda engine will instantiate one more process instance compared to the repeating interval number specified (3 instead of 2 in the example). 

            The problem seems to be in [[this loop|https://github.com/camunda/camunda-bpm-platform/blob/7.17.0/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122]|https://github.com/camunda/camunda-bpm-platform/blob/7.17.0/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122] responsible for evaluation the next dueDate of a repetitive time-cycle.

            I wrote following test in _DurationHelperTest_ that fails:
            {code:java}
              @Test
              public void shouldNotExceedNumberPeriodsWithTimeCycle() throws Exception {
                ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
                DurationHelper dh = new DurationHelper("R2/1970-01-01T00:30:00/PT2M");
                assertEquals(parse("19700101-00:30:00"), dh.getDateAfter());

                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:30:10"));
                assertEquals(parse("19700101-00:31:00"), dh.getDateAfter());


                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:31:10"));
                assertNull("There must not be more than 2 repetitions", dh.getDateAfter());
              }{code}
            h3. Steps to reproduce (Required on creation):

            Create a process definition with a repeating interval. Number of repetitions should be static.
            h3. Observed Behavior (Required on creation):

            Number of process instances instantiated is equal to the number of repetitions + 1.
            h3. Expected behavior (Required on creation):

            Number of process instances instantiated should be equal to the number of repetitions.
            h3. Root Cause (Required on prioritization):

            The problem seems to be in [[this loop|https://github.com/camunda/camunda-bpm-platform/blob/7.17.0/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122]|https://github.com/camunda/camunda-bpm-platform/blob/7.17.0/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122] responsible for evaluation the next dueDate of a repetitive time-cycle.
            h3. Solution Ideas (Optional):
            h3. Hints (optional):
            New: h3. Environment (Required on creation):

            Any Camunda environment.

            h3. Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):

            While creating a process definition with a repeating interval and a start date (example R2/2022-07-18T09:18:00Z/PT1M), the Camunda engine will instantiate one more process instance compared to the repeating interval number specified (3 instead of 2 in the example).

            h3. Steps to reproduce (Required on creation):
            Execute the test included in this PR:
            https://github.com/camunda/camunda-bpm-platform/pull/1968

            or the test submitted by [~krisdacoder]:
              @Test
              public void shouldNotExceedNumberPeriodsWithTimeCycle() throws Exception {
                ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
                DurationHelper dh = new DurationHelper("R2/1970-01-01T00:30:00/PT2M");
                assertEquals(parse("19700101-00:30:00"), dh.getDateAfter());

                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:30:10"));
                assertEquals(parse("19700101-00:31:00"), dh.getDateAfter());


                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:31:10"));
                assertNull("There must not be more than 2 repetitions", dh.getDateAfter());
              }

            or create a process definition with a repeating interval including a start date e.g., "R2/2022-07-18T09:18:00Z/PT1M".

            h3. Observed Behavior (Required on creation):

            The number of process instances instantiated is equal to the number of repetitions + 1.

            h3. Expected behavior (Required on creation):

            The number of process instances instantiated should be equal to the number of repetitions.

            h3. Root Cause (Required on prioritization):

            [This loop|https://github.com/camunda/camunda-bpm-platform/blob/0bc04bd98a97e4099996acd3bbd42f828f77b219/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122-L124] which calculates the next date calculates the repeats based on the start date. When the start date is part of the expression though this leads to the timer firing once when the start date is reached and then {{n}} times to match the expression of {{Rn}} repeats.

            h3. Solution Ideas (Optional):
            h3. Hints (optional):
            Miklas Boskamp made changes -
            Description Original: h3. Environment (Required on creation):

            Any Camunda environment.

            h3. Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):

            While creating a process definition with a repeating interval and a start date (example R2/2022-07-18T09:18:00Z/PT1M), the Camunda engine will instantiate one more process instance compared to the repeating interval number specified (3 instead of 2 in the example).

            h3. Steps to reproduce (Required on creation):
            Execute the test included in this PR:
            https://github.com/camunda/camunda-bpm-platform/pull/1968

            or the test submitted by [~krisdacoder]:
              @Test
              public void shouldNotExceedNumberPeriodsWithTimeCycle() throws Exception {
                ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
                DurationHelper dh = new DurationHelper("R2/1970-01-01T00:30:00/PT2M");
                assertEquals(parse("19700101-00:30:00"), dh.getDateAfter());

                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:30:10"));
                assertEquals(parse("19700101-00:31:00"), dh.getDateAfter());


                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:31:10"));
                assertNull("There must not be more than 2 repetitions", dh.getDateAfter());
              }

            or create a process definition with a repeating interval including a start date e.g., "R2/2022-07-18T09:18:00Z/PT1M".

            h3. Observed Behavior (Required on creation):

            The number of process instances instantiated is equal to the number of repetitions + 1.

            h3. Expected behavior (Required on creation):

            The number of process instances instantiated should be equal to the number of repetitions.

            h3. Root Cause (Required on prioritization):

            [This loop|https://github.com/camunda/camunda-bpm-platform/blob/0bc04bd98a97e4099996acd3bbd42f828f77b219/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122-L124] which calculates the next date calculates the repeats based on the start date. When the start date is part of the expression though this leads to the timer firing once when the start date is reached and then {{n}} times to match the expression of {{Rn}} repeats.

            h3. Solution Ideas (Optional):
            h3. Hints (optional):
            New: h3. Environment (Required on creation):

            Any Camunda environment.

            h3. Description (Required on creation; please attach any relevant screenshots, stacktraces, log files, etc. to the ticket):

            While creating a process definition with a repeating interval and a start date (example R2/2022-07-18T09:18:00Z/PT1M), the Camunda engine will instantiate one more process instance compared to the repeating interval number specified (3 instead of 2 in the example).

            h3. Steps to reproduce (Required on creation):
            Execute the test included in this PR:
            https://github.com/camunda/camunda-bpm-platform/pull/1968

            or the test submitted by [~krisdacoder]:

            {code:java}
              @Test
              public void shouldNotExceedNumberPeriodsWithTimeCycle() throws Exception {
                ClockUtil.setCurrentTime(parse("19700101-00:00:00"));
                DurationHelper dh = new DurationHelper("R2/1970-01-01T00:30:00/PT2M");
                assertEquals(parse("19700101-00:30:00"), dh.getDateAfter());

                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:30:10"));
                assertEquals(parse("19700101-00:31:00"), dh.getDateAfter());

                // simulate some execution time of 10 seconds
                ClockUtil.setCurrentTime(parse("19700101-00:31:10"));
                assertNull("There must not be more than 2 repetitions", dh.getDateAfter());
              }
            {code}


            or create a process definition with a repeating interval including a start date e.g., "R2/2022-07-18T09:18:00Z/PT1M".

            h3. Observed Behavior (Required on creation):

            The number of process instances instantiated is equal to the number of repetitions + 1.

            h3. Expected behavior (Required on creation):

            The number of process instances instantiated should be equal to the number of repetitions.

            h3. Root Cause (Required on prioritization):

            [This loop|https://github.com/camunda/camunda-bpm-platform/blob/0bc04bd98a97e4099996acd3bbd42f828f77b219/engine/src/main/java/org/camunda/bpm/engine/impl/calendar/DurationHelper.java#L122-L124] which calculates the next date calculates the repeats based on the start date. When the start date is part of the expression though this leads to the timer firing once when the start date is reached and then {{n}} times to match the expression of {{Rn}} repeats.

            h3. Solution Ideas (Optional):
            h3. Hints (optional):
            Miklas Boskamp made changes -
            Assignee Original: Miklas Boskamp [ miklas.boskamp ] New: Thorben Lindhauer [ thorben.lindhauer ]
            Miklas Boskamp made changes -
            Assignee Original: Thorben Lindhauer [ thorben.lindhauer ] New: Tobias Metzke-Bernstein [ tobias.metzke ]
            Tobias Metzke-Bernstein made changes -
            Assignee Original: Tobias Metzke-Bernstein [ tobias.metzke ] New: Miklas Boskamp [ miklas.boskamp ]
            Tobias Metzke-Bernstein made changes -
            Assignee Original: Miklas Boskamp [ miklas.boskamp ] New: Tobias Metzke-Bernstein [ tobias.metzke ]
            Tobias Metzke-Bernstein made changes -
            Summary Original: When creating a process definition with a repeating interval (example R2/2022-07-18T09:18:00Z/PT1M), camunda engine will instantiate one more process instance compared to the repeating interval number specified (3 instead of 2 in the example). New: Repeating interval with start date instantiates too often
            Tobias Metzke-Bernstein made changes -
            Assignee Original: Tobias Metzke-Bernstein [ tobias.metzke ] New: Miklas Boskamp [ miklas.boskamp ]

              Unassigned Unassigned
              krisdacoder Kristjan Demiri
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated: