details: https://code.openbravo.com/erp/devel/pi/rev/fb7f413caad7 changeset: 20122:fb7f413caad7 user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Apr 16 18:23:36 2013 +0200 summary: Fixes Issue 23548: Defines Background Processes as Prevent Concurrent Executions.
details: https://code.openbravo.com/erp/devel/pi/rev/29bceb9cd953 changeset: 20123:29bceb9cd953 user: David Miguelez <david.miguelez <at> openbravo.com> date: Tue Apr 16 18:22:59 2013 +0200 summary: Fixes Issue 23561: When a Process is defined as Prevent Concurrent Executions, check first if a Process is the same and for the same Client and Organization before canceling it. diffstat: src-db/database/sourcedata/AD_PROCESS.xml | 6 +- src/org/openbravo/scheduling/ProcessMonitor.java | 49 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diffs (100 lines): diff -r ccd4e235b604 -r 29bceb9cd953 src-db/database/sourcedata/AD_PROCESS.xml --- a/src-db/database/sourcedata/AD_PROCESS.xml Tue Apr 16 13:36:20 2013 +0200 +++ b/src-db/database/sourcedata/AD_PROCESS.xml Tue Apr 16 18:22:59 2013 +0200 @@ -2801,7 +2801,7 @@ <!--800064--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> <!--800064--> <UIPATTERN><![CDATA[M]]></UIPATTERN> <!--800064--> <ISADVANCEDFEATURE><![CDATA[N]]></ISADVANCEDFEATURE> -<!--800064--> <PREVENTCONCURRENT><![CDATA[N]]></PREVENTCONCURRENT> +<!--800064--> <PREVENTCONCURRENT><![CDATA[Y]]></PREVENTCONCURRENT> <!--800064--></AD_PROCESS> <!--800067--><AD_PROCESS> @@ -4457,7 +4457,7 @@ <!--800170--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> <!--800170--> <UIPATTERN><![CDATA[M]]></UIPATTERN> <!--800170--> <ISADVANCEDFEATURE><![CDATA[N]]></ISADVANCEDFEATURE> -<!--800170--> <PREVENTCONCURRENT><![CDATA[N]]></PREVENTCONCURRENT> +<!--800170--> <PREVENTCONCURRENT><![CDATA[Y]]></PREVENTCONCURRENT> <!--800170--></AD_PROCESS> <!--800171--><AD_PROCESS> @@ -5652,7 +5652,7 @@ <!--3F2B4AAC707B4CE7B98D2005CF7310B5--> <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID> <!--3F2B4AAC707B4CE7B98D2005CF7310B5--> <UIPATTERN><![CDATA[M]]></UIPATTERN> <!--3F2B4AAC707B4CE7B98D2005CF7310B5--> <ISADVANCEDFEATURE><![CDATA[N]]></ISADVANCEDFEATURE> -<!--3F2B4AAC707B4CE7B98D2005CF7310B5--> <PREVENTCONCURRENT><![CDATA[N]]></PREVENTCONCURRENT> +<!--3F2B4AAC707B4CE7B98D2005CF7310B5--> <PREVENTCONCURRENT><![CDATA[Y]]></PREVENTCONCURRENT> <!--3F2B4AAC707B4CE7B98D2005CF7310B5--></AD_PROCESS> <!--4062D3F4448547C3A2BCDFB09D062BA2--><AD_PROCESS> diff -r ccd4e235b604 -r 29bceb9cd953 src/org/openbravo/scheduling/ProcessMonitor.java --- a/src/org/openbravo/scheduling/ProcessMonitor.java Tue Apr 16 13:36:20 2013 +0200 +++ b/src/org/openbravo/scheduling/ProcessMonitor.java Tue Apr 16 18:22:59 2013 +0200 @@ -208,10 +208,24 @@ } // Checking if there is another instance in execution for this process + for (JobExecutionContext job : jobs) { if (job.getTrigger().getJobDataMap().get(Process.PROCESS_ID) .equals(trigger.getJobDataMap().get(Process.PROCESS_ID)) && !job.getJobInstance().equals(jec.getJobInstance())) { + + ProcessBundle jobAlreadyScheduled = (ProcessBundle) job.getTrigger().getJobDataMap() + .get("org.openbravo.scheduling.ProcessBundle.KEY"); + ProcessBundle newJob = (ProcessBundle) trigger.getJobDataMap().get( + "org.openbravo.scheduling.ProcessBundle.KEY"); + + boolean isSameClient = isSameParam(jobAlreadyScheduled, newJob, "Client"); + + if (!isSameClient + || (isSameClient && !isSameParam(jobAlreadyScheduled, newJob, "Organization"))) { + continue; + } + log.info("There's another instance running, so leaving" + processName); try { @@ -246,6 +260,41 @@ return false; } + private boolean isSameParam(ProcessBundle jobAlreadyScheduled, ProcessBundle newJob, String param) { + ProcessContext jobAlreadyScheduledContext = null; + String jobAlreadyScheduledParam = null; + ProcessContext newJobContext = null; + String newJobParam = null; + + if (jobAlreadyScheduled != null) { + jobAlreadyScheduledContext = jobAlreadyScheduled.getContext(); + if (jobAlreadyScheduledContext != null) { + if ("Client".equals(param)) { + jobAlreadyScheduledParam = jobAlreadyScheduledContext.getClient(); + } else if ("Organization".equals(param)) { + jobAlreadyScheduledParam = jobAlreadyScheduledContext.getOrganization(); + } + } + } + + if (newJob != null) { + newJobContext = newJob.getContext(); + if (newJobContext != null) { + if ("Client".equals(param)) { + newJobParam = newJobContext.getClient(); + } else if ("Organization".equals(param)) { + newJobParam = newJobContext.getOrganization(); + } + } + } + + if (newJobParam != null && jobAlreadyScheduledParam != null + && newJobParam.equals(jobAlreadyScheduledParam)) { + return true; + } + return false; + } + /** * @return the database Connection Provider */ ------------------------------------------------------------------------------ Precog is a next-generation analytics platform capable of advanced analytics on semi-structured data. The platform includes APIs for building apps and a phenomenal toolset for data science. Developers can use our toolset for easy data analysis & visualization. Get a free account! http://www2.precog.com/precogplatform/slashdotnewsletter _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits