Reputation: 1933
I have a web application and I upload a file as soon as i upload a file i launch the job using job launcher and async task executor. So tehcnically the job runs in its own thread. The spring batch job spits out csv, imports into database and does some validations on the data. So any kind of exceptions during any of the steps like error parsing flat file due to an invalid date all the exceptions I get using
jobExecution.getAllFailureExceptions()
are sent out in error email at the end of the job using a listner. And the user who uploaded the file I make the thread sleep for 4 minutes
while(isJobRunning(jobId)) {
if(count == 0)
break;
Thread.sleep(sleepMilliSeconds);
count--;
}
and then if the job has completed before the time I show the user in the UI all the validation error messages at the step level and job level. So now I use
jobExecution = jobExplorer.getJobExecution(jobExecution.getId());
now when I do this to get the jobExecution.getAllFailureExceptions()
it returns empty exceptions. I see the step exceptions and job level exceptions in the database job repository in the column 'EXIT_MESSAGE' BATCH_JOB_EXECUTION and BATCH_JOB_STEP_EXECUTION but they are not loaded when i retreive jobexecution using job explorer. Is there any workaround ? I have to create custom queries to retreive the step execution exceptions and job exceptions? please help me.
Below are my job repository, jobexplorer and taskexecutor config
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="batchDataSource" />
<property name="transactionManager" ref="batchTransactionManager" />
<property name="databaseType" value="Oracle" />
<property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor" ref="taskExecutor" />
</bean>
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="1" />
<property name="maxPoolSize" value="3" />
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="batchDataSource"/>
</bean>
Upvotes: 2
Views: 1254
Reputation: 21453
The JobExplorer only returns what is in the JobRepository. Since the list of failure exceptions is not stored in the JobRepository you won't get that list back. If you really need to maintain a list of errors, you'll have to either store them somewhere independent of the JobRepository or use the ExecutionContext. If you're using the ExecutionContext, be aware of what you put in it vs how big that column is in the database.
Upvotes: 2