Author: adrianc
Date: Mon Sep 15 17:10:17 2008
New Revision: 695695
URL: http://svn.apache.org/viewvc?rev=695695&view=rev
Log:
Updated the job scheduler to use temporal expressions. Recurrence rules still
work - so there is no rush to change existing installations.
I moved the recurrence count to the job sandbox. Keeping counters in the
recurrence info was a bad idea. Any other code that relied upon counters in
recurrence info will have to be redesigned to use temporal expressions.
Modified:
ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
ofbiz/trunk/framework/entityext/data/EntityScheduledServices.xml
ofbiz/trunk/framework/service/data/ScheduledServices.xml
ofbiz/trunk/framework/service/entitydef/entitymodel.xml
ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/job/PersistedServiceJob.java
Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=695695&r1=695694&r2=695695&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Mon Sep 15
17:10:17 2008
@@ -160,9 +160,8 @@
<!-- The following three elements set up a regularly scheduled job that
will automatically create
fixed asset maintenances from ProductMaint time intervals. -->
- <RecurrenceRule recurrenceRuleId="FAM_AUTO_CREATE" untilDateTime=""
frequency="MINUTELY" intervalNumber="5" countNumber="-1"/>
- <RecurrenceInfo recurrenceInfoId="FAM_AUTO_CREATE"
startDateTime="2000-01-01 00:00:00.000" recurrenceRuleId="FAM_AUTO_CREATE"
recurrenceCount="0"/>
- <JobSandbox jobId="FAM_AUTO_CREATE" jobName="Auto-create Fixed Asset
Maintenances" runTime="2000-01-01 00:00:00.000"
serviceName="createMaintsFromTimeInterval" poolId="pool" runAsUser="system"
recurrenceInfoId="FAM_AUTO_CREATE"/>
+ <TemporalExpression tempExprId="FAM_AUTO_CREATE"
tempExprTypeId="FREQUENCY" date1="2000-01-01 00:00:00.000" integer1="12"
integer2="5"/>
+ <JobSandbox jobId="FAM_AUTO_CREATE" jobName="Auto-create Fixed Asset
Maintenances" runTime="2000-01-01 00:00:00.000"
serviceName="createMaintsFromTimeInterval" poolId="pool" runAsUser="system"
tempExprId="FAM_AUTO_CREATE" maxRecurrenceCount="-1"/>
<!-- Fixed Asset Maintenance party roles -->
<RoleType description="Fixed Asset Maint Assignee" hasTable="N"
roleTypeId="FAM_ASSIGNEE"/>
Modified: ofbiz/trunk/framework/entityext/data/EntityScheduledServices.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/data/EntityScheduledServices.xml?rev=695695&r1=695694&r2=695695&view=diff
==============================================================================
--- ofbiz/trunk/framework/entityext/data/EntityScheduledServices.xml (original)
+++ ofbiz/trunk/framework/entityext/data/EntityScheduledServices.xml Mon Sep 15
17:10:17 2008
@@ -18,9 +18,7 @@
under the License.
-->
<entity-engine-xml>
- <RecurrenceRule recurrenceRuleId="270" untilDateTime="" frequency="DAILY"
intervalNumber="1" countNumber="-1"/>
- <RecurrenceInfo recurrenceInfoId="270" startDateTime="2000-01-01
00:00:00.000" recurrenceRuleId="270" recurrenceCount="0"/>
- <JobSandbox jobId="8200" jobName="Clear EntitySyncRemove Info"
runTime="2000-01-01 00:00:00.000" serviceName="cleanSyncRemoveInfo"
poolId="pool" runAsUser="system" recurrenceInfoId="270"/>
+ <JobSandbox jobId="8200" jobName="Clear EntitySyncRemove Info"
runTime="2000-01-01 00:00:00.000" serviceName="cleanSyncRemoveInfo"
poolId="pool" runAsUser="system" tempExprId="MIDNIGHT_DAILY"
maxRecurrenceCount="-1"/>
<!-- EntitySync example, with Job demo -->
<!-- Increased default split time to 10 minutes (600000 seconds) instead
of 10 seconds, for demonstrations and normal
Modified: ofbiz/trunk/framework/service/data/ScheduledServices.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/data/ScheduledServices.xml?rev=695695&r1=695694&r2=695695&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/data/ScheduledServices.xml (original)
+++ ofbiz/trunk/framework/service/data/ScheduledServices.xml Mon Sep 15
17:10:17 2008
@@ -18,8 +18,6 @@
under the License.
-->
<entity-engine-xml>
- <RecurrenceRule recurrenceRuleId="100" untilDateTime="" frequency="DAILY"
intervalNumber="1" countNumber="-1"/>
- <RecurrenceInfo recurrenceInfoId="100" startDateTime="2000-01-01
00:00:00.000" recurrenceRuleId="100" recurrenceCount="0"/>
-
- <JobSandbox jobId="8300" jobName="Purge Old Jobs" runTime="2000-01-01
00:00:00.000" serviceName="purgeOldJobs" poolId="pool" runAsUser="system"
recurrenceInfoId="100"/>
+ <TemporalExpression tempExprId="MIDNIGHT_DAILY" tempExprTypeId="FREQUENCY"
date1="2000-01-01 00:00:00.000" integer1="5" integer2="1"/>
+ <JobSandbox jobId="PURGE_OLD_JOBS" jobName="Purge Old Jobs"
runTime="2000-01-01 00:00:00.000" serviceName="purgeOldJobs" poolId="pool"
runAsUser="system" tempExprId="MIDNIGHT_DAILY" maxRecurrenceCount="-1"/>
</entity-engine-xml>
Modified: ofbiz/trunk/framework/service/entitydef/entitymodel.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/entitydef/entitymodel.xml?rev=695695&r1=695694&r2=695695&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/service/entitydef/entitymodel.xml Mon Sep 15 17:10:17
2008
@@ -56,7 +56,10 @@
<field name="authUserLoginId" type="id-vlong"></field>
<field name="runAsUser" type="id-vlong"></field>
<field name="runtimeDataId" type="id"></field>
- <field name="recurrenceInfoId" type="id"></field>
+ <field name="recurrenceInfoId" type="id"><description>Deprecated - use
tempExprId instead</description></field>
+ <field name="tempExprId" type="id"><description>Temporal expression
id</description></field>
+ <field name="currentRecurrenceCount" type="numeric"></field>
+ <field name="maxRecurrenceCount" type="numeric"></field>
<field name="runByInstanceId" type="id"></field>
<field name="startDateTime" type="date-time"></field>
<field name="finishDateTime" type="date-time"></field>
@@ -65,6 +68,9 @@
<relation type="one" fk-name="JOB_SNDBX_RECINFO"
rel-entity-name="RecurrenceInfo">
<key-map field-name="recurrenceInfoId"/>
</relation>
+ <relation type="one" fk-name="JOB_SNDBX_TEMPEXPR"
rel-entity-name="TemporalExpression">
+ <key-map field-name="tempExprId"/>
+ </relation>
<relation type="one" fk-name="JOB_SNDBX_RNTMDTA"
rel-entity-name="RuntimeData">
<key-map field-name="runtimeDataId"/>
</relation>
@@ -91,7 +97,7 @@
<field name="recurrenceDateTimes" type="very-long"></field>
<field name="exceptionRuleId" type="id-ne"></field>
<field name="recurrenceRuleId" type="id-ne"></field>
- <field name="recurrenceCount" type="numeric"></field>
+ <field name="recurrenceCount" type="numeric"><description>Not
recommended - more than one process could be using this
RecurrenceInfo</description></field>
<prim-key field="recurrenceInfoId"/>
<relation type="one" fk-name="REC_INFO_RCRLE"
rel-entity-name="RecurrenceRule">
<key-map field-name="recurrenceRuleId"/>
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java?rev=695695&r1=695694&r2=695695&view=diff
==============================================================================
---
ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java
(original)
+++
ofbiz/trunk/framework/service/src/org/ofbiz/service/calendar/RecurrenceInfo.java
Mon Sep 15 17:10:17 2008
@@ -19,6 +19,7 @@
package org.ofbiz.service.calendar;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
@@ -27,6 +28,7 @@
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.StringUtil;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.service.calendar.TemporalExpression;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
@@ -325,4 +327,41 @@
throw rie;
}
}
+
+ public static TemporalExpression toTemporalExpression(RecurrenceInfo info)
{
+ if (info == null) {
+ throw new IllegalArgumentException("info argument cannot be null");
+ }
+ return new RecurrenceWrapper(info);
+ }
+
+ @SuppressWarnings("serial")
+ protected static class RecurrenceWrapper extends TemporalExpression {
+ protected RecurrenceInfo info;
+ protected RecurrenceWrapper() {}
+ public RecurrenceWrapper(RecurrenceInfo info) {
+ this.info = info;
+ }
+ public Calendar first(Calendar cal) {
+ long result = info.first();
+ if (result == 0) {
+ return null;
+ }
+ Calendar first = (Calendar) cal.clone();
+ first.setTimeInMillis(result);
+ return first;
+ }
+ public boolean includesDate(Calendar cal) {
+ return info.isValidCurrent(cal.getTimeInMillis());
+ }
+ public Calendar next(Calendar cal) {
+ long result = info.next(cal.getTimeInMillis());
+ if (result == 0) {
+ return null;
+ }
+ Calendar next = (Calendar) cal.clone();
+ next.setTimeInMillis(result);
+ return next;
+ }
+ }
}
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=695695&r1=695694&r2=695695&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
Mon Sep 15 17:10:17 2008
@@ -31,15 +31,15 @@
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilGenerics;
-import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.service.calendar.TemporalExpression;
+import org.ofbiz.service.calendar.TemporalExpressionWorker;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityFieldMap;
-import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.serialize.SerializeException;
import org.ofbiz.entity.serialize.XmlSerializer;
import org.ofbiz.service.DispatchContext;
@@ -52,6 +52,7 @@
/**
* Entity Service Job - Store => Schedule => Run
*/
[EMAIL PROTECTED]("serial")
public class PersistedServiceJob extends GenericServiceJob {
public static final String module = PersistedServiceJob.class.getName();
@@ -60,6 +61,7 @@
private Timestamp storedDate = null;
private long nextRecurrence = -1;
private long maxRetry = -1;
+ private boolean warningLogged = false;
/**
* Creates a new PersistedServiceJob
@@ -122,23 +124,56 @@
// configure any addition recurrences
GenericValue job = this.getJob();
+ long maxRecurrenceCount = -1;
+ long currentRecurrenceCount = 0;
+ TemporalExpression expr = null;
RecurrenceInfo recurrence = JobManager.getRecurrenceInfo(job);
+ if (recurrence != null) {
+ if (!this.warningLogged) {
+ Debug.logWarning("Persisted Job [" + getJobId() + "]
references a RecurrenceInfo, recommend using TemporalExpression instead",
module);
+ this.warningLogged = true;
+ }
+ currentRecurrenceCount = recurrence.getCurrentCount();
+ expr = RecurrenceInfo.toTemporalExpression(recurrence);
+ }
+ if (expr == null &&
UtilValidate.isNotEmpty(job.getString("tempExprId"))) {
+ try {
+ expr =
TemporalExpressionWorker.getTemporalExpression(this.delegator,
job.getString("tempExprId"));
+ } catch (GenericEntityException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+ }
String instanceId =
UtilProperties.getPropertyValue("general.properties", "unique.instanceId",
"ofbiz0");
if (!instanceId.equals(job.getString("runByInstanceId"))) {
throw new InvalidJobException("Job has been accepted by a
different instance!");
}
+ if (job.get("maxRecurrenceCount") != null) {
+ maxRecurrenceCount = job.getLong("maxRecurrenceCount").longValue();
+ }
+ if (job.get("currentRecurrenceCount") != null) {
+ currentRecurrenceCount =
job.getLong("currentRecurrenceCount").longValue();
+ }
+ if (maxRecurrenceCount != -1) {
+ currentRecurrenceCount++;
+ job.set("currentRecurrenceCount", currentRecurrenceCount);
+ }
+
try {
- if (recurrence != null) {
- recurrence.incrementCurrentCount();
- long next = recurrence.next();
- createRecurrence(job, next);
+ if (expr != null && (maxRecurrenceCount == -1 ||
currentRecurrenceCount <= maxRecurrenceCount)) {
+ if (recurrence != null) {
+ recurrence.incrementCurrentCount();
+ }
+ Calendar next = expr.next(Calendar.getInstance());
+ if (next != null) {
+ createRecurrence(job, next.getTimeInMillis());
+ }
}
} catch (GenericEntityException e) {
throw new RuntimeException(e.getMessage());
}
- if (Debug.infoOn()) Debug.logInfo(this.toString() + "[" + getJobId() +
"] -- Next runtime: " + new java.sql.Timestamp(nextRecurrence), module);
+ if (Debug.infoOn()) Debug.logInfo(this.toString() + "[" + getJobId() +
"] -- Next runtime: " + new Date(nextRecurrence), module);
}
private void createRecurrence(GenericValue job, long next) throws
GenericEntityException {