File tree Expand file tree Collapse file tree 2 files changed +11
-10
lines changed
main/java/org/comixedproject/service/batch
test/java/org/comixedproject/service/batch Expand file tree Collapse file tree 2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -126,14 +126,15 @@ private void doDeleteInactiveJobsFor(final String jobName) throws NoSuchJobExcep
126126 jobName , 0 , (int ) this .jobExplorer .getJobInstanceCount (jobName ));
127127 for (int whichInstance = 0 ; whichInstance < jobInstances .size (); whichInstance ++) {
128128 final JobInstance jobInstance = jobInstances .get (whichInstance );
129- final List <JobExecution > jobExecutions = this .jobExplorer .getJobExecutions (jobInstance );
130- for (int whichExecution = 0 ; whichExecution < jobExecutions .size (); whichExecution ++) {
131- final JobExecution jobExecution = jobExecutions .get (whichExecution );
132- if (Objects .nonNull (jobExecution .getExitStatus ())
133- && DELETABLE_JOB_STATUSES .contains (jobExecution .getExitStatus ().getExitCode ())) {
134- log .trace ("Deleting job execution: {}" , jobExecution .getJobId ());
135- this .jobRepository .deleteJobExecution (jobExecution );
136- }
129+ if (this .jobExplorer .getJobExecutions (jobInstance ).stream ()
130+ .filter (execution -> Objects .nonNull (execution .getExitStatus ()))
131+ .filter (
132+ execution ->
133+ !DELETABLE_JOB_STATUSES .contains (execution .getExitStatus ().getExitCode ()))
134+ .toList ()
135+ .isEmpty ()) {
136+ log .debug ("Deleting job instance: id={}" , jobInstance .getId ());
137+ this .jobRepository .deleteJobInstance (jobInstance );
137138 }
138139 }
139140 }
Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ void deleteCompletedJobs_whenCompleted() {
162162 assertNotNull (result );
163163 assertEquals (TEST_INSTANCE_COUNT , result .size ());
164164
165- Mockito .verify (jobRepository , Mockito .times (1 )).deleteJobExecution ( jobExecution );
165+ Mockito .verify (jobRepository , Mockito .times (1 )).deleteJobInstance ( jobInstance );
166166 }
167167
168168 @ Test
@@ -176,7 +176,7 @@ void deleteCompletedJobs_whenFailed() {
176176 assertNotNull (result );
177177 assertEquals (TEST_INSTANCE_COUNT , result .size ());
178178
179- Mockito .verify (jobRepository , Mockito .times (1 )).deleteJobExecution ( jobExecution );
179+ Mockito .verify (jobRepository , Mockito .times (1 )).deleteJobInstance ( jobInstance );
180180 }
181181
182182 @ Test
You can’t perform that action at this time.
0 commit comments