private int insertJobDetail(Connection conn, JobExecutionContext context) throws IOException, SQLException, SchedulerException { JobDetail job = context.getJobDetail(); JobDataMap jobDataMap = job.getJobDataMap(); Object oResult = context.getResult(); ByteArrayOutputStream baos = serializeJobData(jobDataMap); ByteArrayOutputStream baosResult = serializeObject(oResult); PreparedStatement ps = null; int insertResult = 0; try { ps = conn.prepareStatement(rtp(INSERT_JOB_DETAIL_TRACK, scheduler.getSchedulerName())); ps.setString(1, job.getKey().getName()); ps.setString(2, job.getKey().getGroup()); String instanceId = context.getFireInstanceId(); ps.setString(3, instanceId); ps.setString(4, job.getDescription()); ps.setString(5, job.getJobClass().getName()); // TODO verify it works with DB2v8 // DB2v8 : ps.setInt(6, ((job.isDurable()) ? 1 : 0)); ps.setBoolean(6, job.isDurable()); // TODO verify it works with DB2v8 // DB2v8 : ps.setInt(7, ((job.isConcurrentExectionDisallowed()) ? 1 : 0)); ps.setBoolean(7, job.isConcurrentExectionDisallowed()); // TODO verify it works with DB2v8 // DB2v8 : ps.setInt(8, ((job.isPersistJobDataAfterExecution()) ? 1 : 0)); ps.setBoolean(8, job.isPersistJobDataAfterExecution()); // TODO verify it works with DB2v8 // DB2v8 : ps.setInt(9, ((job.requestsRecovery()) ? 1 : 0)); ps.setBoolean(9, job.requestsRecovery()); // TODO verify it works with Sybase // Sybase : ps.setBytes(10, (baos == null) ? null: baos.toByteArray()); ps.setBytes(10, (baos == null) ? new byte[0] : baos.toByteArray()); ps.setBytes(11, (baosResult == null) ? new byte[0] : baosResult.toByteArray()); String restartedInstanceId = jobDataMap.getString(RESTARTED_FIRE_INSTANCE_ID); ps.setString(12, restartedInstanceId); String returnCode = null; if (oResult instanceof JobDataMap) { returnCode = ((JobDataMap) oResult).getString(QuartzContextAdapter.RETURN_CODE); } else { returnCode = String.valueOf(oResult); } ps.setString(13, returnCode); insertResult = ps.executeUpdate(); } finally { closeStatement(ps); cleanupConnection(conn); } return insertResult; }
/** @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext, JobExecutionException) */ public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { Trigger trigger = context.getTrigger(); Object[] args = null; Object oResult = context.getResult(); String result = showJobDataMap(oResult); if (jobException != null) { String errMsg = jobException.getMessage(); args = new Object[] { context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), Integer.valueOf(context.getRefireCount()), context.getFireInstanceId(), result, errMsg }; try { insertJobDetail(this.getNonManagedTXConnection(), context); getLog().info(MessageFormat.format(getJobFailedMessage(), args)); // without exception trace // getLog().info(MessageFormat.format(getJobFailedMessage(), args), // jobException); } catch (Exception e) { getLog().error(MessageFormat.format(getJobFailedMessage(), args, e)); } } else { args = new Object[] { context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), Integer.valueOf(context.getRefireCount()), context.getFireInstanceId(), result }; try { insertJobDetail(this.getNonManagedTXConnection(), context); getLog().info(MessageFormat.format(getJobSuccessMessage(), args)); } catch (Exception e) { getLog().error(MessageFormat.format(getJobSuccessMessage(), args, e)); } } }
/** * @param context * @param jobException * @see org.quartz.JobListener#jobWasExecuted(JobExecutionContext, JobExecutionException) Called * by the Scheduler after a JobDetail has been executed, and be for the associated Trigger's * triggered method has been called */ @Override public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { try { String ipAddress = getIpAddress(); Trigger trigger = context.getTrigger(); Object[] args; if (jobException != null) { /*if (!getLog().isWarnEnabled()) { return; }*/ String errMsg = jobException.getMessage(); args = new Object[] { context.getFireInstanceId(), context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), jobDataMapToString(context.getJobDetail().getJobDataMap()), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime() != null ? trigger.getPreviousFireTime() : new Date(0), trigger.getNextFireTime() != null ? trigger.getNextFireTime() : new Date(0), Integer.toString(context.getRefireCount()), errMsg, context.getScheduler().getSchedulerInstanceId(), context.getScheduler().getSchedulerName(), ipAddress != null ? ipAddress : "", "FAILED", "LoggingJobHistoryPluginCustom", "INFO" }; // getLog().warn(MessageFormat.format(getJobFailedMessage(), args), jobException); // log data and set progress value as null because it has not to be updated in the database // row logToDatabase(args, MessageFormat.format(getJobFailedMessage(), args), true, null); } else { /*if (!getLog().isInfoEnabled()) { return; }*/ String result = String.valueOf(context.getResult()); args = new Object[] { context.getFireInstanceId(), context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), jobDataMapToString(context.getJobDetail().getJobDataMap()), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime() != null ? trigger.getPreviousFireTime() : new Date(0), trigger.getNextFireTime() != null ? trigger.getNextFireTime() : new Date(0), Integer.toString(context.getRefireCount()), result, // truncateResult(result) truncate result if too long to insert in the // database context.getScheduler().getSchedulerInstanceId(), context.getScheduler().getSchedulerName(), ipAddress != null ? ipAddress : "", "SUCCESS", "LoggingJobHistoryPluginCustom", "INFO" }; // getLog().info(MessageFormat.format(getJobSuccessMessage(), args)); // log data and set progress value as 100 because the job completed successfully logToDatabase(args, MessageFormat.format(getJobSuccessMessage(), args), true, "100"); } } catch (SQLException | SchedulerException e) { e.printStackTrace(); } }