FINERACT-1678: Add retry limit to COB

This commit is contained in:
Adam Saghy
2023-05-10 07:51:10 +02:00
committed by Arnold Gálovics
parent b86a70397f
commit 70c93484f4
8 changed files with 123 additions and 1 deletions
@@ -93,7 +93,8 @@ public class LoanCOBWorkerConfiguration {
public Step loanBusinessStep(@Value("#{stepExecutionContext['partition']}") String partitionName) {
return localStepBuilderFactory.get("Loan Business - Step:" + partitionName)
.<Loan, Loan>chunk(propertyService.getChunkSize(JobName.LOAN_COB.name())).reader(cobWorkerItemReader())
.processor(cobWorkerItemProcessor()).writer(cobWorkerItemWriter()).faultTolerant().skip(Exception.class)
.processor(cobWorkerItemProcessor()).writer(cobWorkerItemWriter()).faultTolerant().retry(Exception.class)
.retryLimit(propertyService.getRetryLimit(LoanCOBConstant.JOB_NAME)).skip(Exception.class)
.skipLimit(propertyService.getChunkSize(JobName.LOAN_COB.name()) + 1).listener(loanItemListener()).build();
}
@@ -147,6 +147,7 @@ public class FineractProperties {
private Integer chunkSize;
private Integer partitionSize;
private Integer threadCount;
private Integer retryLimit;
}
@Getter
@@ -23,4 +23,6 @@ public interface PropertyService {
Integer getPartitionSize(String jobName);
Integer getChunkSize(String jobName);
Integer getRetryLimit(String jobName);
}
@@ -50,4 +50,15 @@ public class PropertyServiceImpl implements PropertyService {
.map(FineractProperties.PartitionedJobProperty::getChunkSize) //
.orElse(1);
}
@Override
public Integer getRetryLimit(String jobName) {
List<FineractProperties.PartitionedJobProperty> jobProperties = fineractProperties.getPartitionedJob()
.getPartitionedJobProperties();
return jobProperties.stream() //
.filter(jobProperty -> jobName.equals(jobProperty.getJobName())) //
.findFirst() //
.map(FineractProperties.PartitionedJobProperty::getRetryLimit) //
.orElse(1);
}
}
@@ -65,6 +65,7 @@ fineract.partitioned-job.partitioned-job-properties[0].job-name=LOAN_COB
fineract.partitioned-job.partitioned-job-properties[0].chunk-size=${LOAN_COB_CHUNK_SIZE:100}
fineract.partitioned-job.partitioned-job-properties[0].partition-size=${LOAN_COB_PARTITION_SIZE:100}
fineract.partitioned-job.partitioned-job-properties[0].thread-count=${LOAN_COB_THREAD_COUNT:1}
fineract.partitioned-job.partitioned-job-properties[0].retry-limit=${LOAN_COB_RETRY_LIMIT:5}
fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_SPRING_EVENTS_ENABLED:true}
fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false}
@@ -0,0 +1,65 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.springbatch;
import static org.assertj.core.api.Assertions.assertThat;
import io.cucumber.java8.En;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.springframework.beans.factory.annotation.Autowired;
public class SpringBatchPropertyServiceDefinitions implements En {
@Autowired
private FineractProperties fineractProperties;
private PropertyService propertyService;
private int partitionSize;
private int chunkSize;
private int retryLimit;
public SpringBatchPropertyServiceDefinitions() {
Given("Property Service is initialized", () -> {
propertyService = new PropertyServiceImpl(fineractProperties);
});
When("partition size is fetched for {string}", (String jobName) -> {
partitionSize = propertyService.getPartitionSize(jobName);
});
When("chunk size is fetched for {string}", (String jobName) -> {
chunkSize = propertyService.getChunkSize(jobName);
});
When("retry limit is fetched for {string}", (String jobName) -> {
retryLimit = propertyService.getRetryLimit(jobName);
});
Then("partition size is {int}", (Integer value) -> {
assertThat(partitionSize).isEqualTo(value);
});
Then("chunk size is {int}", (Integer value) -> {
assertThat(chunkSize).isEqualTo(value);
});
Then("retry limit is {int}", (Integer value) -> {
assertThat(retryLimit).isEqualTo(value);
});
}
}
@@ -43,6 +43,7 @@ fineract.partitioned-job.partitioned-job-properties[0].job-name=LOAN_COB
fineract.partitioned-job.partitioned-job-properties[0].chunk-size=100
fineract.partitioned-job.partitioned-job-properties[0].partition-size=100
fineract.partitioned-job.partitioned-job-properties[0].thread-count=1
fineract.partitioned-job.partitioned-job-properties[0].retry-limit=5
fineract.remote-job-message-handler.spring-events.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_SPRING_EVENTS_ENABLED:true}
fineract.remote-job-message-handler.jms.enabled=${FINERACT_REMOTE_JOB_MESSAGE_HANDLER_JMS_ENABLED:false}
@@ -0,0 +1,40 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
Feature: SpringBatch Infrastructure
@springbatch
Scenario: Verify that spring batch properties are read correctly for LOAN_COB
Given Property Service is initialized
When partition size is fetched for "LOAN_COB"
When chunk size is fetched for "LOAN_COB"
When retry limit is fetched for "LOAN_COB"
Then partition size is 100
Then chunk size is 100
Then retry limit is 5
@springbatch
Scenario: Verify that spring batch default properties are read correctly for non-existing job
Given Property Service is initialized
When partition size is fetched for "INVALID_JOB"
When chunk size is fetched for "INVALID_JOB"
When retry limit is fetched for "INVALID_JOB"
Then partition size is 1
Then chunk size is 1
Then retry limit is 1