You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ra...@apache.org on 2016/06/01 06:21:55 UTC

incubator-fineract git commit: FINERACT-145

Repository: incubator-fineract
Updated Branches:
  refs/heads/develop f96d96a14 -> 6f25da56e


FINERACT-145


Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/6f25da56
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/6f25da56
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/6f25da56

Branch: refs/heads/develop
Commit: 6f25da56eaf3370728a6858d89ea7f81bcb6fa51
Parents: f96d96a
Author: Nazeer Hussain Shaik <na...@confluxtechnologies.com>
Authored: Tue May 31 12:48:51 2016 +0530
Committer: Nazeer Hussain Shaik <na...@confluxtechnologies.com>
Committed: Tue May 31 12:48:51 2016 +0530

----------------------------------------------------------------------
 .../jobs/service/SchedulerTriggerListener.java  | 28 +++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/6f25da56/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/SchedulerTriggerListener.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/SchedulerTriggerListener.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/SchedulerTriggerListener.java
index 90a1e1e..b5a1c4b 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/SchedulerTriggerListener.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/SchedulerTriggerListener.java
@@ -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