/** * Executes the given task if it is scheduled for the given hour. * * @param currentHour the hour to pretend * @param task the task to execute */ public void runDailyTimer(int currentHour, EveryDay task) { Optional<Integer> executionHour = getExecutionHour(task); if (!executionHour.isPresent()) { LOG.WARN("Skipping daily timer %s as config key '%s' is missing!", task.getClass().getName(), TIMER_DAILY_PREFIX + task.getConfigKeyName()); return; } if (executionHour.get() != currentHour) { return; } if (orchestration != null && !orchestration.shouldRunDailyTask(task.getConfigKeyName())) { return; } executeTask(task); }
/** * Calls {@code doWork()} with proper error handling and then {@code loop()} again to schedule the next call. */ private void executeWork() { try { if (orchestration == null || orchestration.tryExecuteBackgroundLoop(getName())) { try { Watch w = Watch.start(); LocalDateTime now = LocalDateTime.now(); String executedWork = doWork(); buildAndLogExecutionInfo(w, now, executedWork); } finally { if (orchestration != null) { orchestration.backgroundLoopCompleted(getName(), executionInfo); } } } } catch (Exception e) { Exceptions.handle(Tasks.LOG, e); } loop(); }