FINERACT-145

This commit is contained in:
Nazeer Hussain Shaik
2016-05-31 12:48:51 +05:30
parent f96d96a147
commit 6f25da56ea
@@ -18,6 +18,8 @@
*/
package org.apache.fineract.infrastructure.jobs.service;
import java.util.Random;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.infrastructure.security.service.TenantDetailsService;
@@ -26,12 +28,16 @@ import org.quartz.JobKey;
import org.quartz.Trigger;
import org.quartz.Trigger.CompletedExecutionInstruction;
import org.quartz.TriggerListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class SchedulerTriggerListener implements TriggerListener {
private final static Logger logger = LoggerFactory.getLogger(SchedulerTriggerListener.class);
private final String name = "Global trigger Listner";
private final SchedularWritePlatformService schedularService;
@@ -68,7 +74,27 @@ public class SchedulerTriggerListener implements TriggerListener {
if (context.getMergedJobDataMap().containsKey(SchedulerServiceConstants.TRIGGER_TYPE_REFERENCE)) {
triggerType = context.getMergedJobDataMap().getString(SchedulerServiceConstants.TRIGGER_TYPE_REFERENCE);
}
return this.schedularService.processJobDetailForExecution(jobKey, triggerType);
Integer maxNumberOfRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxRetriesOnDeadlock();
Integer maxIntervalBetweenRetries = ThreadLocalContextUtil.getTenant().getConnection().getMaxIntervalBetweenRetries();
Integer numberOfRetries = 0;
boolean proceedJob = false;
while (numberOfRetries <= maxNumberOfRetries) {
try {
proceedJob = this.schedularService.processJobDetailForExecution(jobKey, triggerType);
numberOfRetries = maxNumberOfRetries + 1;
} catch (Exception exception) { //Adding generic exception as it depends on JPA provider
logger.debug("Not able to acquire the lock to update job running status for JobKey: " + jobKey);
try {
Random random = new Random();
int randomNum = random.nextInt(maxIntervalBetweenRetries + 1);
Thread.sleep(1000 + (randomNum * 1000));
numberOfRetries = numberOfRetries + 1;
} catch (InterruptedException e) {
}
}
}
return proceedJob;
}
@Override