private void runTimerJobs()
{
Date now = new Date();
long nowMs = now.getTime();
boolean anyJobsRun = false;
ActionProcessor actionProcessor = Session.getInstance().getActionProcessor();
for (int numMinutes : jobs.keySet())
{
// has it been more that numMinutes since this batch last ran?
Date lastRun = lastRunTimes.get(numMinutes);
boolean okToRun = true;
if (lastRun != null)
{
long deltaSec = (nowMs - lastRun.getTime()) / MS_IN_SEC;
long requiredSec = numMinutes * SEC_IN_MIN - TIMER_MERCY_SEC;
okToRun = deltaSec >= requiredSec;
}
if (okToRun)
{
for (String job : jobs.get(numMinutes))
{
if (!anyJobsRun)
{
anyJobsRun = true;
actionProcessor.setQueueRequests(true);
}
try
{
if (fetchables.containsKey(job) && !pausedJobs.contains(job))
{
fetchables.get(job).fetch(requests.get(job), false);
}
}
catch (Exception ex)
{
// Just making sure ANYTHING that goes wrong doesn't hose the entire app.
int x = 0;
}
}
// mark this batch as having run (using the base
lastRunTimes.put(numMinutes, now);
}
}
if (anyJobsRun)
{
actionProcessor.setQueueRequests(false);
actionProcessor.fireQueuedRequests();
}
}