use of org.compiere.model.MSchedulerLog in project adempiere by adempiere.
the class Scheduler method doWork.
/**
* Work
*/
protected void doWork() {
m_summary = new StringBuffer(m_model.toString()).append(" - ");
// Prepare a ctx for the report/process - BF [1966880]
m_schedulerctx.clear();
MClient schedclient = MClient.get(getCtx(), m_model.getAD_Client_ID());
Env.setContext(m_schedulerctx, "#AD_Client_ID", schedclient.getAD_Client_ID());
Env.setContext(m_schedulerctx, "#AD_Language", schedclient.getAD_Language());
Env.setContext(m_schedulerctx, "#AD_Org_ID", m_model.getAD_Org_ID());
if (m_model.getAD_Org_ID() != 0) {
MOrgInfo schedorg = MOrgInfo.get(getCtx(), m_model.getAD_Org_ID(), null);
if (schedorg.getM_Warehouse_ID() > 0)
Env.setContext(m_schedulerctx, "#M_Warehouse_ID", schedorg.getM_Warehouse_ID());
}
Env.setContext(m_schedulerctx, "#AD_User_ID", getAD_User_ID());
Env.setContext(m_schedulerctx, "#SalesRep_ID", getAD_User_ID());
// TODO: It can be convenient to add AD_Scheduler.AD_Role_ID
MUser scheduser = MUser.get(getCtx(), getAD_User_ID());
MRole[] schedroles = scheduser.getRoles(m_model.getAD_Org_ID());
if (schedroles != null && schedroles.length > 0)
// first role, ordered by AD_Role_ID
Env.setContext(m_schedulerctx, "#AD_Role_ID", schedroles[0].getAD_Role_ID());
Timestamp ts = new Timestamp(System.currentTimeMillis());
SimpleDateFormat dateFormat4Timestamp = new SimpleDateFormat("yyyy-MM-dd");
// JDBC format
Env.setContext(m_schedulerctx, "#Date", dateFormat4Timestamp.format(ts) + " 00:00:00");
Properties currentctx = Env.getCtx();
Env.setCtx(m_schedulerctx);
MProcess process = new MProcess(m_schedulerctx, m_model.getAD_Process_ID(), null);
try {
m_trx = Trx.get(Trx.createTrxName("Scheduler"), true);
m_summary.append(runProcess(process));
m_trx.commit(true);
} catch (Exception e) {
if (m_trx != null)
m_trx.rollback();
log.log(Level.WARNING, process.toString(), e);
m_summary.append(e.toString());
} finally {
if (m_trx != null)
m_trx.close();
}
// Restore system context
Env.setCtx(currentctx);
//
int no = m_model.deleteLog();
m_summary.append(" Logs deleted=").append(no);
//
MSchedulerLog pLog = new MSchedulerLog(m_model, m_summary.toString());
pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork)));
pLog.saveEx();
}
Aggregations