New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SimpleJobRepository should ignore non-identifying JobParameters #1221
Labels
Milestone
Comments
fmbenhassine
added a commit
that referenced
this issue
May 5, 2021
Before this commit, the logic that validates if a job instance is complete or not was based only on the size of previous parameters, without checking if they are identifying or not. This commit introduces a change that uses only identifying job parameters to identify a job instance and validate its previous executions. Issue #1221
This is a valid issue, here is a quick way to reproduce it: import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
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.launch.JobLauncher;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableBatchProcessing
public class JobConfig {
@Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
return jobs.get("job")
.start(steps.get("step")
.tasklet((contribution, chunkContext) -> {
Object name = chunkContext.getStepContext().getJobParameters().get("name");
System.out.println("hello " + name);
return RepeatStatus.FINISHED;
})
.build())
.build();
}
public static void main(String[] args) throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(JobConfig.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobParameters jobParameters = new JobParametersBuilder()
.addString("name", "foo", false)
.toJobParameters();
jobLauncher.run(job, jobParameters);
jobLauncher.run(job, jobParameters); // fails with: A job instance already exists and is complete for parameters={name=foo}
}
} Fixed in 7f0824b by applying a slightly modified version of the attached patch. |
fmbenhassine
added a commit
that referenced
this issue
May 6, 2021
Before this commit, the logic that validates if a job instance is complete or not was based only on the size of previous parameters, without checking if they are identifying or not. This commit introduces a change that uses only identifying job parameters to identify a job instance and validate its previous executions. Issue #1221
fmbenhassine
added a commit
that referenced
this issue
May 11, 2021
Before this commit, the logic that validates if a job instance is complete or not was based only on the size of previous parameters, without checking if they are identifying or not. This commit introduces a change that uses only identifying job parameters to identify a job instance and validate its previous executions. Issue #1221
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Trevor Baker opened BATCH-2383 and commented
Using the CommandLineJobRunner I pass in some non-identifying parameters but when I rerun with the same parameter, SimpleJobRepository throws an exception:
This is because SimpleJobRepository only checks the number of JobParameters but doesn't check if they are identifying or not.
Related Jira: BATCH-1412
Affects: 3.0.3
Attachments:
The text was updated successfully, but these errors were encountered: