Search in sources :

Example 61 with TriggerKey

use of org.quartz.TriggerKey in project new-cloud by xie-summer.

the class MachineCenterImpl method deployMachineMonitor.

/**
 * 为监控每台机器的状态部署trigger
 *
 * @param hostId 机器id
 * @param ip     ip
 * @return 是否部署成功
 */
@Override
public boolean deployMachineMonitor(final long hostId, final String ip) {
    Assert.isTrue(hostId > 0);
    Assert.hasText(ip);
    Map<String, Object> dataMap = new HashMap<String, Object>();
    dataMap.put(ConstUtils.HOST_KEY, ip);
    dataMap.put(ConstUtils.HOST_ID_KEY, hostId);
    JobKey jobKey = JobKey.jobKey(ConstUtils.MACHINE_MONITOR_JOB_NAME, ConstUtils.MACHINE_MONITOR_JOB_GROUP);
    TriggerKey triggerKey = TriggerKey.triggerKey(ip, ConstUtils.MACHINE_MONITOR_TRIGGER_GROUP + hostId);
    boolean result = schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getHourCronByHostId(hostId), false);
    return result;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) HashMap(java.util.HashMap)

Example 62 with TriggerKey

use of org.quartz.TriggerKey in project new-cloud by xie-summer.

the class RedisCenterImpl method deployRedisSlowLogCollection.

@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;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey)

Example 63 with TriggerKey

use of org.quartz.TriggerKey in project new-cloud by xie-summer.

the class RedisCenterImpl method unDeployRedisCollection.

@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);
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger)

Example 64 with TriggerKey

use of org.quartz.TriggerKey in project new-cloud by xie-summer.

the class SchedulerCenterTest method testSchedule.

@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);
// }
}
Also used : TriggerKey(org.quartz.TriggerKey) Trigger(org.quartz.Trigger) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 65 with TriggerKey

use of org.quartz.TriggerKey in project openolat by klemens.

the class ViteroModule method initCronJob.

private void initCronJob() {
    try {
        TriggerKey triggerKey = new TriggerKey("Vitero_Cleaner_Cron_Trigger", Scheduler.DEFAULT_GROUP);
        if (scheduler.getTrigger(triggerKey) == null) {
            // Create job with cron trigger configuration
            JobDetail jobDetail = newJob(ViteroZombieSlayerJob.class).withIdentity("Vitero_Cleaner_Cron_Job", Scheduler.DEFAULT_GROUP).build();
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.SECOND, 30);
            Trigger trigger = newTrigger().withIdentity("Vitero_Cleaner_Cron_Trigger").withSchedule(cronSchedule(cronExpression)).startAt(cal.getTime()).build();
            scheduler.scheduleJob(jobDetail, trigger);
        }
    } catch (Exception e) {
        log.error("Cannot start the Quartz Job which clean the Vitero rooms", e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) Calendar(java.util.Calendar)

Aggregations

TriggerKey (org.quartz.TriggerKey)112 Trigger (org.quartz.Trigger)49 JobKey (org.quartz.JobKey)30 SchedulerException (org.quartz.SchedulerException)30 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Test (org.junit.Test)18 Scheduler (org.quartz.Scheduler)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4