Search in sources :

Example 46 with CronTrigger

use of org.quartz.CronTrigger in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobOrdersTriggersAccordingNextFireTimeAndPriority.

@Test
void quartzJobOrdersTriggersAccordingNextFireTimeAndPriority() throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").build();
    mockJobs(job);
    Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
    CronTrigger triggerOne = TriggerBuilder.newTrigger().withIdentity("one", "samples").withPriority(3).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).build();
    ((OperableTrigger) triggerOne).setNextFireTime(nextFireTime);
    CronTrigger triggerTwo = TriggerBuilder.newTrigger().withIdentity("two", "samples").withPriority(7).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).build();
    ((OperableTrigger) triggerTwo).setNextFireTime(nextFireTime);
    mockTriggers(triggerOne, triggerTwo);
    given(this.scheduler.getTriggersOfJob(JobKey.jobKey("hello", "samples"))).willAnswer((invocation) -> Arrays.asList(triggerOne, triggerTwo));
    QuartzJobDetails jobDetails = this.endpoint.quartzJob("samples", "hello");
    assertThat(jobDetails.getTriggers()).hasSize(2);
    assertThat(jobDetails.getTriggers().get(0)).containsEntry("name", "two");
    assertThat(jobDetails.getTriggers().get(1)).containsEntry("name", "one");
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with CronTrigger

use of org.quartz.CronTrigger in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzTriggerWithDataMap.

@Test
void quartzTriggerWithDataMap() throws SchedulerException {
    CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("3am-every-day", "samples").withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).usingJobData("user", "user").usingJobData("password", "secret").usingJobData("url", "https://user:secret@example.com").build();
    mockTriggers(trigger);
    given(this.scheduler.getTriggerState(TriggerKey.triggerKey("3am-every-day", "samples"))).willReturn(TriggerState.NORMAL);
    Map<String, Object> triggerDetails = this.endpoint.quartzTrigger("samples", "3am-every-day");
    assertThat(triggerDetails).extractingByKey("data", nestedMap()).containsOnly(entry("user", "user"), entry("password", "******"), entry("url", "https://user:******@example.com"));
}
Also used : CronTrigger(org.quartz.CronTrigger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with CronTrigger

use of org.quartz.CronTrigger in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzTriggerGroupSummaryWithCronTrigger.

@Test
void quartzTriggerGroupSummaryWithCronTrigger() throws SchedulerException {
    CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("3am-every-day", "samples").withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).build();
    mockTriggers(cronTrigger);
    QuartzTriggerGroupSummary summary = this.endpoint.quartzTriggerGroupSummary("samples");
    assertThat(summary.getGroup()).isEqualTo("samples");
    assertThat(summary.isPaused()).isFalse();
    assertThat(summary.getTriggers().getCron()).containsOnlyKeys("3am-every-day");
    assertThat(summary.getTriggers().getSimple()).isEmpty();
    assertThat(summary.getTriggers().getDailyTimeInterval()).isEmpty();
    assertThat(summary.getTriggers().getCalendarInterval()).isEmpty();
    assertThat(summary.getTriggers().getCustom()).isEmpty();
}
Also used : CronTrigger(org.quartz.CronTrigger) QuartzTriggerGroupSummary(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzTriggerGroupSummary) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with CronTrigger

use of org.quartz.CronTrigger in project engine by craftercms.

the class ConfigurationScriptJobResolverTest method testResolveJobs.

@Test
public void testResolveJobs() throws Exception {
    List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
    assertNotNull(jobContexts);
    assertEquals(2, jobContexts.size());
    JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
    CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/morejobs/testJob2.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
    jobDetail = (JobDetailImpl) jobContexts.get(1).getDetail();
    trigger = (CronTrigger) jobContexts.get(1).getTrigger();
    assertEquals(ScriptJob.class, jobDetail.getJobClass());
    assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
    assertEquals("0 0/15 * * * ?", trigger.getCronExpression());
}
Also used : CronTrigger(org.quartz.CronTrigger) JobDetailImpl(org.quartz.impl.JobDetailImpl) JobContext(org.craftercms.engine.util.quartz.JobContext) Test(org.junit.Test)

Example 50 with CronTrigger

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

the class BaseJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    // 是否已执行业务逻辑
    boolean isExecute = false;
    // 业务逻辑执行后返回结果
    boolean flag = false;
    try {
        // 可以通过context拿到执行当前任务的quartz中的很多信息,如当前是哪个trigger在执行该任务
        CronTrigger trigger = (CronTrigger) context.getTrigger();
        String corn = trigger.getCronExpression();
        String jobName = trigger.getKey().getName();
        String jobGroup = trigger.getKey().getGroup();
    } catch (Exception e) {
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) JobExecutionException(org.quartz.JobExecutionException)

Aggregations

CronTrigger (org.quartz.CronTrigger)103 JobDetail (org.quartz.JobDetail)42 Trigger (org.quartz.Trigger)36 SimpleTrigger (org.quartz.SimpleTrigger)29 SchedulerException (org.quartz.SchedulerException)28 Test (org.junit.Test)24 Scheduler (org.quartz.Scheduler)19 TriggerKey (org.quartz.TriggerKey)19 Date (java.util.Date)14 JobKey (org.quartz.JobKey)12 JobDataMap (org.quartz.JobDataMap)11 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 CronScheduleBuilder (org.quartz.CronScheduleBuilder)8 ParseException (java.text.ParseException)7 HashMap (java.util.HashMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 JobExecutionException (org.quartz.JobExecutionException)6 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)5 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)5