protected void registerExecutionFinish(ScheduledTask task, ScheduledExecution execution, Object result, boolean manually) { if ((!BooleanUtils.isTrue(task.getLogFinish()) && !BooleanUtils.isTrue(task.getSingleton()) && task.getSchedulingType() != SchedulingType.FIXED_DELAY) || execution == null) return; log.trace("{}: registering execution finish", task); Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); execution = em.merge(execution); execution.setFinishTime(timeSource.currentTimestamp()); StringBuilder sb = new StringBuilder(); if (result != null) { sb.append(result.toString()); } if (manually) { sb.append("\n{Executed manually}"); } execution.setResult(sb.toString()); tx.commit(); } finally { tx.end(); } }
if (task.getStartDate() != null || SchedulingType.CRON == task.getSchedulingType()) { long currentStart; if (SchedulingType.FIXED_DELAY == task.getSchedulingType()) { currentStart = calculateNextDelayDate(task, task.getLastStart(), coordinator.getLastFinished(task), now, frame, period); } else if (SchedulingType.CRON == task.getSchedulingType()) { currentStart = calculateNextCronDate(task, task.getLastStart(), now, frame); } else { } else { long delay = giveChanceToPreviousHost ? period + period / 2 : period; if (SchedulingType.FIXED_DELAY == task.getSchedulingType()) { long lastFinish = coordinator.getLastFinished(task); if ((task.getLastStart() < lastFinish || !lastFinishCache.containsKey(task)) && lastFinish + delay < now) { Long lastStart = lastStartCache.getOrDefault(task, 0L); Long lastFinish = lastFinishCache.getOrDefault(task, 0L); if (task.getStartDate() != null || SchedulingType.CRON == task.getSchedulingType()) { long currentStart; if (SchedulingType.FIXED_DELAY == task.getSchedulingType()) { currentStart = calculateNextDelayDate(task, lastStart, lastFinish, now, frame, period); } else if (SchedulingType.CRON == task.getSchedulingType()) { currentStart = calculateNextCronDate(task, lastStart, now, frame); } else { if (SchedulingType.FIXED_DELAY == task.getSchedulingType()) { if ((lastStart == 0 || lastStart < lastFinish) && now >= lastFinish + period) { runTask(task, now);
protected ScheduledExecution registerExecutionStart(ScheduledTask task, long now) { if (!BooleanUtils.isTrue(task.getLogStart()) && !BooleanUtils.isTrue(task.getSingleton()) && task.getSchedulingType() != SchedulingType.FIXED_DELAY) return null; log.trace("{}: registering execution start", task); Transaction tx = persistence.createTransaction(); try { EntityManager em = persistence.getEntityManager(); ScheduledExecution execution = metadata.create(ScheduledExecution.class); execution.setTask(em.getReference(ScheduledTask.class, task.getId())); execution.setStartTime(new Date(now)); execution.setServer(serverInfo.getServerId()); em.persist(execution); tx.commit(); return execution; } finally { tx.end(); } }