Java Code Examples for org.quartz.Scheduler#getTrigger()

The following examples show how to use org.quartz.Scheduler#getTrigger() . 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: ScheduleUtils.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 获取表达式触发器
 */
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId)
{
    try
    {
    	System.out.println(">>>>>>>>scheduler:"+scheduler.getSchedulerName());
    	System.out.println(">>>>>>>>jobId:"+jobId);
    	System.out.println(">>>>>>>>getName:"+getTriggerKey(jobId).getName());
        return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
    }
    catch (SchedulerException e)
    {
        log.error("getCronTrigger 异常:", e);
    }
    return null;
}
 
Example 2
Source File: ScheduleUtils.java    From ruoyiplus with MIT License 5 votes vote down vote up
/**
 * 获取表达式触发器
 */
public static CronTrigger getCronTrigger(Scheduler scheduler, Long jobId)
{
    try
    {
        return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
    }
    catch (SchedulerException e)
    {
        log.error("getCronTrigger 异常:", e);
    }
    return null;
}
 
Example 3
Source File: JobTrigger.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
/**
 * 更新定时任务
 *
 * @param scheduler      the scheduler
 * @param jobName        the job name
 * @param jobGroup       the job group
 * @param cronExpression the cron expression
 * @param param          the param
 */
private static void updateJob(Scheduler scheduler, String jobName, String jobGroup, String cronExpression, Object param) throws SchedulerException {

    // 同步或异步
    Class<? extends Job> jobClass = JobQuartzJobBean.class;
    JobDetail jobDetail = scheduler.getJobDetail(getJobKey(jobName, jobGroup));

    jobDetail = jobDetail.getJobBuilder().ofType(jobClass).build();

    // 更新参数 实际测试中发现无法更新
    JobDataMap jobDataMap = jobDetail.getJobDataMap();
    jobDataMap.put("JobAdapter", param);
    jobDetail.getJobBuilder().usingJobData(jobDataMap);

    TriggerKey triggerKey = getTriggerKey(jobName, jobGroup);

    // 表达式调度构建器
    CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);

    CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);

    // 按新的cronExpression表达式重新构建trigger
    trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
    Trigger.TriggerState triggerState = scheduler.getTriggerState(trigger.getKey());
    // 忽略状态为PAUSED的任务,解决集群环境中在其他机器设置定时任务为PAUSED状态后,集群环境启动另一台主机时定时任务全被唤醒的bug
    if (!JobEnums.PAUSE.name().equalsIgnoreCase(triggerState.name())) {
        // 按新的trigger重新设置job执行
        scheduler.rescheduleJob(triggerKey, trigger);
    }
}
 
Example 4
Source File: QuartzManager.java    From quartz-web with Apache License 2.0 5 votes vote down vote up
public Trigger getTrigger(String schedulerName,String triggerName,String triggerGroup) throws SchedulerException {
    Assert.notEmpty(triggerName, "triggerName can not be empty");
    Assert.notEmpty(triggerGroup, "triggerGroup can not be empty");
    Scheduler scheduler = this.getAssertScheduler(schedulerName);
    TriggerKey triggerKey = QuartzUtils.getTriggerKey(triggerName, triggerGroup);
    Trigger trigger = scheduler.getTrigger(triggerKey);
    return trigger;
}
 
Example 5
Source File: ScheduleJobService.java    From frameworkAggregate with Apache License 2.0 5 votes vote down vote up
/**
 * 更新job时间表达式
 * 
 * @param scheduleJob
 * @throws SchedulerException
 */
public void updateJobCron(ScheduleJob scheduleJob) throws SchedulerException {
	Scheduler scheduler = schedulerFactoryBean.getScheduler();
	TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
	CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
	CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());
	trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
	scheduler.rescheduleJob(triggerKey, trigger);
}
 
Example 6
Source File: SchedulerServiceSupplier.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Gets the job schedulation definition.
 * 
 * @param triggerName the trigger name
 * @param triggerGroup the trigger group
 * 
 * @return the job schedulation definition
 */
public   String getJobSchedulationDefinition(String triggerName, String triggerGroup) {
	String schedDef = "";
	try {
		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
		if (triggerName == null || triggerName.trim().equals("")) {
			SpagoBITracer.critical(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), 
							   	   "getJobSchedulationDefinition", "Missing trigger name request parameter!");
			throw new Exception("Missing trigger name request parameter!");
		}
		if (triggerGroup == null || triggerGroup.trim().equals("")) {
			SpagoBITracer.major(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), 
								"getJobSchedulationDefinition", "Missing trigger group name! Using default group...");
			triggerGroup = Scheduler.DEFAULT_GROUP;
		}
		Trigger trigger = (Trigger) scheduler.getTrigger(triggerName, triggerGroup);
		if (trigger == null) {
			SpagoBITracer.critical(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), 
								   "getJobSchedulationDefinition", 
								   "Trigger with name '" + triggerName + "' not found in group '" + triggerGroup + "'!");
			throw new Exception("Trigger with name '" + triggerName + "' not found in group '" + triggerGroup + "'!");
		}
		schedDef = serializeTrigger(trigger);
	} catch (Exception e) {
		SpagoBITracer.critical(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), 
	   			   			   "getJobSchedulationDefinition", "Error while recovering schedule definition");
	}
	return schedDef;
}
 
Example 7
Source File: QuartzUtil.java    From fixflow with Apache License 2.0 5 votes vote down vote up
/**
 * 根据定时任务和触发器名称得到触发器
 * @param scheduler 定时任务
 * @param triggerKey 触发器名称
 * @return
 */
public static Trigger getTrigger(Scheduler scheduler, String triggerKey) {
	Trigger trigger = null;
	try {
		trigger = scheduler.getTrigger(new TriggerKey(triggerKey));
	} catch (SchedulerException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return trigger;
}
 
Example 8
Source File: JobTrigger.java    From spring-cloud-shop with MIT License 2 votes vote down vote up
/**
 * 获取表达式触发器
 *
 * @param scheduler 调度器
 * @param jobName   job名称
 * @param jobGroup  job组
 */
public static CronTrigger getCronTrigger(Scheduler scheduler, String jobName, String jobGroup) throws SchedulerException {
    log.info("执行的定时任务 JobName = {}, JobGroup = {}", jobName, jobGroup);
    return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobName, jobGroup));
}