job parameter를 넣고 job을 실행했을 때 ,
파라미터값이 달라도 step_execution_id 가 같은 게 참조되고
complited 되어있으니 step을 실행시키지 않는다는 오류가 발생했다.
// All steps already completed or no steps configured for this job.
Step already complete or not restartable, so no action to execute: StepExecution: id=4, version=3, name=helloStep2, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=
해당 job은 같은 파라미터가 중복으로 들어가면 안되기 때문에 incrementer 설정은 추가하지 않았다.
그러면 파라미터값이 달라질 때마다 새로 들어가져야하는데 이전 값을 계속 참조하는 것이 문제였다.
해결방안 1. COMPLETED된 Step도 Job 재실행 대상에 포함하기 - allowStartIfComplete
하지만 이건 임시방편에 불과하다.
내가 원하는 건 별도의 설정없이 job 기본설정들에서 파라미터가 달라지면 돌아가야하는게 맞는데 안되는거니까...
@Bean
public Step limitAllowStepStep1() {
return stepBuilderFactory.get("limitAllowStepStep1")
.tasklet(new Tasklet() {
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println("limitAllowStepStep1");
return RepeatStatus.FINISHED;
}
})
.allowStartIfComplete(true) // COMPLETED 되도 재실행에 포함
.build();
https://devfunny.tistory.com/697
[SpringBatch] COMPLETED된 Step도 Job 재실행 대상에 포함하기 -allowStartIfComplete
Job 재실행 Job의 재실행에 대해서는 아래 포스팅을 참고하자. https://devfunny.tistory.com/680 SpringBatch 에서 JobInstance, JobExecution 의 관계 들어가기전 JobInstance, JobExecution 의 개념은 알고가자..
devfunny.tistory.com
해결방안 2. job parameter를 넣을 때 - 를 빼기.
기존에 다른 블로그에서 job이름과 파라미터를
--spring.batch.jobName = job -jobParam = param
이런 식으로 파라미터 값에 - 하나를 붙여주어 사용했다.
그랬더니 batch_job_execution_params에서 해당 파라미터를 identifying(파라미터값으로 인지)를 못하는 것이다.
- 하나를 붙이면 파라미터값으로 인정을 안해줌으로 없이 그냥 써야한다.
--spring.batch.jobName = job jobParam = param
다음과 같이 없는 상태로 값을 주입해야 파라미터값이로 인지해 identifying = Y로 된다.
그러면 새로운 파라미터로 인지해 기존과 무관하게 새 step을 실행시켜준다.
stackoverflow 참고내용.
-
You need to use double dashes like --date=2018-01-20 as one dash will be removed by the parameters converter (This is related to how Spring Boot handles parameters). This way, the parameter date will end up being -date=2018-01-20 and will be considered as non-identifying. Please let me know if this helps. Sep 11, 2018 at 6:59
-
The logs shows [{-date=2018-01-20, run.id=2, ....] and the parameter is not taken by spring-batch as an identifying parameter ... The problem now is his value, allways null. I'm injecting this parameter using @Value("#{jobParameters[date]}", I've tried '[-date]' in the previous expression but it doesnt work too, throws an exeption. I'm tempted to use a -D system parameter :) Sep 11, 2018 at 14:16
-
update: I've changed the expression to @Value("#{jobParameters['-date']}" and now have the inverse situation. I can inject the parameter in my reader, but it takes the value of first execution Sep 11, 2018 at 14:26
-
The logs shows [{-date=2018-01-20, run.id=2, ....] the parameter is not taken by spring-batch as an identifying parameter but this is what we want right? We want the run.id to be identifying and the date to be non identifying. Is that correct? Sep 11, 2018 at 14:39
Spring Batch: execute same job with different parameters - Stack Overflow
Spring Batch: execute same job with different parameters
I'm newbie in sprint batch, and I couldn't find an answer for my problem. I'm trying to implement a JOB using spring boot and spring batch. My JOB needs a parameter, so I'm executing the application
stackoverflow.com
'Spring > Batch' 카테고리의 다른 글
[Spring Boot Batch] 오류: "Failed to configure a DataSource: ‘url’ attribute is not...". 오류해결 (0) | 2022.09.13 |
---|---|
spring batch 개요 및 아키텍처 (0) | 2022.09.12 |
spring batch의 핵심 10가지 (0) | 2022.09.12 |
[spring batch] job parameter 공백(space) 포함하는 경우. (0) | 2022.08.24 |