amrishlal commented on a change in pull request #7174: URL: https://github.com/apache/pinot/pull/7174#discussion_r691549537
########## File path: pinot-core/src/main/java/org/apache/pinot/core/periodictask/PeriodicTaskScheduler.java ########## @@ -108,4 +111,62 @@ public synchronized void stop() { _tasksWithValidInterval.parallelStream().forEach(PeriodicTask::stop); } } + + /** @return true if task with given name exists; otherwise, false. */ + public boolean hasTask(String periodicTaskName) { + for (PeriodicTask task : _tasksWithValidInterval) { + if (task.getTaskName().equals(periodicTaskName)) { + return true; + } + } + return false; + } + + /** @return List of tasks name that will run periodically. */ + public List<String> getTaskNameList() { + List<String> taskNameList = new ArrayList<>(); + for (PeriodicTask task : _tasksWithValidInterval) { + taskNameList.add(task.getTaskName()); + } + return taskNameList; + } + + private PeriodicTask getPeriodicTask(String periodicTaskName) { + for (PeriodicTask task : _tasksWithValidInterval) { + if (task.getTaskName().equals(periodicTaskName)) { + return task; + } + } + return null; + } + + /** Execute {@link PeriodicTask} immediately on the specified table. */ + public void scheduleNow(String periodicTaskName, @Nullable Properties periodicTaskProperties) { + // During controller deployment, each controller can have a slightly different list of periodic tasks if we add, + // remove, or rename periodic task. To avoid this situation, we check again (besides the check at controller API + // level) whether the periodic task exists. + PeriodicTask periodicTask = getPeriodicTask(periodicTaskName); + if (periodicTask == null) { + throw new IllegalArgumentException("Unknown Periodic Task " + periodicTaskName); + } + + String taskRequestId = periodicTaskProperties.get(PeriodicTask.PROPERTY_KEY_REQUEST_ID).toString(); + + LOGGER.info( + "[TaskRequestId: {}] Schedule task '{}' to run immediately. If the task is already running, this run will wait until the current run finishes.", + taskRequestId, periodicTaskName); + _executorService.schedule(() -> { + try { + // Run the periodic task using the specified parameters. The call to run() method will block if another thread + // (the periodic execution thread or another thread calling this method) is already in the process of + // running the same task. + periodicTask.run(periodicTaskProperties); + } catch (Throwable t) { + // catch all errors to prevent subsequent executions from being silently suppressed + // Ref: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleWithFixedDelay-java.lang.Runnable-long-long-java.util.concurrent.TimeUnit- + LOGGER.warn("[TaskRequestId: {}] Caught exception while attempting to execute named periodic task: {}", Review comment: Fixed. ########## File path: pinot-core/src/main/java/org/apache/pinot/core/periodictask/PeriodicTaskScheduler.java ########## @@ -108,4 +111,62 @@ public synchronized void stop() { _tasksWithValidInterval.parallelStream().forEach(PeriodicTask::stop); } } + + /** @return true if task with given name exists; otherwise, false. */ + public boolean hasTask(String periodicTaskName) { + for (PeriodicTask task : _tasksWithValidInterval) { + if (task.getTaskName().equals(periodicTaskName)) { + return true; + } + } + return false; + } + + /** @return List of tasks name that will run periodically. */ + public List<String> getTaskNameList() { Review comment: Fixed. -- 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-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org