This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 4f03bde1e85 [Feat](job)scheduled job allows the time to be set in the 
past (#36732) (#37573)
4f03bde1e85 is described below

commit 4f03bde1e85cbebc0db7a22d8ef4b27f07f9172a
Author: Calvin Kirs <[email protected]>
AuthorDate: Thu Jul 18 19:15:10 2024 +0800

    [Feat](job)scheduled job allows the time to be set in the past (#36732) 
(#37573)
    
    ## Proposed changes
    
    In some cases, users want to set the start time to a time in the past.
    
    **For periodic scheduling tasks only, the start time of a one-time task
    must be set to the future or present time**
    **If the start time is the past time, then the next execution time
    should be the start time + time interval.**
    
    (cherry picked from commit fa6061070f6d4063b1966e99fc285e4e6b9c3750)
    
    
    
    #36732
---
 .../doris/job/base/JobExecutionConfiguration.java       |  2 +-
 .../java/org/apache/doris/job/base/TimerDefinition.java |  5 +----
 .../doris/job/base/JobExecutionConfigurationTest.java   |  3 +++
 .../suites/job_p0/test_base_insert_job.groovy           | 17 +++++++++++++++--
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/base/JobExecutionConfiguration.java
 
b/fe/fe-core/src/main/java/org/apache/doris/job/base/JobExecutionConfiguration.java
index 55b4ff79119..46bc2c71ea2 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/job/base/JobExecutionConfiguration.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/job/base/JobExecutionConfiguration.java
@@ -96,7 +96,7 @@ public class JobExecutionConfiguration {
             return;
         }
         if (timerDefinition.getStartTimeMs() < System.currentTimeMillis()) {
-            throw new IllegalArgumentException("startTimeMs cannot be less 
than current time");
+            throw new IllegalArgumentException("startTimeMs must be greater 
than current time");
         }
     }
 
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/job/base/TimerDefinition.java 
b/fe/fe-core/src/main/java/org/apache/doris/job/base/TimerDefinition.java
index 978538e607d..bcff4216c6e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/job/base/TimerDefinition.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/job/base/TimerDefinition.java
@@ -39,9 +39,6 @@ public class TimerDefinition {
 
 
     public void checkParams(boolean immediate) {
-        if (null != startTimeMs && startTimeMs < System.currentTimeMillis()) {
-            throw new IllegalArgumentException("startTimeMs must be greater 
than current time");
-        }
         if (null != startTimeMs && immediate) {
             throw new IllegalArgumentException("startTimeMs must be null when 
immediate is true");
         }
@@ -52,7 +49,7 @@ public class TimerDefinition {
             startTimeMs = System.currentTimeMillis() + 
intervalUnit.getIntervalMs(interval);
         }
         if (null != endTimeMs && endTimeMs < startTimeMs) {
-            throw new IllegalArgumentException("end time cannot be less than 
start time");
+            throw new IllegalArgumentException("endTimeMs must be greater than 
the start time");
         }
 
         if (null != intervalUnit) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/job/base/JobExecutionConfigurationTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/job/base/JobExecutionConfigurationTest.java
index 33a1178561d..6d01f09c5ea 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/job/base/JobExecutionConfigurationTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/job/base/JobExecutionConfigurationTest.java
@@ -65,6 +65,9 @@ public class JobExecutionConfigurationTest {
         delayTimes = configuration.getTriggerDelayTimes(
                 1001000L, 0L, 1000000L);
         Assertions.assertEquals(1, delayTimes.size());
+        timerDefinition.setStartTimeMs(2000L);
+        timerDefinition.setIntervalUnit(IntervalUnit.SECOND);
+        Assertions.assertArrayEquals(new Long[]{2L, 12L}, 
configuration.getTriggerDelayTimes(100000L, 100000L, 120000L).toArray());
     }
 
     @Test
diff --git a/regression-test/suites/job_p0/test_base_insert_job.groovy 
b/regression-test/suites/job_p0/test_base_insert_job.groovy
index 3f5cd5692f9..d66266d8d6f 100644
--- a/regression-test/suites/job_p0/test_base_insert_job.groovy
+++ b/regression-test/suites/job_p0/test_base_insert_job.groovy
@@ -145,9 +145,21 @@ suite("test_base_insert_job") {
     Thread.sleep(5000)
     def pressJob = sql """ select * from jobs("type"="insert") where 
name='press' """
     println pressJob
-    
+    sql """
+        DROP JOB IF EXISTS where jobname =  'past_start_time'
+    """
+    sql """
+          CREATE JOB past_start_time  ON SCHEDULE every 10 hour starts 
'2023-11-13 14:18:07'  comment 'test for test&68686781jbjbhj//ncsa' DO insert 
into ${tableName}  values  ('2023-07-19', 99, 99);
+     """
+
+    def past_start_time_job = sql """ select status from jobs("type"="insert") 
where name='past_start_time'"""
+    println past_start_time_job
+    assert past_start_time_job.get(0).get(0) == "RUNNING"
     def recurringTableDatas = sql """ select count(1) from ${tableName} where 
user_id=99 and type=99 """
     assert recurringTableDatas.get(0).get(0) == 1
+    sql """
+        DROP JOB IF EXISTS where jobname =  'past_start_time'
+    """
     sql """
         DROP JOB IF EXISTS where jobname =  '${jobName}'
     """
@@ -190,6 +202,7 @@ suite("test_base_insert_job") {
             CREATE JOB ${jobName}  ON SCHEDULE at '2023-11-13 14:18:07'   
comment 'test' DO insert into ${tableName} (timestamp, type, user_id) values 
('2023-03-18','1','12213');
         """
     } catch (Exception e) {
+        println e.getMessage()
         assert e.getMessage().contains("startTimeMs must be greater than 
current time")
     }
     // assert end time less than start time
@@ -213,7 +226,7 @@ suite("test_base_insert_job") {
             CREATE JOB test_error_starts  ON SCHEDULE every 1 second ends 
'2023-11-13 14:18:07'   comment 'test' DO insert into ${tableName} (timestamp, 
type, user_id) values ('2023-03-18','1','12213');
         """
     } catch (Exception e) {
-        assert e.getMessage().contains("end time cannot be less than start 
time")
+        assert e.getMessage().contains("endTimeMs must be greater than the 
start time")
     }
     // assert interval time unit can not be years
     try {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to