You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by GitBox <gi...@apache.org> on 2019/03/06 11:06:39 UTC

[GitHub] [fineract] vorburger commented on a change in pull request #524: FINERACT-428 Parallelization of Jobs : Parallelizing and paging of recalculate interest for loans

vorburger commented on a change in pull request #524: FINERACT-428 Parallelization of Jobs : Parallelizing and paging of recalculate interest for loans
URL: https://github.com/apache/fineract/pull/524#discussion_r262893899
 
 

 ##########
 File path: fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanSchedularServiceImpl.java
 ##########
 @@ -184,4 +191,133 @@ public void recalculateInterest() throws JobExecutionException {
 
 	}
 
-}
+	@Override
+	@CronTarget(jobName = JobName.RECALCULATE_INTEREST_FOR_LOAN)
+	public void recalculateInterest(Map<String, String> jobParameters) {
+		//gets the officeId
+		final String officeId = jobParameters.get("officeId");
+		logger.info(officeId);
+		Long officeIdLong=Long.valueOf(officeId);
+		//gets the Office object
+		final Office office = this.officeRepository.findOne(officeIdLong);
+		if(office == null)
+			throw new OfficeNotFoundException(officeIdLong);
+		final int threadPoolSize=Integer.parseInt(jobParameters.get("thread-pool-size"));
+		final int batchSize=Integer.parseInt(jobParameters.get("batch-size"));
+
+		recalculateInterest(office,threadPoolSize,batchSize);
+	}
+
+	@Override
+	public void recalculateInterest(Office office, int threadPoolSize, int batchSize) {
+		final int pageSize = batchSize * threadPoolSize;
+
+		//initialise the executor service with fetched configurations
+		final ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
+
+		Long maxLoanIdInList = 0L;
+		final String officeHierarchy = office.getHierarchy() + "%";
+
+		//Get the loanIds from service
+		List<Long> loanIds = this.loanReadPlatformService
+				.fetchLoansForInterestRecalculation(pageSize, maxLoanIdInList, officeHierarchy);
+
+		// gets the loanIds data set iteratively and call addAccuruals for that paginated dataset
+		do {
+			int totalFilteredRecords = loanIds.size();
+			logger.info("Starting accrual - total filtered records - " + totalFilteredRecords);
+			recalculateInterest(loanIds, threadPoolSize, batchSize,
+					executorService);
+			maxLoanIdInList+=pageSize+1;
+			loanIds = this.loanReadPlatformService
+					.fetchLoansForInterestRecalculation(pageSize, maxLoanIdInList, officeHierarchy);
+		} while (!CollectionUtils.isEmpty(loanIds));
 
 Review comment:
   make sure that `List<Long> loanIds` is something like `Collections.synchronizedList(new ArrayList())` should be fine as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services