details: https://code.openbravo.com/erp/devel/pi/rev/23cf0735e7c3
changeset: 20229:23cf0735e7c3
user: Asier Lostalé <asier.lostale <at> openbravo.com>
date: Mon May 06 16:17:45 2013 +0200
summary: fixed bug 23653: Incorrect execution time for daily processes
scheduled PM
- Date format to retrieve next fire time from DB was incorrect (java format
instead of SQL one): as this is queried to be consumed internally don't use
any configurable formatting but a hardcoded one.
- Do not remove next fire time from DB when a process is scheduled.
- Added debugging log.
diffstat:
src/org/openbravo/scheduling/OBScheduler.java | 37 ++++++++----------
src/org/openbravo/scheduling/ProcessMonitor.java | 22 +++++++++--
src/org/openbravo/scheduling/ProcessRequest_data.xsql | 21 ++++++++++-
src/org/openbravo/scheduling/Trigger_data.xsql | 11 ++---
4 files changed, 59 insertions(+), 32 deletions(-)
diffs (275 lines):
diff -r 481da426bf53 -r 23cf0735e7c3
src/org/openbravo/scheduling/OBScheduler.java
--- a/src/org/openbravo/scheduling/OBScheduler.java Mon Apr 29 22:08:56
2013 +0800
+++ b/src/org/openbravo/scheduling/OBScheduler.java Mon May 06 16:17:45
2013 +0200
@@ -11,7 +11,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2008-2012 Openbravo SLU
+ * All portions are Copyright (C) 2008-2013 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -28,7 +28,6 @@
import javax.servlet.ServletException;
-import org.apache.log4j.Logger;
import org.openbravo.base.ConfigParameters;
import org.openbravo.base.ConnectionProviderContextListener;
import org.openbravo.base.secureApp.VariablesSecureApp;
@@ -45,6 +44,8 @@
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author awolski
@@ -54,7 +55,7 @@
private static final OBScheduler INSTANCE = new OBScheduler();
- static Logger log = Logger.getLogger(OBScheduler.class);
+ private static Logger log = LoggerFactory.getLogger(OBScheduler.class);
private static final String OB_GROUP = "OB_QUARTZ_GROUP";
@@ -346,6 +347,8 @@
private static final String MONTH_OPTION_SPECIFIC = "S";
+ private static final SimpleDateFormat DATE_FORMAT = new
SimpleDateFormat("dd-MM-yyyy");
+
/**
* Loads the trigger details from AD_PROCESS_REQUEST and converts them
into a schedulable Quartz
* Trigger instance.
@@ -354,7 +357,7 @@
*/
private static Trigger newInstance(String name, ProcessBundle bundle,
ConnectionProvider conn)
throws ServletException {
- final TriggerData data = TriggerData.select(conn, dateTimeFormat, name);
+ final TriggerData data = TriggerData.select(conn, name);
Trigger trigger = null;
@@ -363,7 +366,6 @@
trigger.getJobDataMap().put(ProcessBundle.KEY, bundle);
return trigger;
}
-
Calendar start = null;
Calendar finish = null;
try {
@@ -373,11 +375,11 @@
} else if (data.timingOption.equals(TIMING_OPTION_LATER)) {
trigger = new SimpleTrigger();
- start = timestamp(data.startDate, data.startTime, dateTimeFormat);
+ start = timestamp(data.startDate, data.startTime);
trigger.setStartTime(start.getTime());
} else if (data.timingOption.equals(TIMING_OPTION_SCHEDULED)) {
- start = timestamp(data.startDate, data.startTime, dateTimeFormat);
+ start = timestamp(data.startDate, data.startTime);
final int second = start.get(Calendar.SECOND);
final int minute = start.get(Calendar.MINUTE);
@@ -475,13 +477,12 @@
if (data.nextFireTime.equals("")) {
trigger.setStartTime(start.getTime());
} else {
- Calendar nextTriggerTime = timestamp(data.nextFireTime,
data.nextFireTime,
- dateTimeFormat);
+ Calendar nextTriggerTime = timestamp(data.nextFireTime,
data.nextFireTime);
trigger.setStartTime(nextTriggerTime.getTime());
}
if (data.finishes.equals(FINISHES)) {
- finish = timestamp(data.finishesDate, data.finishesTime,
dateTimeFormat);
+ finish = timestamp(data.finishesDate, data.finishesTime);
trigger.setEndTime(finish.getTime());
}
@@ -503,6 +504,8 @@
trigger.getJobDataMap().put(Process.PROCESS_NAME, data.processName);
trigger.getJobDataMap().put(Process.PROCESS_ID, data.adProcessId);
+ log.debug("Scheduled process {}. Start time:{}.", data.processName,
trigger.getStartTime());
+
return trigger;
}
@@ -533,27 +536,21 @@
/**
* Utility method to parse a start date string and a start time string
into a date.
*
+ * Expected format for dates: 'dd-MM-yyyy' Expected format for times:
'HH24:MI:SS'
+ *
* @param date
* @param time
- * @param dtFormat
* @return
* @throws ParseException
*/
- private static Calendar timestamp(String date, String time, String
dtFormat)
- throws ParseException {
-
- if (dtFormat == null || dtFormat.trim().equals("")) {
- throw new ParseException("dateTimeFormat cannot be null.", -1);
- }
-
+ private static Calendar timestamp(String date, String time) throws
ParseException {
Calendar cal = null;
- final String dateFormat = dtFormat.substring(0, dtFormat.indexOf(' '));
if (date == null || date.equals("")) {
cal = Calendar.getInstance();
} else {
cal = Calendar.getInstance();
- cal.setTime(new SimpleDateFormat(dateFormat).parse(date));
+ cal.setTime(DATE_FORMAT.parse(date));
}
if (time != null && !time.equals("")) {
diff -r 481da426bf53 -r 23cf0735e7c3
src/org/openbravo/scheduling/ProcessMonitor.java
--- a/src/org/openbravo/scheduling/ProcessMonitor.java Mon Apr 29 22:08:56
2013 +0800
+++ b/src/org/openbravo/scheduling/ProcessMonitor.java Mon May 06 16:17:45
2013 +0200
@@ -32,7 +32,6 @@
import javax.servlet.ServletException;
-import org.apache.log4j.Logger;
import org.openbravo.base.ConfigParameters;
import org.openbravo.base.ConnectionProviderContextListener;
import org.openbravo.database.ConnectionProvider;
@@ -46,6 +45,8 @@
import org.quartz.SchedulerListener;
import org.quartz.Trigger;
import org.quartz.TriggerListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author awolski
@@ -53,7 +54,7 @@
*/
class ProcessMonitor implements SchedulerListener, JobListener,
TriggerListener {
- static final Logger log = Logger.getLogger(ProcessMonitor.class);
+ static final Logger log = LoggerFactory.getLogger(ProcessMonitor.class);
public static final String KEY =
"org.openbravo.scheduling.ProcessMonitor.KEY";
@@ -70,8 +71,8 @@
final ProcessBundle bundle = (ProcessBundle)
trigger.getJobDataMap().get(ProcessBundle.KEY);
final ProcessContext ctx = bundle.getContext();
try {
- ProcessRequestData.update(getConnection(), ctx.getUser(), ctx.getUser(),
SCHEDULED, bundle
- .getChannel().toString(), null, null, null, null, ctx.toString(),
trigger.getName());
+ ProcessRequestData.setContext(getConnection(), ctx.getUser(),
ctx.getUser(), SCHEDULED,
+ bundle.getChannel().toString(), ctx.toString(), trigger.getName());
} catch (final ServletException e) {
log.error(e.getMessage(), e);
@@ -82,6 +83,12 @@
final ProcessBundle bundle = (ProcessBundle)
jec.getMergedJobDataMap().get(ProcessBundle.KEY);
final ProcessContext ctx = bundle.getContext();
try {
+ try {
+ log.debug("triggerFired for process process {}. Next execution time:
{}", jec.getTrigger()
+ .getJobDataMap().getString(Process.PROCESS_NAME),
trigger.getNextFireTime());
+ } catch (Exception ignore) {
+ // ignore: exception while trying to log
+ }
ProcessRequestData.update(getConnection(), ctx.getUser(), ctx.getUser(),
SCHEDULED, bundle
.getChannel().toString(), format(trigger.getPreviousFireTime()),
OBScheduler.sqlDateTimeFormat, format(trigger.getNextFireTime()),
format(trigger
@@ -153,6 +160,13 @@
}
public void triggerMisfired(Trigger trigger) {
+ try {
+ log.debug("Misfired process {}, start time {}.",
+ trigger.getJobDataMap().getString(Process.PROCESS_NAME),
trigger.getStartTime());
+ } catch (Exception e) {
+ // ignore: exception while trying to log
+ }
+
// Not implemented
}
diff -r 481da426bf53 -r 23cf0735e7c3
src/org/openbravo/scheduling/ProcessRequest_data.xsql
--- a/src/org/openbravo/scheduling/ProcessRequest_data.xsql Mon Apr 29
22:08:56 2013 +0800
+++ b/src/org/openbravo/scheduling/ProcessRequest_data.xsql Mon May 06
16:17:45 2013 +0200
@@ -12,7 +12,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2001-2011 Openbravo SLU
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -120,4 +120,23 @@
<Parameter name="obContext"/>
<Parameter name="id"/>
</SqlMethod>
+
+ <SqlMethod name="setContext" type="preparedStatement" return="rowcount">
+ <SqlMethodComment></SqlMethodComment>
+ <Sql><![CDATA[
+ UPDATE AD_Process_Request
+ SET Updatedby = ?,
+ AD_User_ID = ?,
+ Status = ?,
+ Channel = ?,
+ Ob_Context = ?
+ WHERE AD_Process_Request_ID = ?
+ ]]></Sql>
+ <Parameter name="updatedBy"/>
+ <Parameter name="user"/>
+ <Parameter name="status"/>
+ <Parameter name="channel"/>
+ <Parameter name="obContext"/>
+ <Parameter name="id"/>
+ </SqlMethod>
</SqlClass>
\ No newline at end of file
diff -r 481da426bf53 -r 23cf0735e7c3
src/org/openbravo/scheduling/Trigger_data.xsql
--- a/src/org/openbravo/scheduling/Trigger_data.xsql Mon Apr 29 22:08:56
2013 +0800
+++ b/src/org/openbravo/scheduling/Trigger_data.xsql Mon May 06 16:17:45
2013 +0200
@@ -12,7 +12,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2001-2012 Openbravo SLU
+ * All portions are Copyright (C) 2001-2013 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
@@ -22,19 +22,16 @@
<SqlMethod name="select" type="preparedStatement" return="single">
<SqlMethodComment></SqlMethodComment>
<Sql><![CDATA[
- SELECT AD_Process_Request_ID, Timing_Option, TO_CHAR(Start_Time,
'HH24:MI:SS') AS Start_Time, to_char(Start_Date, ?) AS Start_Date,
+ SELECT AD_Process_Request_ID, Timing_Option, TO_CHAR(Start_Time,
'HH24:MI:SS') AS Start_Time, to_char(Start_Date, 'DD-MM-YYYY') AS Start_Date,
Frequency, Secondly_Interval, Secondly_Repetitions, Minutely_Interval,
Minutely_Repetitions,
Hourly_Interval, Hourly_Repetitions, Daily_Interval, Day_Mon, Day_Tue,
Day_Wed, Day_Thu, Day_Fri, Day_Sat, Day_Sun, Monthly_Option,
Monthly_Specific_Day,
- Monthly_Day_Of_Week, Finishes, TO_CHAR(Finishes_Time, 'HH24:MI:SS') AS
Finishes_Time, to_char(Finishes_Date, ?) as Finishes_Date,
- Daily_Option, Cron, r.Description, TO_CHAR(Next_Fire_Time, ?) AS
Next_Fire_Time, p.preventConcurrent, p.name as process_name, p.ad_process_id
+ Monthly_Day_Of_Week, Finishes, TO_CHAR(Finishes_Time, 'HH24:MI:SS') AS
Finishes_Time, to_char(Finishes_Date, 'DD-MM-YYYY') as Finishes_Date,
+ Daily_Option, Cron, r.Description, TO_CHAR(Next_Fire_Time, 'DD-MM-YYYY
HH24:MI:SS') AS Next_Fire_Time, p.preventConcurrent, p.name as process_name,
p.ad_process_id
FROM AD_Process_Request r, AD_Process p
WHERE AD_Process_Request_ID = ?
AND p.AD_Process_ID = r.AD_Process_ID
]]></Sql>
- <Parameter name="dateTimeFormat" />
- <Parameter name="dateTimeFormat" />
- <Parameter name="dateTimeFormat" />
<Parameter name="id"/>
</SqlMethod>
</SqlClass>
\ No newline at end of file
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits