Java Code Examples for org.quartz.JobKey#jobKey()
The following examples show how to use
org.quartz.JobKey#jobKey() .
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: QuartzManage.java From DimpleBlog with Apache License 2.0 | 6 votes |
/** * 立即执行job */ public void runAJobNow(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 CustomException("定时任务执行失败"); } }
Example 2
Source File: MachineCenterImpl.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public boolean deployServerCollection(long hostId, String ip) { Assert.hasText(ip); Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put(ConstUtils.HOST_KEY, ip); JobKey jobKey = JobKey.jobKey(ConstUtils.SERVER_JOB_NAME, ConstUtils.SERVER_JOB_GROUP); TriggerKey triggerKey = TriggerKey.triggerKey(ip, ConstUtils.SERVER_TRIGGER_GROUP + ip); boolean result = schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getFiveMinuteCronByHostId(hostId), false); return result; }
Example 3
Source File: JobExecuteService.java From spring-boot-starter-micro-job with Apache License 2.0 | 5 votes |
/** * 使用指定的分组删除任务 * * @param triggerKey 任务key */ public void removeJob(String triggerKey, String groupName) { try { JobKey jobKey = JobKey.jobKey(triggerKey, groupName); scheduler.deleteJob(jobKey); } catch (Exception e) { logger.error("删除任务:{},遇到异常信息如下.", triggerKey); e.printStackTrace(); } }
Example 4
Source File: JobExecuteService.java From spring-boot-starter-micro-job with Apache License 2.0 | 5 votes |
/** * 使用指定分组暂停任务 * * @param triggerKey 任务key * @param groupName 任务分组 */ public void pauseJob(String triggerKey, String groupName) { try { JobKey jobKey = JobKey.jobKey(triggerKey, groupName); scheduler.pauseJob(jobKey); } catch (Exception e) { logger.error("暂停任务:{},遇到异常信息如下.", triggerKey); e.printStackTrace(); } }
Example 5
Source File: TransientProducerRepositoryTest.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
@Test public void assertPutMoreJobWithChangedCron() throws JobExecutionException { String jobName2 = "other_test_job"; transientProducerRepository.put(jobKey, jobName); transientProducerRepository.put(jobKey, jobName2); JobKey newJobKey = JobKey.jobKey("0/15 * * * * ?"); transientProducerRepository.put(newJobKey, jobName); assertThat(transientProducerRepository.get(jobKey).get(0), is(jobName2)); assertThat(transientProducerRepository.get(newJobKey).get(0), is(jobName)); transientProducerRepository.remove(jobName); transientProducerRepository.remove(jobName2); }
Example 6
Source File: TransientProducerRepositoryTest.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
@Test public void assertPutJobWithChangedCron() throws JobExecutionException { transientProducerRepository.put(jobKey, jobName); JobKey newJobKey = JobKey.jobKey("0/15 * * * * ?"); transientProducerRepository.put(newJobKey, jobName); assertTrue(transientProducerRepository.get(jobKey).isEmpty()); assertThat(transientProducerRepository.get(newJobKey).get(0), is(jobName)); transientProducerRepository.remove(jobName); }
Example 7
Source File: RedisCenterImpl.java From cachecloud with Apache License 2.0 | 5 votes |
@Override public boolean deployRedisCollection(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_JOB_NAME, ConstUtils.REDIS_JOB_GROUP); TriggerKey triggerKey = TriggerKey .triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_TRIGGER_GROUP + appId); return schedulerCenter .deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getMinuteCronByAppId(appId), false); }
Example 8
Source File: QssService.java From seed with Apache License 2.0 | 5 votes |
/** * 立即执行一个QuartzJob(只会运行一次) * ---------------------------------------------------------------------------- * Quartz是通过临时生成一个Trigger(Trigger的key是随机生成的)的方式实现的 * 该临时Trigger将在本次任务运行完成之后自动删除 * ---------------------------------------------------------------------------- */ void triggerJob(long taskId) { Optional<ScheduleTask> taskOptional = scheduleTaskRepository.findById(taskId); if(!taskOptional.isPresent()){ throw new RuntimeException("不存在的任务:taskId=[" + taskId + "]"); } ScheduleTask task = taskOptional.get(); JobKey jobKey = JobKey.jobKey(task.getJobname()); try{ scheduler.triggerJob(jobKey); }catch(SchedulerException e){ throw new SeedException(CodeEnum.SYSTEM_ERROR.getCode(), "立即执行QuartzJob失败:jobname=["+task.getJobname()+"]", e); } }
Example 9
Source File: QuartzManage.java From yshopmall with Apache License 2.0 | 5 votes |
/** * 暂停一个job * @param quartzJob / */ public void pauseJob(QuartzJob quartzJob){ try { JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); scheduler.pauseJob(jobKey); } catch (Exception e){ log.error("定时任务暂停失败", e); throw new BadRequestException("定时任务暂停失败"); } }
Example 10
Source File: SchedulerHelper.java From iaf with Apache License 2.0 | 5 votes |
public boolean contains(String name, String group) throws SchedulerException { JobKey key = null; if(StringUtils.isEmpty(group)) key = JobKey.jobKey(name, DEFAULT_GROUP); else key = JobKey.jobKey(name, group); return scheduler.checkExists(key); }
Example 11
Source File: QuartzManage.java From DimpleBlog with Apache License 2.0 | 5 votes |
/** * 删除一个job */ public void deleteJob(QuartzJob quartzJob) { try { JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId()); scheduler.pauseJob(jobKey); scheduler.deleteJob(jobKey); } catch (Exception e) { log.error("删除定时任务失败", e); throw new CustomException("删除定时任务失败"); } }
Example 12
Source File: ScheduleUtils.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 4 votes |
/** * 获取jobKey */ public static JobKey getJobKey(Long jobId) { return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId); }
Example 13
Source File: ScheduleJobService.java From springboot-quartz with MIT License | 4 votes |
public void resumeJob(ScheduleJob scheduleJob) throws SchedulerException{ checkNotNull(scheduleJob); JobKey jobKey = JobKey.jobKey(scheduleJob.getJobName(), scheduleJob.getJobGroup()); scheduler.resumeJob(jobKey); }
Example 14
Source File: SnifferJobManager.java From logsniffer with GNU Lesser General Public License v3.0 | 4 votes |
protected static JobKey getJobKey(final long snifferId, final long logSourceId) { return JobKey.jobKey(snifferId + ":" + logSourceId, "SNIFFER:" + snifferId); }
Example 15
Source File: ScheduleJobService.java From springboot-quartz with MIT License | 4 votes |
public void runJobOnce(ScheduleJob scheduleJob) throws SchedulerException{ checkNotNull(scheduleJob); JobKey jobKey = JobKey.jobKey(scheduleJob.getJobName(), scheduleJob.getJobGroup()); scheduler.triggerJob(jobKey); }
Example 16
Source File: ScheduleUtils.java From ruoyiplus with MIT License | 4 votes |
/** * 获取jobKey */ public static JobKey getJobKey(Long jobId) { return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId); }
Example 17
Source File: ScheduleUtils.java From RuoYi-Vue with MIT License | 4 votes |
/** * 构建任务键对象 */ public static JobKey getJobKey(Long jobId, String jobGroup) { return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); }
Example 18
Source File: SmartQuartzUtil.java From smart-admin with MIT License | 4 votes |
/** * 获取jobKey */ public static JobKey getJobKey(Long taskId) { return JobKey.jobKey(QuartzConst.JOB_KEY_PREFIX + taskId); }
Example 19
Source File: JobTrigger.java From spring-cloud-shop with MIT License | 3 votes |
/** * 恢复任务 * * @param scheduler scheduler * @param jobName jobName * @param jobGroup jobGroup */ public static void resumeJob(Scheduler scheduler, String jobName, String jobGroup) throws SchedulerException { log.info("恢复定时任务 jobName = {}, jobGroup = {}", jobName, jobGroup); JobKey jobKey = JobKey.jobKey(jobName, jobGroup); scheduler.resumeJob(jobKey); }
Example 20
Source File: JobTrigger.java From spring-cloud-shop with MIT License | 2 votes |
/** * 获取jobKey * * @param jobName the job name * @param jobGroup the job group * @return the job key */ private static JobKey getJobKey(String jobName, String jobGroup) { return JobKey.jobKey(jobName, jobGroup); }