/** * Appends a log message to the execution log. The first time the log exceeds MAX_LOG_LENGTH, it * gets truncated and the TRUNCATION_BANNER gets added. Subsequent calls to appendLog will be * ignored. * * @param formattedMessage The formatted message to append to the log. */ void appendLog(String formattedMessage) { if (logTruncated) return; String combined = join(getLog(), formattedMessage); if (combined.length() > MAX_LOG_LENGTH) { String truncated = abbreviate(combined, MAX_LOG_LENGTH - TRUNCATION_BANNER.length() * 2 - 2); combined = join(new String[] {TRUNCATION_BANNER, truncated, TRUNCATION_BANNER}, "\n"); logTruncated = true; } setLog(combined); }
@Override public void failed(String message, @Nullable Throwable throwable) { JOB_EXECUTION_LOG.error("Failed. " + message, throwable); jobExecution.setEndDate(Instant.now()); jobExecution.setStatus(FAILED); jobExecution.setProgressMessage(message); sendEmail( jobExecution.getFailureEmail(), jobExecution.getType() + " job failed.", jobExecution.getLog()); update(); JobExecutionHolder.unset(); }
@Override public void canceled() { JOB_EXECUTION_LOG.warn("Canceled"); jobExecution.setEndDate(Instant.now()); jobExecution.setStatus(CANCELED); sendEmail( jobExecution.getFailureEmail(), jobExecution.getType() + " job failed.", jobExecution.getLog()); update(); JobExecutionHolder.unset(); }
@Override public void success() { jobExecution.setEndDate(Instant.now()); jobExecution.setStatus(SUCCESS); jobExecution.setProgressInt(jobExecution.getProgressMax()); Duration yourDuration = Duration.millis(timeRunning()); Period period = yourDuration.toPeriod(); PeriodFormatter periodFormatter = new PeriodFormatterBuilder() .appendDays() .appendSuffix("d ") .appendHours() .appendSuffix("h ") .appendMinutes() .appendSuffix("m ") .appendSeconds() .appendSuffix("s ") .appendMillis() .appendSuffix("ms ") .toFormatter(); String timeSpent = periodFormatter.print(period); JOB_EXECUTION_LOG.info("Execution successful. Time spent: {}", timeSpent); sendEmail( jobExecution.getSuccessEmail(), jobExecution.getType() + " job succeeded.", jobExecution.getLog()); update(); JobExecutionHolder.unset(); }