IDEMPIERE-3383 Schedule process: always recalculate sleep time before start

This commit is contained in:
Heng Sin Low 2017-05-31 11:26:32 +08:00
parent d12e72aec3
commit 2b18e84428
2 changed files with 23 additions and 0 deletions

View File

@ -103,6 +103,28 @@ public abstract class AdempiereServer implements Runnable
return Env.getCtx();
} // getCtx
public void recalculateSleepMS()
{
if (p_model instanceof PO)
{
PO po = (PO) p_model;
po.load(null);
}
m_sleepMS = 0;
m_nextWork = 0;
Timestamp lastRun = new Timestamp(System.currentTimeMillis());
m_nextWork = MSchedule.getNextRunMS(lastRun.getTime(),
p_model.getScheduleType(), p_model.getFrequencyType(),
p_model.getFrequency(), p_model.getCronPattern());
m_sleepMS = m_nextWork - lastRun.getTime();
if (log.isLoggable(Level.INFO)) log.info(" Next run: " + new Timestamp(m_nextWork) + " sleep " + m_sleepMS);
//
p_model.setDateNextRun(new Timestamp(m_nextWork));
p_model.saveEx();
}
/**
* @return Returns the sleepMS.
*/

View File

@ -237,6 +237,7 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer<IServerFacto
try
{
// replace
server.getServer().recalculateSleepMS();
server.start();
}
catch (Exception e)