Closed tyrng closed 3 years ago
Attached the specific job config that is used in the logs in my original post:
package cc.worldline.dni.rhbwllbatch.report.user;
import cc.worldline.dni.rhbwllbatch.common.DateUtil;
import cc.worldline.dni.rhbwllbatch.common.ReportInfor;
import cc.worldline.dni.rhbwllbatch.common.entity.ActivityLog;
import cc.worldline.dni.rhbwllbatch.common.entity.ActivityLogRepository;
import cc.worldline.dni.rhbwllbatch.report.common.service.MaintenanceListingService;
import lombok.extern.slf4j.Slf4j;
import net.sf.jasperreports.engine.JRException;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Slf4j
@Configuration
@EnableBatchProcessing
public class UserLoginReportBatchConfig {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Autowired
private StepBuilderFactory stepBuilderFactory;
@Autowired
MaintenanceListingService maintenanceListingService;
@Autowired
ActivityLogRepository activityLogRepository;
@Value("${reportProperties.common.mainTitle}")
private String mainTitle;
@Value("${reportProperties.common.headerSeparator}")
private String headerSeparator;
@Value("${reportProperties.common.reportEndNote}")
private String reportEndNote;
@Value("${reportProperties.userLoginReportJob.reportId}")
private String reportId;
@Value("${reportProperties.userLoginReportJob.reportTitle}")
private String reportTitle;
@Value("${reportProperties.userLoginReportJob.location}")
private String location;
@Value("${reportProperties.userLoginReportJob.reportName}")
private String reportName;
@Value("${reportProperties.userLoginReportJob.createdJob}")
private String createdJob;
@Value("${reportProperties.userLoginReportJob.templateName}")
private String templateName;
@Value("${reportProperties.userLoginReportJob.jrGzipVirtualizerSize}")
private String jrGzipVirtualizerSize;
@Value("${reportProperties.userLoginReportJob.minusDay}")
private String minusDay;
@Bean
public Job userLoginReportJob(Step userLoginProcessingStep) {
return jobBuilderFactory.get("userLoginReportJob")
.start(userLoginProcessingStep)
.build();
}
@Bean
public Step userLoginProcessingStep() throws IOException, IllegalStateException {
return stepBuilderFactory.get("userLoginProcessingStep")
.tasklet(userLoginListing())
.build();
}
@Bean
public Tasklet userLoginListing() {
return (Tasklet)(new Tasklet() {
public final RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws ParseException, IOException, JRException, SQLException {
List<ActivityLog> activityLogList;
String paramDate = (String) chunkContext.getStepContext().getJobParameters().get("date");
ReportInfor reportInfor;
if (paramDate != null) {
reportInfor = DateUtil.beginEndDate(paramDate, DateUtil.SYSTEM_YEAR_MONTH_DATE + DateUtil.TIME_PATTERN_1, DateUtil.SYSTEM_YEAR_MONTH_DATE);
} else {
// minusDay = 0 or 1, get today or today - 1 date (yesterday)
paramDate = LocalDate.now().minusDays(Long.valueOf(minusDay)).format(DateTimeFormatter.ofPattern(DateUtil.SYSTEM_YEAR_MONTH_DATE));
reportInfor = DateUtil.beginEndDate(paramDate, DateUtil.SYSTEM_YEAR_MONTH_DATE + DateUtil.TIME_PATTERN_1, DateUtil.SYSTEM_YEAR_MONTH_DATE);
}
reportInfor.setReportDate(paramDate);
reportInfor.setMainTitle(mainTitle);
reportInfor.setHeaderSeparator(headerSeparator);
reportInfor.setReportEndNote(reportEndNote);
reportInfor.setReportTitle(reportTitle);
reportInfor.setReportId(reportId);
reportInfor.setLocation(location);
reportInfor.setReportName(reportName);
reportInfor.setKind(createdJob);
reportInfor.setTemplateName(templateName);
reportInfor.setJrGzipVirtualizerSize(jrGzipVirtualizerSize);
maintenanceListingService.generateUserLoginReport(reportInfor);
return RepeatStatus.FINISHED;
}
});
}
}
Closing this issue as we found that printStackTrace() outputs to STDERR instead of STDOUT, which our script is not able to produce in the log file output. And the printed error seems to be caused by #1448 .
Bug description We currently launch our jobs using command line arguments (the main function we used is attached below). We have a collection of Bash scripts that run the jobs separately, hence the job names would not contain human typing error during execution (we have tested each script thoroughly). However, sometimes, and without a clear pattern, some jobs would not be executed at all (refer to the logs attached), nor any new entry inserted into BATCH_JOB_EXECUTION and BATCH_STEP_EXECUTION.
Environment Spring Batch 2.1.7 Java 1.8 SQL Server 2017
Steps to reproduce Run the Java application with job name as the command line argument.
Expected behavior Job should always execute, the execution should be shown in the logs, new entries should be able to be seen in BATCH_JOB_EXECUTION and BATCH_STEP_EXECUTION.
Minimal Complete Reproducible example Main function:
Log when the job is executed normally:
Log when the job randomly does not execute: