You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "tiagodolphine (via GitHub)" <gi...@apache.org> on 2023/10/03 14:22:15 UTC

Re: [PR] [KOGITO-9842] The initial load job task from DB is not executed Job Service [incubator-kie-kogito-apps]

tiagodolphine commented on code in PR #1888:
URL: https://github.com/apache/incubator-kie-kogito-apps/pull/1888#discussion_r1344194907


##########
jobs-service/jobs-service-common/src/main/java/org/kie/kogito/jobs/service/scheduler/JobSchedulerManager.java:
##########
@@ -73,26 +74,49 @@ public class JobSchedulerManager {
 
     @Inject
     Vertx vertx;
-    private AtomicBoolean enabled = new AtomicBoolean(false);
+    final AtomicBoolean enabled = new AtomicBoolean(false);
+
+    final AtomicLong periodicTimerIdForLoadJobs = new AtomicLong(-1l);
 
     void onStartup(@Observes @Priority(Interceptor.Priority.PLATFORM_AFTER) StartupEvent startupEvent) {
-        if (loadJobIntervalInMinutes > schedulerChunkInMinutes) {
-            LOGGER.warn("The loadJobIntervalInMinutes ({}) cannot be greater than schedulerChunkInMinutes ({}), " +
-                    "setting value {} for both",
-                    loadJobIntervalInMinutes,
-                    schedulerChunkInMinutes,
-                    schedulerChunkInMinutes);
-            loadJobIntervalInMinutes = schedulerChunkInMinutes;
+        if (enabled.get()) {

Review Comment:
   done



##########
jobs-service/jobs-service-common/src/main/java/org/kie/kogito/jobs/service/scheduler/JobSchedulerManager.java:
##########
@@ -73,26 +74,49 @@ public class JobSchedulerManager {
 
     @Inject
     Vertx vertx;
-    private AtomicBoolean enabled = new AtomicBoolean(false);
+    final AtomicBoolean enabled = new AtomicBoolean(false);
+
+    final AtomicLong periodicTimerIdForLoadJobs = new AtomicLong(-1l);
 
     void onStartup(@Observes @Priority(Interceptor.Priority.PLATFORM_AFTER) StartupEvent startupEvent) {
-        if (loadJobIntervalInMinutes > schedulerChunkInMinutes) {
-            LOGGER.warn("The loadJobIntervalInMinutes ({}) cannot be greater than schedulerChunkInMinutes ({}), " +
-                    "setting value {} for both",
-                    loadJobIntervalInMinutes,
-                    schedulerChunkInMinutes,
-                    schedulerChunkInMinutes);
-            loadJobIntervalInMinutes = schedulerChunkInMinutes;
+        if (enabled.get()) {
+            startJobsLoadingFromRepositoryTask();
         }
+    }
 
-        //first execution
-        vertx.runOnContext(this::loadJobDetails);
-        //periodic execution
-        vertx.setPeriodic(TimeUnit.MINUTES.toMillis(loadJobIntervalInMinutes), id -> loadJobDetails());
+    private void startJobsLoadingFromRepositoryTask() {
+        //guarantee it starts the task just in case it is not already active
+        if (periodicTimerIdForLoadJobs.get() < 0) {
+            if (loadJobIntervalInMinutes > schedulerChunkInMinutes) {
+                LOGGER.warn("The loadJobIntervalInMinutes ({}) cannot be greater than schedulerChunkInMinutes ({}), " +
+                        "setting value {} for both",
+                        loadJobIntervalInMinutes,
+                        schedulerChunkInMinutes,
+                        schedulerChunkInMinutes);
+                loadJobIntervalInMinutes = schedulerChunkInMinutes;
+            }
+            //first execution
+            vertx.runOnContext(this::loadJobDetails);
+            //next executions to run periodically
+            periodicTimerIdForLoadJobs.set(vertx.setPeriodic(TimeUnit.MINUTES.toMillis(loadJobIntervalInMinutes), id -> loadJobDetails()));
+        }
     }
 
-    protected void onMessagingStatusChange(@Observes MessagingChangeEvent event) {
-        this.enabled.set(event.isEnabled());
+    private void cancelJobsLoadingFromRepositoryTask() {
+        if (periodicTimerIdForLoadJobs.get() > 0) {
+            vertx.cancelTimer(periodicTimerIdForLoadJobs.get());
+            //negative id indicates this is not active anymore
+            periodicTimerIdForLoadJobs.set(-1);
+        }
+    }
+
+    protected synchronized void onMessagingStatusChange(@Observes MessagingChangeEvent event) {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org