use of org.quartz.SimpleTrigger in project spring-boot by spring-projects.
the class QuartzEndpointTests method quartzTriggerGroupSummaryWithSimpleTriggerDetails.
@Test
void quartzTriggerGroupSummaryWithSimpleTriggerDetails() throws SchedulerException {
Date previousFireTime = Date.from(Instant.parse("2020-11-30T03:00:00Z"));
Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().withIdentity("every-hour", "samples").withPriority(7).withSchedule(SimpleScheduleBuilder.repeatHourlyForever(1)).build();
((OperableTrigger) simpleTrigger).setPreviousFireTime(previousFireTime);
((OperableTrigger) simpleTrigger).setNextFireTime(nextFireTime);
mockTriggers(simpleTrigger);
QuartzTriggerGroupSummary summary = this.endpoint.quartzTriggerGroupSummary("samples");
Map<String, Object> triggers = summary.getTriggers().getSimple();
assertThat(triggers).containsOnlyKeys("every-hour");
assertThat(triggers).extractingByKey("every-hour", nestedMap()).containsOnly(entry("previousFireTime", previousFireTime), entry("nextFireTime", nextFireTime), entry("priority", 7), entry("interval", 3600000L));
}
use of org.quartz.SimpleTrigger in project spring-boot by spring-projects.
the class QuartzEndpointTests method quartzTriggerWithSimpleTrigger.
@Test
void quartzTriggerWithSimpleTrigger() throws SchedulerException {
Date startTime = Date.from(Instant.parse("2020-01-01T09:00:00Z"));
Date previousFireTime = Date.from(Instant.parse("2020-11-30T03:00:00Z"));
Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
Date endTime = Date.from(Instant.parse("2020-01-31T09:00:00Z"));
SimpleTrigger trigger = TriggerBuilder.newTrigger().withIdentity("every-hour", "samples").withPriority(20).withDescription("Every hour").startAt(startTime).endAt(endTime).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(1).withRepeatCount(2000)).build();
((OperableTrigger) trigger).setPreviousFireTime(previousFireTime);
((OperableTrigger) trigger).setNextFireTime(nextFireTime);
mockTriggers(trigger);
given(this.scheduler.getTriggerState(TriggerKey.triggerKey("every-hour", "samples"))).willReturn(TriggerState.COMPLETE);
Map<String, Object> triggerDetails = this.endpoint.quartzTrigger("samples", "every-hour");
assertThat(triggerDetails).contains(entry("group", "samples"), entry("name", "every-hour"), entry("description", "Every hour"), entry("type", "simple"), entry("state", TriggerState.COMPLETE), entry("priority", 20));
assertThat(triggerDetails).contains(entry("startTime", startTime), entry("previousFireTime", previousFireTime), entry("nextFireTime", nextFireTime), entry("endTime", endTime));
assertThat(triggerDetails).doesNotContainKeys("cron", "dailyTimeInterval", "calendarInterval", "custom");
assertThat(triggerDetails).extractingByKey("simple", nestedMap()).containsOnly(entry("interval", 3600000L), entry("repeatCount", 2000), entry("timesTriggered", 0));
}
use of org.quartz.SimpleTrigger in project spring-boot by spring-projects.
the class QuartzAutoConfigurationTests method withOverwriteExistingJobs.
@Test
void withOverwriteExistingJobs() {
this.contextRunner.withUserConfiguration(OverwriteTriggerConfiguration.class).withPropertyValues("spring.quartz.overwrite-existing-jobs=true").run((context) -> {
assertThat(context).hasSingleBean(Scheduler.class);
Scheduler scheduler = context.getBean(Scheduler.class);
Trigger fooTrigger = scheduler.getTrigger(TriggerKey.triggerKey("fooTrigger"));
assertThat(fooTrigger).isNotNull();
assertThat(((SimpleTrigger) fooTrigger).getRepeatInterval()).isEqualTo(30000);
});
}
use of org.quartz.SimpleTrigger in project spring-boot by spring-projects.
the class QuartzEndpointDocumentationTests method quartzTriggerGroup.
@Test
void quartzTriggerGroup() throws Exception {
CronTrigger cron = cronTrigger.getTriggerBuilder().startAt(fromUtc("2020-11-30T17:00:00Z")).endAt(fromUtc("2020-12-30T03:00:00Z")).withIdentity("3am-week", "tests").build();
setPreviousNextFireTime(cron, "2020-12-04T03:00:00Z", "2020-12-07T03:00:00Z");
SimpleTrigger simple = simpleTrigger.getTriggerBuilder().withIdentity("every-day", "tests").build();
setPreviousNextFireTime(simple, null, "2020-12-04T12:00:00Z");
CalendarIntervalTrigger calendarInterval = calendarIntervalTrigger.getTriggerBuilder().withIdentity("once-a-week", "tests").startAt(fromUtc("2019-07-10T14:00:00Z")).endAt(fromUtc("2023-01-01T12:00:00Z")).build();
setPreviousNextFireTime(calendarInterval, "2020-12-02T14:00:00Z", "2020-12-08T14:00:00Z");
DailyTimeIntervalTrigger tueThuTrigger = dailyTimeIntervalTrigger.getTriggerBuilder().withIdentity("tue-thu", "tests").build();
Trigger customTrigger = mock(Trigger.class);
given(customTrigger.getKey()).willReturn(TriggerKey.triggerKey("once-a-year-custom", "tests"));
given(customTrigger.toString()).willReturn("com.example.CustomTrigger@fdsfsd");
given(customTrigger.getPriority()).willReturn(10);
given(customTrigger.getPreviousFireTime()).willReturn(fromUtc("2020-07-14T16:00:00Z"));
given(customTrigger.getNextFireTime()).willReturn(fromUtc("2021-07-14T16:00:00Z"));
mockTriggers(cron, simple, calendarInterval, tueThuTrigger, customTrigger);
this.mockMvc.perform(get("/actuator/quartz/triggers/tests")).andExpect(status().isOk()).andDo(document("quartz/trigger-group", responseFields(fieldWithPath("group").description("Name of the group."), fieldWithPath("paused").description("Whether the group is paused."), fieldWithPath("triggers.cron").description("Cron triggers keyed by name, if any."), fieldWithPath("triggers.simple").description("Simple triggers keyed by name, if any."), fieldWithPath("triggers.dailyTimeInterval").description("Daily time interval triggers keyed by name, if any."), fieldWithPath("triggers.calendarInterval").description("Calendar interval triggers keyed by name, if any."), fieldWithPath("triggers.custom").description("Any other triggers keyed by name, if any.")).andWithPrefix("triggers.cron.*.", concat(triggerSummary, cronTriggerSummary)).andWithPrefix("triggers.simple.*.", concat(triggerSummary, simpleTriggerSummary)).andWithPrefix("triggers.dailyTimeInterval.*.", concat(triggerSummary, dailyTimeIntervalTriggerSummary)).andWithPrefix("triggers.calendarInterval.*.", concat(triggerSummary, calendarIntervalTriggerSummary)).andWithPrefix("triggers.custom.*.", concat(triggerSummary, customTriggerSummary))));
}
use of org.quartz.SimpleTrigger in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManager method getTask.
/**
* Returns task by given key
*
* @param jobKey
* @return task dto
*/
@SuppressWarnings("unchecked")
private Task getTask(JobKey jobKey) {
try {
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
// job does not exists
return null;
}
Task task = new Task();
// task setting
task.setId(jobKey.getName());
// app context is needed here
SchedulableTaskExecutor<?> taskExecutor = (SchedulableTaskExecutor<?>) context.getAutowireCapableBeanFactory().createBean(jobDetail.getJobClass());
task.setTaskType((Class<? extends SchedulableTaskExecutor<?>>) AutowireHelper.getTargetClass(taskExecutor));
task.setDescription(jobDetail.getDescription());
JobDataMap jobDataMap = jobDetail.getJobDataMap();
task.setInstanceId(jobDataMap.getString(SchedulableTaskExecutor.PARAMETER_INSTANCE_ID));
task.setModified((ZonedDateTime) jobDataMap.get(SchedulableTaskExecutor.PARAMETER_MODIFIED));
task.setTriggers(new ArrayList<>());
// task properties
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
task.getParameters().put(entry.getKey(), entry.getValue() == null ? null : entry.getValue().toString());
}
task.setDisabled(taskExecutor.isDisabled());
if (!task.isDisabled()) {
task.setSupportsDryRun(taskExecutor.supportsDryRun());
task.setFormDefinition(taskExecutor.getFormDefinition());
task.setRecoverable(taskExecutor.isRecoverable());
} else {
LOG.warn("Task [{}] is disabled and cannot be executed, remove schedule for this task to hide this warning.", task.getTaskType().getSimpleName());
}
// scheduled triggers - native
for (Trigger trigger : scheduler.getTriggersOfJob(jobKey)) {
TriggerState state = scheduler.getTriggerState(trigger.getKey());
if (trigger instanceof CronTrigger) {
task.getTriggers().add(new CronTaskTrigger(task.getId(), (CronTrigger) trigger, TaskTriggerState.convert(state)));
} else if (trigger instanceof SimpleTrigger) {
task.getTriggers().add(new SimpleTaskTrigger(task.getId(), (SimpleTrigger) trigger, TaskTriggerState.convert(state)));
} else {
LOG.warn("Job '{}' ({}) has registered trigger of unsupported type {}", jobKey, jobDetail.getJobClass(), trigger);
}
}
// dependent tasks
dependentTaskTriggerRepository.findByDependentTaskId(jobKey.getName()).forEach(dependentTask -> {
task.getTriggers().add(new DependentTaskTrigger(task.getId(), dependentTask.getId(), dependentTask.getInitiatorTaskId()));
});
return task;
} catch (org.quartz.SchedulerException ex) {
if (ex.getCause() instanceof ClassNotFoundException) {
deleteTask(jobKey.getName());
LOG.warn("Job [{}] inicialization failed, job class was removed, scheduled task is removed.", jobKey, ex);
return null;
}
throw new CoreException(ex);
} catch (BeansException | IllegalArgumentException ex) {
deleteTask(jobKey.getName());
LOG.warn("Job [{}] inicialization failed, scheduled task is removed", jobKey, ex);
return null;
}
}
Aggregations