protected synchronized void run(WGACore core, Map customOptions, JobExecutionContext quartzContext, String executor) {
Logger logger = Logger.getLogger("wga.job." + _name);
logger.setLevel(Level.INFO);
_currentLog = new StringWriter();
WriterAppender tempAppender = new WriterAppender(JOBLOG_LAYOUT, _currentLog);
logger.addAppender(tempAppender);
_failed = false;
_exception = null;
_running = true;
try {
// Prepare logging
_lastRun = new Date();
if (_scheduler.getLoggingDir() != null) {
initPermanentLog(logger);
}
// Prepare jobContext
JobContext jobContext = new JobContext(this, quartzContext, core, logger);
if (customOptions != null) {
jobContext.getCustomOptions().putAll(customOptions);
}
// Run tasks
if (executor != null) {
logger.info("Starting job " + _name + " started by admin account '" + executor + "'");
}
else {
logger.info("Starting job " + _name + " triggered by WGA Scheduler");
}
runTasks(logger, jobContext);
logger.info("Job execution finished");
if (jobContext.getResult() != null) {
logger.info("End result: " + String.valueOf(jobContext.getResult()));
_lastResult = jobContext.getResult();
}
}
catch (Exception e) {
logger.error("Exception executing job", e);
_exception = e;
_failed = true;
}
catch (Error e) {
logger.error("Error executing job", e);
_exception = e;
_failed = true;
}
finally {
// We switch off stats on the currently registered job of this name
Job currentJob = _scheduler.getJob(_name);
closeStats(logger, currentJob);
if (currentJob != this) {
closeStats(logger, this);
}
if (tempAppender != null) {
tempAppender.close();
logger.removeAppender(tempAppender);
}
}
}