IDEMPIERE-3670 Schedule process: always recalculate sleep time before start and startAll

This commit is contained in:
Heng Sin Low 2018-04-05 16:59:14 +08:00
parent deecf48074
commit 3d675e132c
2 changed files with 16 additions and 6 deletions

View File

@ -117,13 +117,21 @@ public abstract class AdempiereServer implements Runnable
}
m_sleepMS = 0;
m_nextWork = 0;
Timestamp dateNextRun = getDateNextRun(true);
Timestamp now = new Timestamp(System.currentTimeMillis());
if (dateNextRun != null)
{
m_nextWork = dateNextRun.getTime();
}
else
{
m_nextWork = MSchedule.getNextRunMS(now.getTime(),
p_model.getScheduleType(), p_model.getFrequencyType(),
p_model.getFrequency(), p_model.getCronPattern());
}
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 (m_nextWork > now.getTime())
m_sleepMS = m_nextWork - now.getTime();
if (log.isLoggable(Level.INFO)) log.info(" Next run: " + new Timestamp(m_nextWork) + " sleep " + m_sleepMS);
//
p_model.setDateNextRun(new Timestamp(m_nextWork));

View File

@ -176,6 +176,7 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer<IServerFacto
* @param scheduler
* @return true
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public boolean addScheduler(MScheduler scheduler) {
String serverId = scheduler.getServerID();
if (getServer(serverId) != null)
@ -226,6 +227,7 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer<IServerFacto
continue;
// Do start
// replace
server.getServer().recalculateSleepMS();
server.start();
}
catch (Exception e)