You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2012/06/26 16:52:08 UTC
svn commit: r1354041 - in /ofbiz/trunk/framework/service:
entitydef/entitymodel.xml src/org/ofbiz/service/job/JobManager.java
src/org/ofbiz/service/job/PersistedServiceJob.java
Author: jacopoc
Date: Tue Jun 26 14:52:06 2012
New Revision: 1354041
URL: http://svn.apache.org/viewvc?rev=1354041&view=rev
Log:
Added new field "Current Retry Count" and logic to keep track of failed job executions; before this enhancement the check against maxRetry was done querying failed records and the approach had performance issues and could be unreliable because failed records can be purged. However the old mechanism is still used when the new field is not set for backward compatibility.
Modified:
ofbiz/trunk/framework/service/entitydef/entitymodel.xml
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
Modified: ofbiz/trunk/framework/service/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/entitydef/entitymodel.xml?rev=1354041&r1=1354040&r2=1354041&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/service/entitydef/entitymodel.xml Tue Jun 26 14:52:06 2012
@@ -51,6 +51,7 @@ under the License.
<field name="serviceName" type="name"></field>
<field name="loaderName" type="name"></field>
<field name="maxRetry" type="numeric"></field>
+ <field name="currentRetryCount" type="numeric"></field>
<field name="authUserLoginId" type="id-vlong"></field>
<field name="runAsUser" type="id-vlong"></field>
<field name="runtimeDataId" type="id"></field>
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java?rev=1354041&r1=1354040&r2=1354041&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java Tue Jun 26 14:52:06 2012
@@ -410,6 +410,7 @@ public class JobManager {
// set the max retry
jFields.put("maxRetry", Long.valueOf(maxRetry));
+ jFields.put("currentRetryCount", new Long(0));
// create the value and store
GenericValue jobV;
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java?rev=1354041&r1=1354040&r2=1354041&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java Tue Jun 26 14:52:06 2012
@@ -63,6 +63,7 @@ public class PersistedServiceJob extends
private Timestamp storedDate = null;
private long nextRecurrence = -1;
private long maxRetry = -1;
+ private long currentRetryCount = 0;
private boolean warningLogged = false;
/**
@@ -79,7 +80,14 @@ public class PersistedServiceJob extends
this.storedDate = jobValue.getTimestamp("runTime");
this.runtime = storedDate.getTime();
this.maxRetry = jobValue.get("maxRetry") != null ? jobValue.getLong("maxRetry").longValue() : -1;
-
+ Long retryCount = jobValue.getLong("currentRetryCount");
+ if (retryCount != null) {
+ this.currentRetryCount = retryCount.longValue();
+ } else {
+ // backward compatibility
+ this.currentRetryCount = PersistedServiceJob.getRetries(jobValue, this.delegator);
+ }
+
// Debug.logInfo("=============== New PersistedServiceJob, delegator from dctx is [" + dctx.getDelegator().getDelegatorName() + "] and delegator from jobValue is [" + jobValue.getDelegator().getDelegatorName() + "]", module);
}
@@ -173,7 +181,7 @@ public class PersistedServiceJob extends
}
Calendar next = expr.next(Calendar.getInstance());
if (next != null) {
- createRecurrence(job, next.getTimeInMillis());
+ createRecurrence(job, next.getTimeInMillis(), false);
}
}
} catch (GenericEntityException e) {
@@ -182,7 +190,7 @@ public class PersistedServiceJob extends
if (Debug.infoOn()) Debug.logInfo("Job [" + getJobName() + "] Id [" + getJobId() + "] -- Next runtime: " + new Date(nextRecurrence), module);
}
- private void createRecurrence(GenericValue job, long next) throws GenericEntityException {
+ private void createRecurrence(GenericValue job, long next, boolean isRetryOnFailure) throws GenericEntityException {
if (Debug.verboseOn()) Debug.logVerbose("Next runtime returned: " + next, module);
if (next > runtime) {
@@ -198,6 +206,11 @@ public class PersistedServiceJob extends
newJob.set("startDateTime", null);
newJob.set("runByInstanceId", null);
newJob.set("runTime", new java.sql.Timestamp(next));
+ if (isRetryOnFailure) {
+ newJob.set("currentRetryCount", new Long(currentRetryCount + 1));
+ } else {
+ newJob.set("currentRetryCount", new Long(0));
+ }
nextRecurrence = next;
delegator.createSetNextSeqId(newJob);
if (Debug.verboseOn()) Debug.logVerbose("Created next job entry: " + newJob, module);
@@ -251,7 +264,7 @@ public class PersistedServiceJob extends
cal.add(Calendar.MINUTE, ServiceConfigUtil.getFailedRetryMin());
long next = cal.getTimeInMillis();
try {
- createRecurrence(job, next);
+ createRecurrence(job, next, true);
} catch (GenericEntityException gee) {
Debug.logError(gee, "ERROR: Unable to re-schedule job [" + getJobId() + "] to re-run : " + job, module);
}
@@ -339,8 +352,7 @@ public class PersistedServiceJob extends
}
// returns the number of current retries
- private long getRetries() throws InvalidJobException {
- GenericValue job = this.getJob();
+ private static long getRetries(GenericValue job, Delegator delegator) {
String pJobId = job.getString("parentJobId");
if (pJobId == null) {
return 0;
@@ -361,9 +373,6 @@ public class PersistedServiceJob extends
if (maxRetry == -1) {
return true;
}
- if (this.getRetries() < maxRetry) {
- return true;
- }
- return false;
+ return currentRetryCount < maxRetry;
}
}