* Use Hashtable instead of WeakHashMap for activeCronJobs - we're using function names as keys, so

it's actually bogus to use WeakHashMap, plus WeakHashMap is not synchronized.
* Add event log statements each time cron jobs are executed: List of cron jobs we're going to execute,
   and the map of cron jobs still active from last time.
* Add log statement if CronRunner catches an exception, just so it behaves like the same-thread cron
   execution code.
This commit is contained in:
hns 2005-07-29 13:30:45 +00:00
parent 42989de65e
commit 3c29cd2e32

View file

@ -163,7 +163,7 @@ public final class Application implements IPathElement, Runnable {
private String xmlrpcHandlerName; private String xmlrpcHandlerName;
// the list of currently active cron jobs // the list of currently active cron jobs
private Map activeCronJobs = null; Hashtable activeCronJobs = null;
// the list of custom cron jobs // the list of custom cron jobs
Hashtable customCronJobs = null; Hashtable customCronJobs = null;
@ -361,7 +361,7 @@ public final class Application implements IPathElement, Runnable {
} }
activeRequests = new Hashtable(); activeRequests = new Hashtable();
activeCronJobs = new WeakHashMap(); activeCronJobs = new Hashtable();
customCronJobs = new Hashtable(); customCronJobs = new Hashtable();
// create the skin manager // create the skin manager
@ -1492,6 +1492,9 @@ public final class Application implements IPathElement, Runnable {
jobs.addAll(customCronJobs.values()); jobs.addAll(customCronJobs.values());
CronJob.sort(jobs); CronJob.sort(jobs);
logEvent("Running cron jobs: " + jobs);
logEvent("Cron jobs still running from last minute: " + activeCronJobs);
for (Iterator i = jobs.iterator(); i.hasNext();) { for (Iterator i = jobs.iterator(); i.hasNext();) {
CronJob job = (CronJob) i.next(); CronJob job = (CronJob) i.next();
@ -1522,16 +1525,16 @@ public final class Application implements IPathElement, Runnable {
// the job is run from an extra thread // the job is run from an extra thread
if ((job.getTimeout() > 20000) || if ((job.getTimeout() > 20000) ||
(CronJob.millisToNextFullMinute() < 30000)) { (CronJob.millisToNextFullMinute() < 30000)) {
CronRunner r = new CronRunner(evaluator, job); CronRunner runner = new CronRunner(evaluator, job);
activeCronJobs.put(job.getName(), r); activeCronJobs.put(job.getName(), runner);
r.start(); runner.start();
} else { } else {
try { try {
evaluator.invokeInternal(null, job.getFunction(), evaluator.invokeInternal(null, job.getFunction(),
new Object[0], job.getTimeout()); new Object[0], job.getTimeout());
} catch (Exception ex) { } catch (Exception ex) {
logEvent("error running " + job + ": " + ex.toString()); logEvent("error running " + job + ": " + ex);
} finally { } finally {
releaseEvaluator(evaluator); releaseEvaluator(evaluator);
} }
@ -1949,7 +1952,7 @@ public final class Application implements IPathElement, Runnable {
thisEvaluator.invokeInternal(null, job.getFunction(), thisEvaluator.invokeInternal(null, job.getFunction(),
new Object[0], job.getTimeout()); new Object[0], job.getTimeout());
} catch (Exception ex) { } catch (Exception ex) {
// gets logged in RequestEvaluator logEvent("error running " + job + ": " + ex);
} finally { } finally {
releaseEvaluator(thisEvaluator); releaseEvaluator(thisEvaluator);
thisEvaluator = null; thisEvaluator = null;