IDEMPIERE-2771 Improve 2pack tracing for errors / attach embedded 2pack for reprocessing - implement semaphore (120 secs) to process one 2pack at a time

This commit is contained in:
Carlos Ruiz 2015-08-18 20:29:15 -05:00
parent 1c6eabc3a6
commit 966d02d2fe
4 changed files with 48 additions and 5 deletions

View File

@ -39,10 +39,10 @@ import org.compiere.util.DisplayType;
*/
public class MSysConfig extends X_AD_SysConfig
{
/**
/**
*
*/
private static final long serialVersionUID = 6107779915945715515L;
private static final long serialVersionUID = -2870394087507976203L;
public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION";
public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS";
@ -58,6 +58,7 @@ public class MSysConfig extends X_AD_SysConfig
public static final String APPLICATION_MAIN_VERSION = "APPLICATION_MAIN_VERSION";
public static final String APPLICATION_MAIN_VERSION_SHOWN = "APPLICATION_MAIN_VERSION_SHOWN";
public static final String APPLICATION_OS_INFO_SHOWN = "APPLICATION_OS_INFO_SHOWN";
public static final String ATTACH_EMBEDDED_2PACK = "ATTACH_EMBEDDED_2PACK";
public static final String BACKGROUND_JOB_ALLOWED = "BACKGROUND_JOB_ALLOWED";
public static final String BACKGROUND_JOB_BY_DEFAULT = "BACKGROUND_JOB_BY_DEFAULT";
public static final String BACKGROUND_JOB_MAX_IN_SYSTEM = "BACKGROUND_JOB_MAX_IN_SYSTEM";

View File

@ -13,11 +13,15 @@ package org.adempiere.pipo.srv;
import java.io.File;
import java.sql.Timestamp;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.adempiere.base.IDictionaryService;
import org.adempiere.pipo2.PackIn;
import org.adempiere.pipo2.Zipper;
import org.compiere.model.MAttachment;
import org.compiere.model.MSysConfig;
import org.compiere.model.X_AD_Package_Imp_Proc;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
@ -28,16 +32,30 @@ public class PipoDictionaryService implements IDictionaryService {
CLogger logger = CLogger.getCLogger(PipoDictionaryService.class.getName());
private final Semaphore semaphore;
public PipoDictionaryService() {
super();
semaphore = new Semaphore(1, true);
}
@Override
public void merge(BundleContext context, File packageFile) throws Exception {
if (packageFile == null || !packageFile.exists()) {
logger.info("No PackIn Model found");
return;
}
String trxName = Trx.createTrxName();
String trxName = null;
X_AD_Package_Imp_Proc adPackageImp = null;
PackIn packIn = null;
try {
try {
semaphore.tryAcquire(120, TimeUnit.SECONDS);
} catch (InterruptedException e) {
semaphore.release();
semaphore.acquire();
}
trxName = Trx.createTrxName("PipoDS");
packIn = new PackIn();
packIn.setPackageName(context.getBundle().getSymbolicName());
@ -85,11 +103,25 @@ public class PipoDictionaryService implements IDictionaryService {
Trx.get(trxName, false).commit();
if (logger.isLoggable(Level.INFO)) logger.info("commit " + trxName);
} catch (Exception e) {
adPackageImp.setP_Msg(e.getLocalizedMessage());
logger.log(Level.SEVERE, "importXML:", e);
throw e;
} finally {
Trx.get(trxName, false).close();
adPackageImp.saveEx();
try {
Trx.get(trxName, false).close();
} catch (Exception e) {}
semaphore.release();
adPackageImp.save(); // ignoring exceptions
if (adPackageImp != null && packIn != null) {
// Add the attachment to the packin for possible reprocessing
if (MSysConfig.getBooleanValue(MSysConfig.ATTACH_EMBEDDED_2PACK, true) || ! packIn.isSuccess()) {
// TODO: This sometimes fails with error No archive storage provider found - because the IAttachmentStore required is still not loaded
MAttachment attachment = new MAttachment (adPackageImp.getCtx(), X_AD_Package_Imp_Proc.Table_ID, adPackageImp.getAD_Package_Imp_Proc_ID(), null);
attachment.addEntry(packageFile);
attachment.save(); // ignoring exceptions
}
}
}
}

View File

@ -64,6 +64,7 @@ public class PackIn {
private X_AD_Package_Imp_Proc packinProc;
private List<X_AD_Package_Imp_Detail> importDetails;
private boolean success = false;
public PackIn() {
super();
@ -297,4 +298,12 @@ public class PackIn {
this.packinProc = packinProc;
}
public void setSuccess(boolean success) {
this.success = success;
}
public boolean isSuccess() {
return success;
}
} // PackIn

View File

@ -303,6 +303,7 @@ public class PackInHandler extends DefaultHandler {
packageStatus = "Completed - unresolved";
} else {
packageStatus = "Completed successfully";
packIn.setSuccess(true);
}
}