use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class TriggerController method resumeTrigger.
@RequestMapping(value = "/resume/{appId}/{type}/{host}/{port}")
public void resumeTrigger(@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.resumeTrigger(triggerKey);
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
}
logger.info("trigger with name: {}, group: {} is resumed", port, host);
}
use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class TriggerController method pauseTrigger.
@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);
}
use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class ScheduleTriggerServiceImpl method refreshTrigger.
/**
* 定时刷新扫描配置表
*/
@Scheduled(fixedRate = 1000 * 30)
@Override
public void refreshTrigger() {
try {
List<ScheduleTrigger> jobList = scheduleTriggerMapper.selectAll();
if (null != jobList && jobList.size() > 0) {
for (ScheduleTrigger scheduleJob : jobList) {
String status = scheduleJob.getStatus();
TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 说明本条任务还没有添加到quartz中
if (null == trigger) {
if (STATUS.equals(status)) {
continue;
}
JobDetail jobDetail = null;
try {
// 创建JobDetail(数据库中job_name存的任务全路径,这里就可以动态的把任务注入到JobDetail中)
jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(scheduleJob.getJobName())).withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).build();
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCron());
trigger = TriggerBuilder.newTrigger().withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(jobDetail, trigger);
} catch (ClassNotFoundException e) {
}
} else {
// 如果是禁用,从quartz中删除这条任务
if (STATUS.equals(status)) {
JobKey jobKey = JobKey.jobKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
scheduler.deleteJob(jobKey);
continue;
}
String searchCron = scheduleJob.getCron();
String currentCron = trigger.getCronExpression();
if (!searchCron.equals(currentCron)) {
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(searchCron);
// 按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
// 按新的trigger重新设置job执行
scheduler.rescheduleJob(triggerKey, trigger);
}
}
}
}
} catch (Exception e) {
logger.error("定时任务每日刷新触发器任务异常,在ScheduleTriggerService的方法refreshTrigger中,异常信息:", e);
}
}
use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class MachineCenterImpl method unDeployMachineMonitor.
@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);
}
use of org.quartz.TriggerKey in project new-cloud by xie-summer.
the class MachineCenterImpl method deployServerCollection.
@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;
}
Aggregations