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");
}
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"));
}
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();
}
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());
}
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) {
}
}
Aggregations