NewsFetcher: Delay news fetch on new installs (ticket #1153)

This commit is contained in:
zzz
2014-01-09 14:03:49 +00:00
parent 80fadb4580
commit 9757435b09

View File

@ -25,15 +25,20 @@ class NewsTimerTask implements SimpleTimer.TimedEvent {
private volatile boolean _firstRun = true;
private static final long INITIAL_DELAY = 5*60*1000;
private static final long NEW_INSTALL_DELAY = 25*60*1000;
private static final long RUN_DELAY = 10*60*1000;
public NewsTimerTask(RouterContext ctx, ConsoleUpdateManager mgr) {
_context = ctx;
_log = ctx.logManager().getLog(NewsTimerTask.class);
_mgr = mgr;
ctx.simpleScheduler().addPeriodicEvent(this,
INITIAL_DELAY + _context.random().nextLong(INITIAL_DELAY),
RUN_DELAY);
long installed = ctx.getProperty("router.firstInstalled", 0L);
boolean isNew = (ctx.clock().now() - installed) < 30*60*1000L;
long delay = isNew ? NEW_INSTALL_DELAY : INITIAL_DELAY;
delay += _context.random().nextLong(INITIAL_DELAY);
if (_log.shouldLog(Log.INFO))
_log.info("Scheduling first news check in " + DataHelper.formatDuration(delay));
ctx.simpleScheduler().addPeriodicEvent(this, delay, RUN_DELAY);
// UpdateManager calls NewsFetcher to check the existing news at startup
}