下面列出了org.quartz.JobExecutionContext#getFireTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @return composite data
*/
public static CompositeData toCompositeData(JobExecutionContext jec)
throws SchedulerException {
try {
return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
new Object[] {
jec.getScheduler().getSchedulerName(),
jec.getTrigger().getKey().getName(),
jec.getTrigger().getKey().getGroup(),
jec.getJobDetail().getKey().getName(),
jec.getJobDetail().getKey().getGroup(),
JobDataMapSupport.toTabularData(jec
.getMergedJobDataMap()),
jec.getTrigger().getCalendarName(),
jec.isRecovering(),
jec.getRefireCount(),
jec.getFireTime(), jec.getScheduledFireTime(),
jec.getPreviousFireTime(), jec.getNextFireTime(),
jec.getJobRunTime(),
jec.getFireInstanceId() });
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
}
/**
* @return composite data
*/
public static CompositeData toCompositeData(JobExecutionContext jec)
throws SchedulerException {
try {
return new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
new Object[] {
jec.getScheduler().getSchedulerName(),
jec.getTrigger().getFullName(),
jec.getJobDetail().getFullName(),
JobDataMapSupport.toTabularData(jec
.getMergedJobDataMap()),
determineCalendarName(jec),
Boolean.valueOf(jec.isRecovering()),
Integer.valueOf(jec.getRefireCount()),
jec.getFireTime(), jec.getScheduledFireTime(),
jec.getPreviousFireTime(), jec.getNextFireTime(),
Long.valueOf(jec.getJobRunTime()) });
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
}
/**
* Fill common attributes with properties from context.
*/
public void fillWithContext(JobExecutionContext context) {
startDate = context.getFireTime();
jobClass = Jobs.jobCass(context.getJobDetail()).getName();
JobKey key = context.getJobDetail().getKey();
jobKey = Keys.desc(key);
jobGroup = key.getGroup();
jobName = key.getName();
TriggerKey key2 = context.getTrigger().getKey();
triggerKey = Keys.desc(key2);
triggerGroup = key2.getGroup();
triggerName = key2.getName();
dataMap = JobDataMapUtils.toProperties(context.getMergedJobDataMap());
}
private void postExecute(JobExecutionContext context, SysJobRepository jobRepository) {
long endTime = System.currentTimeMillis();
SysJob sysJob = jobRepository.getOne(jobId);
if (null != context.getFireTime()) {
sysJob.setRuntimeLast(context.getFireTime());
}
if (null != context.getNextFireTime()) {
sysJob.setRuntimeNext(context.getNextFireTime());
}
int runtimes = (null == sysJob.getRuntimes()) ? 0 : sysJob.getRuntimes();
sysJob.setRuntimes(runtimes + 1);
sysJob.setRunDuration(endTime - beginTime);
sysJob.setJobStatus(JobConstantUtils.JOB_RUN_STATUS_AWAITING);
jobRepository.save(sysJob);
}
public ScheduleLogRequest(JobExecutionContext jobExecutionContext, JobExecutionException jobExecutionException) {
JobDetail jobDetail = jobExecutionContext.getJobDetail();
this.className = jobDetail.getKey().getName();
this.application = jobDetail.getKey().getGroup();
this.node = jobDetail.getDescription();
this.type = jobExecutionContext.getTrigger().getDescription();
this.elapsed = jobExecutionContext.getJobRunTime();
this.fireTime = jobExecutionContext.getFireTime();
if (null != jobExecutionException) {
this.stackTrace = ExceptionUtils.getStackTrace(jobExecutionException);
this.success = false;
} else {
this.success = true;
}
}
public void execute(JobExecutionContext jobInfo) throws JobExecutionException {
loginToSakai("admin");
String jobName = jobInfo.getJobDetail().getKey().getName();
String triggerName = jobInfo.getTrigger().getKey().getName();
Date requestedFire = jobInfo.getScheduledFireTime();
Date actualfire = jobInfo.getFireTime();
StringBuffer whoAmI = new StringBuffer("AutoSubmitAssessmentsJob $");
whoAmI.append(" Job: ");
whoAmI.append(jobName);
whoAmI.append(" Trigger: ");
whoAmI.append(triggerName);
if (requestedFire != null) {
whoAmI.append(" Fire scheduled: ");
whoAmI.append(requestedFire.toString());
}
if (actualfire != null) {
whoAmI.append(" Fire actual: ");
whoAmI.append(actualfire.toString());
}
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_AUTO_SUBMIT_JOB, safeEventLength(whoAmI.toString()), true));
log.info("Start Job: {}", whoAmI);
GradingService gradingService = new GradingService();
int failures = gradingService.autoSubmitAssessments();
if (failures > 0)
{
samigoETSProvider.notifyAutoSubmitFailures(failures);
}
log.info("End Job: {} ({} failures)", whoAmI, failures);
logoutFromSakai();
}
public void execute(JobExecutionContext jobInfo) throws JobExecutionException {
loginToSakai("admin");
String jobName = jobInfo.getJobDetail().getKey().getName();
String triggerName = jobInfo.getTrigger().getKey().getName();
Date requestedFire = jobInfo.getScheduledFireTime();
Date actualfire = jobInfo.getFireTime();
StringBuffer whoAmI = new StringBuffer("AutoSubmitAssessmentsJob $");
whoAmI.append(" Job: ");
whoAmI.append(jobName);
whoAmI.append(" Trigger: ");
whoAmI.append(triggerName);
if (requestedFire != null) {
whoAmI.append(" Fire scheduled: ");
whoAmI.append(requestedFire.toString());
}
if (actualfire != null) {
whoAmI.append(" Fire actual: ");
whoAmI.append(actualfire.toString());
}
eventTrackingService.post(eventTrackingService.newEvent(SamigoConstants.EVENT_AUTO_SUBMIT_JOB, safeEventLength(whoAmI.toString()), true));
log.info("Start Job: {}", whoAmI);
GradingService gradingService = new GradingService();
int failures = gradingService.autoSubmitAssessments();
if (failures > 0)
{
samigoETSProvider.notifyAutoSubmitFailures(failures);
}
log.info("End Job: {} ({} failures)", whoAmI, failures);
logoutFromSakai();
}
@Transactional(readOnly = true)
@Secured("AFTER_ACL_COLLECTION_READ")
public SchedulerJob[] getActiveSchedulerJobs() {
List<SchedulerJob> activeJobs = new ArrayList<SchedulerJob>();
SchedulerJob[] schedulerJobs = getSchedulerJobs();
for (SchedulerJob job : schedulerJobs) {
boolean active = false;
Date now = new Date();
if (ScheduleConstants.ONCE_TYPE.equals(job.getTime().getType())) {
active = (job.getTime().getRunDate().compareTo(now) >= 0) || job.isRunning();
} else {
active = ((job.getTime().getStartActivationDate().compareTo(now) <= 0) &&
(job.getTime().getEndActivationDate().compareTo(now) >= 0)) || job.isRunning();
}
if (active) {
activeJobs.add(job);
Map<String, JobExecutionContext> runningJobs;
try {
runningJobs = QuartzUtil.getRunningJobs(scheduler);
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
JobExecutionContext executionContext = runningJobs.get(job.getPath());
if (executionContext != null) {
Date fireTime = executionContext.getFireTime();
job.setRunTime(Seconds.secondsBetween(new DateTime(fireTime), new DateTime()).getSeconds());
}
}
}
schedulerJobs = activeJobs.toArray(new SchedulerJob[activeJobs.size()]);
return schedulerJobs;
}
@Override
public void jobToBeExecuted(final JobExecutionContext context) {
final JobKey jobKey = context.getJobDetail().getKey();
log.trace("Job {} : {} jobToBeExecuted", jobKey.getName(), taskInfo.getConfiguration().getTaskLogName());
// get current trigger, which in this method SHOULD be job's trigger.
// Still, in some circumstances (that I cannot imagine right now, except to have concurrency bug)
// the NX Task's Trigger might be missing. Still, we don't want to throw in this listener
// as that would make whole Quartz instance inconsistent. Also, even if job removed (coz bug exists)
// we do want to "follow" it's lifecycle here.
final Trigger currentTrigger = getCurrentTrigger(context);
QuartzTaskFuture future = taskInfo.getTaskFuture();
if (future == null) {
log.trace("Job {} : {} has no future, creating it", jobKey.getName(),
taskInfo.getConfiguration().getTaskLogName());
future = new QuartzTaskFuture(scheduler,
jobKey,
taskInfo.getConfiguration().getTaskLogName(),
context.getFireTime(),
scheduler.triggerConverter().convert(context.getTrigger()),
null
);
// set the future on taskinfo
taskInfo.setNexusTaskState(
RUNNING,
new QuartzTaskState(
configurationOf(context.getJobDetail()),
scheduler.triggerConverter().convert(currentTrigger),
currentTrigger.getNextFireTime()
),
future
);
}
context.put(QuartzTaskFuture.FUTURE_KEY, future);
context.put(QuartzTaskInfo.TASK_INFO_KEY, taskInfo);
eventManager.post(new TaskEventStarted(taskInfo));
}
Date getContextFireTime(JobExecutionContext context) {
return context.getFireTime();
}
@Override
Date getContextFireTime(JobExecutionContext context) {
return context.getFireTime();
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext jobExecutionContext)
{
Date fired = jobExecutionContext.getFireTime();
eventManager.createTriggerEvent (TriggerEvent.TRIGGER_EVENT_TYPE.FIRED, jobExecutionContext.getJobDetail().getKey(), trigger.getKey(), fired, "Trigger fired", getServerId());
}
@Override
public void triggerFired(Trigger trigger, JobExecutionContext jobExecutionContext)
{
Date fired = jobExecutionContext.getFireTime();
eventManager.createTriggerEvent (TriggerEvent.TRIGGER_EVENT_TYPE.FIRED, jobExecutionContext.getJobDetail().getKey(), trigger.getKey(), fired, "Trigger fired", getServerId());
}