Java Code Examples for org.quartz.TriggerKey#triggerKey()

The following examples show how to use org.quartz.TriggerKey#triggerKey() . 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: TriggerController.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/pause/{appId}/{type}/{host}/{port}")
public void pauseTrigger(@PathVariable long appId, @PathVariable int type, @PathVariable String host, @PathVariable int port) {
    Assert.isTrue(appId > 0);
    Assert.isTrue(type > 0);
    Assert.hasText(host);
    Assert.isTrue(port > 0);

    String triggerName = ObjectConvert.linkIpAndPort(host, port);
    String triggerGroup = "";
    if (type == ConstUtils.CACHE_TYPE_REDIS_CLUSTER) {
        triggerGroup = ConstUtils.REDIS_TRIGGER_GROUP + appId;
    }

    TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroup);
    try {
        scheduler.pauseTrigger(triggerKey);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
    }
    logger.info("trigger with name: {}, group: {} is paused", port, host);
}
 
Example 2
Source File: QuartzManage.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 立即执行job
 * @param quartzJob /
 */
public void runJobNow(QuartzJob quartzJob){
    try {
        TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
        CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
        // 如果不存在则创建一个定时任务
        if(trigger == null) {
            addJob(quartzJob);
        }
        JobDataMap dataMap = new JobDataMap();
        dataMap.put(QuartzJob.JOB_KEY, quartzJob);
        JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
        scheduler.triggerJob(jobKey,dataMap);
    } catch (Exception e){
        log.error("定时任务执行失败", e);
        throw new BadRequestException("定时任务执行失败");
    }
}
 
Example 3
Source File: SchedulerCenterTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
    public void testSchedule() {
        TriggerKey key = TriggerKey.triggerKey("appInfoAlertTrigger", "appAlert");
        Trigger trigger = schedulerCenter.getTrigger(key);
        if(trigger != null){
            boolean isSchedule = schedulerCenter.unscheduleJob(key);
            logger.warn("isSchedule={}",isSchedule);
        }
//        try {
//            TimeUnit.SECONDS.sleep(5);
//        } catch (InterruptedException e) {
//            logger.error("{}", e);
//        }
    }
 
Example 4
Source File: RedisCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public boolean deployRedisSlowLogCollection(long appId, String host, int port) {
    Assert.isTrue(appId > 0);
    Assert.hasText(host);
    Assert.isTrue(port > 0);
    Map<String, Object> dataMap = new HashMap<String, Object>();
    dataMap.put(ConstUtils.HOST_KEY, host);
    dataMap.put(ConstUtils.PORT_KEY, port);
    dataMap.put(ConstUtils.APP_KEY, appId);
    JobKey jobKey = JobKey.jobKey(ConstUtils.REDIS_SLOWLOG_JOB_NAME, ConstUtils.REDIS_SLOWLOG_JOB_GROUP);
    TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_SLOWLOG_TRIGGER_GROUP + appId);
    boolean result = schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getRedisSlowLogCron(appId), false);
    return result;
}
 
Example 5
Source File: SchedulerHelper.java    From iaf with Apache License 2.0 5 votes vote down vote up
public Trigger getTrigger(String name, String group) throws SchedulerException {
	TriggerKey key = null;
	if(StringUtils.isEmpty(group))
		key = TriggerKey.triggerKey(name, DEFAULT_GROUP);
	else
		key = TriggerKey.triggerKey(name, group);

	return scheduler.getTrigger(key);
}
 
Example 6
Source File: QuartzManager.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
/**
 * remove
 *
 * @param jobName remove job
 * @param jobGroupName job group name
 * @param triggerName trigger name
 * @param triggerGroupName trigger group name
 */
public RetCode removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName) throws SchedulerException {
    TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);

    scheduler.pauseTrigger(triggerKey);
    scheduler.unscheduleJob(triggerKey);
    if (scheduler.deleteJob(JobKey.jobKey(jobName, jobGroupName))) {
        return ConstantsHelper.SUCCESS;
    }
    return ConstantsHelper.FAIL;
}
 
Example 7
Source File: TimerSchedulerService.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
/**
 * remove
 *
 * @param jobName remove job
 * @param jobGroupName job group name
 * @param triggerName trigger name
 * @param triggerGroupName trigger group name
 */
public RetCode removeJob(String jobName, String jobGroupName, String triggerName, String triggerGroupName) throws BrokerException {
    try {
        TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);
        scheduler.pauseTrigger(triggerKey);
        scheduler.unscheduleJob(triggerKey);
        if (scheduler.deleteJob(JobKey.jobKey(jobName, jobGroupName))) {
            return ConstantsHelper.SUCCESS;
        }
        return ConstantsHelper.FAIL;
    } catch (Exception e) {
        throw new BrokerException(e.getMessage());
    }
}
 
Example 8
Source File: ScheduleJobService.java    From springboot-quartz with MIT License 5 votes vote down vote up
private void updateJobCronExpression(ScheduleJob scheduleJob) throws SchedulerException{  
checkNotNull(scheduleJob);
Preconditions.checkNotNull(StringUtils.isEmpty(scheduleJob.getCronExpression()), "CronExpression is null");

      TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());  
      CronTrigger cronTrigger = (CronTrigger)scheduler.getTrigger(triggerKey);  
      CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression());  
      cronTrigger = cronTrigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();  
      scheduler.rescheduleJob(triggerKey, cronTrigger);  
  }
 
Example 9
Source File: XxlJobDynamicScheduler.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
/**
 * pause
 *
 * @param jobName
 * @param jobGroup
 * @return
 * @throws SchedulerException
 */
public static boolean pauseJob(String jobName, String jobGroup) throws SchedulerException {
	// TriggerKey : name + group
	TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
    
    boolean result = false;
    if (checkExists(jobName, jobGroup)) {
        scheduler.pauseTrigger(triggerKey);
        result = true;
        logger.info(">>>>>>>>>>> pauseJob success, triggerKey:{}", triggerKey);
    } else {
    	logger.info(">>>>>>>>>>> pauseJob fail, triggerKey:{}", triggerKey);
    }
    return result;
}
 
Example 10
Source File: TaskInnerServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 停止任务
 *
 * @param taskDto
 * @return
 */
public int stopTask(@RequestBody TaskDto taskDto) {

    try {
        String jobName = prefixJobName + taskDto.getTaskId();

        String triggerName = prefixJobName + taskDto.getTaskId();

        TriggerKey triggerKey = TriggerKey.triggerKey(jobName, TaskSystemJob.JOB_GROUP_NAME);
        // 停止触发器
        scheduler.pauseTrigger(triggerKey);
        // 移除触发器
        scheduler.unscheduleJob(triggerKey);

        JobKey jobKey = new JobKey(jobName, TaskSystemJob.JOB_GROUP_NAME);
        // 删除任务
        scheduler.deleteJob(jobKey);

        Map paramIn = new HashMap();
        paramIn.put("taskId", taskDto.getTaskId());
        paramIn.put("state", "001");
        paramIn.put("statusCd", "0");
        taskServiceDaoImpl.updateTaskInfoInstance(paramIn);

    } catch (Exception e) {
        logger.error("启动侦听失败", e);
        return 0;
    }
    return 1;
}
 
Example 11
Source File: XxlJobDynamicScheduler.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
/**
    * addJob
    *
    * @param jobName
    * @param jobGroup
    * @param cronExpression
    * @return
    * @throws SchedulerException
    */
public static boolean addJob(String jobName, String jobGroup, String cronExpression) throws SchedulerException {
   	// TriggerKey : name + group
       TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
       JobKey jobKey = new JobKey(jobName, jobGroup);
       
       // TriggerKey valid if_exists
       if (checkExists(jobName, jobGroup)) {
           logger.info(">>>>>>>>> addJob fail, job already exist, jobGroup:{}, jobName:{}", jobGroup, jobName);
           return false;
       }
       
       // CronTrigger : TriggerKey + cronExpression	// withMisfireHandlingInstructionDoNothing 忽略掉调度终止过程中忽略的调度
       CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression).withMisfireHandlingInstructionDoNothing();
       CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build();

       // JobDetail : jobClass
	Class<? extends Job> jobClass_ = RemoteHttpJobBean.class;   // Class.forName(jobInfo.getJobClass());
       
	JobDetail jobDetail = JobBuilder.newJob(jobClass_).withIdentity(jobKey).build();
       /*if (jobInfo.getJobData()!=null) {
       	JobDataMap jobDataMap = jobDetail.getJobDataMap();
       	jobDataMap.putAll(JacksonUtil.readValue(jobInfo.getJobData(), Map.class));	
       	// JobExecutionContext context.getMergedJobDataMap().get("mailGuid");
	}*/
       
       // schedule : jobDetail + cronTrigger
       Date date = scheduler.scheduleJob(jobDetail, cronTrigger);

       logger.info(">>>>>>>>>>> addJob success, jobDetail:{}, cronTrigger:{}, date:{}", jobDetail, cronTrigger, date);
       return true;
   }
 
Example 12
Source File: SystemJobHelper.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a system job asynchronously.
 *
 * @param jobName the system job name (case-sensitive)
 * @param parameters the list of parameters
 *
 * @throws org.quartz.SchedulerException if fails to schedule the system job
 */
public void runSystemJob(String jobName, List<Parameter> parameters) throws SchedulerException
{
    // Validate the system job name.
    AbstractSystemJob systemJob;
    try
    {
        systemJob = (AbstractSystemJob) applicationContext.getBean(jobName);
    }
    catch (Exception e)
    {
        throw new ObjectNotFoundException(String.format("System job with name \"%s\" doesn't exist.", jobName), e);
    }

    // Validate parameters per relative system job.
    systemJob.validateParameters(parameters);

    // Prepare a trigger to run the system job only once.
    TriggerKey triggerKey = TriggerKey.triggerKey(jobName + AbstractSystemJob.RUN_ONCE_TRIGGER_SUFFIX);
    Trigger trigger = newTrigger().withIdentity(triggerKey).forJob(jobName).usingJobData(systemJob.getJobDataMap(parameters)).startNow().build();

    LOGGER.debug(String.format("schedule job with trigger: calendarName: %s, description: %s, endTime: %s, finalFireTime: %s, jobKey: %s, key: %s, " +
        "misfireInstruction: %s, nextFireTime: %s, previousFireTime: %s, priority: %s, startTime: %s", trigger.getCalendarName(), trigger.getDescription(),
        trigger.getEndTime(), trigger.getFinalFireTime(), trigger.getJobKey(), trigger.getKey(), trigger.getMisfireInstruction(), trigger.getNextFireTime(),
        trigger.getPreviousFireTime(), trigger.getPriority(), trigger.getStartTime()));

    // Schedule the system job.
    schedulerFactory.getScheduler().scheduleJob(trigger);
}
 
Example 13
Source File: MachineCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public boolean unDeployMachineMonitor(long hostId, String ip) {
    Assert.isTrue(hostId > 0);
    Assert.hasText(ip);
    TriggerKey monitorTriggerKey = TriggerKey.triggerKey(ip, ConstUtils.MACHINE_MONITOR_TRIGGER_GROUP + hostId);
    Trigger trigger = schedulerCenter.getTrigger(monitorTriggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(monitorTriggerKey);
}
 
Example 14
Source File: RedisCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Override
public boolean unDeployRedisCollection(long appId, String host, int port) {
    Assert.isTrue(appId > 0);
    Assert.hasText(host);
    Assert.isTrue(port > 0);
    TriggerKey triggerKey = TriggerKey
            .triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_TRIGGER_GROUP + appId);
    Trigger trigger = schedulerCenter.getTrigger(triggerKey);
    if (trigger == null) {
        return true;
    }
    return schedulerCenter.unscheduleJob(triggerKey);
}
 
Example 15
Source File: SchedulerHelper.java    From iaf with Apache License 2.0 5 votes vote down vote up
public void deleteTrigger(String name, String group) throws SchedulerException {
	TriggerKey key = null;
	if(StringUtils.isEmpty(group))
		key = TriggerKey.triggerKey(name, DEFAULT_GROUP);
	else
		key = TriggerKey.triggerKey(name, group);

	getScheduler().unscheduleJob(key);
}
 
Example 16
Source File: ScheduleUtils.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 构建任务触发对象
 */
public static TriggerKey getTriggerKey(Long jobId, String jobGroup)
{
    return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
}
 
Example 17
Source File: SnifferJobManager.java    From logsniffer with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected TriggerKey getKey(final Sniffer sniffer, final long logSourceId) {
	return TriggerKey.triggerKey(sniffer.getId() + ":" + logSourceId, "SNIFFER:" + sniffer.getId());
}
 
Example 18
Source File: CollectServiceImpl.java    From zkdoctor with Apache License 2.0 4 votes vote down vote up
@Override
public boolean unDeployZKCollection(int clusterId) {
    TriggerKey triggerKey = TriggerKey.triggerKey(SchedulerConstant.ZK_COLLECT_TRIGGER_NAME,
            SchedulerConstant.ZK_COLLECT_TRIGGER_GROUP + clusterId);
    return schedulerService.unscheduleJob(triggerKey);
}
 
Example 19
Source File: ScheduleTaskService.java    From RCT with Apache License 2.0 4 votes vote down vote up
public String getJobStatus(String triggerName) throws SchedulerException {
	TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, "Group");
	TriggerState status = getScheduler().getTriggerState(triggerKey);
	return status.toString();

}
 
Example 20
Source File: ClusterInfoServiceImpl.java    From EserKnife with Apache License 2.0 4 votes vote down vote up
private boolean removeClusterCollection(String clusterName) {
	TriggerKey triggerKey = TriggerKey.triggerKey(clusterName+"Trigger", clusterName);
	return schedulerCenter.unscheduleJob(triggerKey);
}