You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by jk...@apache.org on 2023/05/03 16:02:56 UTC

[unomi] branch master updated: UNOMI-761: Correctly calculate initial delay of the Segment/Scoring r… (#613)

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

jkevan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git


The following commit(s) were added to refs/heads/master by this push:
     new 9dee6f108 UNOMI-761: Correctly calculate initial delay of the Segment/Scoring r… (#613)
9dee6f108 is described below

commit 9dee6f10809afe7b77786111a17e3b49f79044d4
Author: kevan Jahanshahi <jk...@apache.org>
AuthorDate: Wed May 3 18:02:52 2023 +0200

    UNOMI-761: Correctly calculate initial delay of the Segment/Scoring r… (#613)
    
    * UNOMI-761: Correctly calculate initial delay of the Segment/Scoring recalculation scheduled task
    
    * UNOMI-761: Correctly calculate initial delay of the Segment/Scoring recalculation scheduled task
---
 .../apache/unomi/services/impl/scheduler/SchedulerServiceImpl.java | 7 +++----
 .../apache/unomi/services/impl/segments/SegmentServiceImpl.java    | 6 ++++--
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/services/src/main/java/org/apache/unomi/services/impl/scheduler/SchedulerServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/scheduler/SchedulerServiceImpl.java
index ea21c38f6..89f5d3062 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/scheduler/SchedulerServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/scheduler/SchedulerServiceImpl.java
@@ -64,11 +64,10 @@ public class SchedulerServiceImpl implements SchedulerService {
 
     public static long getTimeDiffInSeconds(int hourInUtc, ZonedDateTime now) {
         ZonedDateTime nextRun = now.withHour(hourInUtc).withMinute(0).withSecond(0);
-        if(now.compareTo(nextRun) > 0)
+        if(now.compareTo(nextRun) > 0) {
             nextRun = nextRun.plusDays(1);
+        }
 
-        Duration duration = Duration.between(now, nextRun);
-        long initialDelay = duration.getSeconds();
-        return initialDelay;
+        return Duration.between(now, nextRun).getSeconds();
     }
 }
diff --git a/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java b/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
index 1cc852f24..0aac270c6 100644
--- a/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
+++ b/services/src/main/java/org/apache/unomi/services/impl/segments/SegmentServiceImpl.java
@@ -1216,8 +1216,10 @@ public class SegmentServiceImpl extends AbstractServiceImpl implements SegmentSe
             }
         };
         long initialDelay = SchedulerServiceImpl.getTimeDiffInSeconds(dailyDateExprEvaluationHourUtc, ZonedDateTime.now(ZoneOffset.UTC));
-        logger.info("daily recalculation job for segments and scoring that contains date relative conditions will run at fixed rate, initialDelay={}, taskExecutionPeriod={}", initialDelay, TimeUnit.DAYS.toSeconds(1));
-        schedulerService.getScheduleExecutorService().scheduleAtFixedRate(task, initialDelay, taskExecutionPeriod, TimeUnit.DAYS);
+        long period = TimeUnit.DAYS.toSeconds(taskExecutionPeriod);
+        logger.info("daily recalculation job for segments and scoring that contains date relative conditions will run at fixed rate, " +
+                "initialDelay={}, taskExecutionPeriod={} in seconds", initialDelay, period);
+        schedulerService.getScheduleExecutorService().scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
 
         task = new TimerTask() {
             @Override