Java Code Examples for org.quartz.JobExecutionContext#getFireTime()

The following examples show how to use org.quartz.JobExecutionContext#getFireTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobExecutionContextSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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);
    }
}
 
Example 2
Source File: JobExecutionContextSupport.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * @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);
	}
}
 
Example 3
Source File: JobExecution.java    From quartz-glass with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example 4
Source File: JobBean.java    From SpringBoot2.0 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: ScheduleLogRequest.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
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;
	}
}
 
Example 6
Source File: AutoSubmitAssessmentsJob.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: AutoSubmitAssessmentsJob.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: DefaultSchedulerService.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: QuartzTaskJobListener.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@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));
}
 
Example 10
Source File: QuartzAdapter.java    From javamelody with Apache License 2.0 4 votes vote down vote up
Date getContextFireTime(JobExecutionContext context) {
	return context.getFireTime();
}
 
Example 11
Source File: Quartz2Adapter.java    From javamelody with Apache License 2.0 4 votes vote down vote up
@Override
Date getContextFireTime(JobExecutionContext context) {
	return context.getFireTime();
}
 
Example 12
Source File: GlobalTriggerListener.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@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());
}
 
Example 13
Source File: GlobalTriggerListener.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@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());
}