leventov commented on a change in pull request #10448:
URL: https://github.com/apache/druid/pull/10448#discussion_r507181662



##########
File path: 
core/src/main/java/org/apache/druid/java/util/common/concurrent/ScheduledExecutors.java
##########
@@ -167,6 +169,50 @@ public void run()
     );
   }
 
+  public static void scheduleAtFixedRate(CronScheduler exec, Duration rate, 
Callable<Signal> callable)
+  {
+    scheduleAtFixedRate(exec, rate, rate, callable);
+  }
+
+  /**
+   * Run callable once every period, after the given initial delay. Uses
+   * {@link CronScheduler} for task scheduling. Exceptions are caught and 
logged
+   * as errors.
+   */
+  public static void scheduleAtFixedRate(
+      final CronScheduler exec,
+      final Duration initialDelay,
+      final Duration rate,
+      final Callable<Signal> callable
+  )
+  {
+    log.debug("Scheduling periodically: %s with period %s", callable, rate);
+    Instant delayInstance = Instant.now().plusMillis(initialDelay.getMillis());
+    exec.scheduleAt(delayInstance,

Review comment:
       I think this logic: scheduling one-shot task which reschedules itself, 
is problematic. I think we should remove these methods (together with the 
`Signal` enum) because they have negative utility.
   
   In particular, for `CronScheduler`, constant rescheduling is probably prone 
to some drift. Instead, `CronScheduler`'s methods like `scheduleAtFixedRate()` 
should be used directly from `MonitorScheduler`. The periodic task can be 
cancelled using the returned `Future`.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to