use of org.quartz.CronTrigger 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.CronTrigger 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;
}
}
use of org.quartz.CronTrigger in project engine by craftercms.
the class FolderBasedScriptJobResolverTest method testResolveJobs.
@Test
public void testResolveJobs() throws Exception {
List<JobContext> jobContexts = resolver.resolveJobs(siteContext);
assertNotNull(jobContexts);
assertEquals(1, jobContexts.size());
JobDetailImpl jobDetail = (JobDetailImpl) jobContexts.get(0).getDetail();
CronTrigger trigger = (CronTrigger) jobContexts.get(0).getTrigger();
assertEquals(ScriptJob.class, jobDetail.getJobClass());
assertEquals("/scripts/jobs/testJob.groovy", jobDetail.getJobDataMap().getString(ScriptJob.SCRIPT_URL_DATA_KEY));
assertEquals(HOURLY_CRON_EXPRESSION, trigger.getCronExpression());
}
use of org.quartz.CronTrigger in project dubidubi by lzzzz4.
the class Quartz method updateJobTime.
public static void updateJobTime(String jobName, String jobGroupName, String triggerName, String triggerGroupName, String cron) {
try {
Scheduler sched = schedulerFactory.getScheduler();
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, triggerGroupName);
CronTrigger trigger = (CronTrigger) sched.getTrigger(triggerKey);
if (trigger == null) {
return;
}
String oldTime = trigger.getCronExpression();
if (!oldTime.equalsIgnoreCase(cron)) {
/**
* 方式一 :调用 rescheduleJob 开始
*/
// 触发器
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
// 触发器名,触发器组
triggerBuilder.withIdentity(triggerName, triggerGroupName);
triggerBuilder.startNow();
// 触发器时间设定
triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cron));
// 创建Trigger对象
trigger = (CronTrigger) triggerBuilder.build();
// 方式一 :修改一个任务的触发时间
sched.rescheduleJob(triggerKey, trigger);
/**
* 方式一 :调用 rescheduleJob 结束
*/
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.quartz.CronTrigger in project ballerina by ballerina-lang.
the class AppointmentManager method schedule.
void schedule(String taskId, NativeCallableUnit fn, Class<? extends Job> jobClass, Context balParentContext, FunctionRefCPEntry onTriggerFunction, FunctionRefCPEntry onErrorFunction, String cronExpression) throws SchedulerException {
JobDataMap jobData = new JobDataMap();
jobData.put(AppointmentConstants.BALLERINA_FUNCTION, fn);
jobData.put(AppointmentConstants.BALLERINA_PARENT_CONTEXT, balParentContext);
jobData.put(AppointmentConstants.BALLERINA_ON_TRIGGER_FUNCTION, onTriggerFunction);
jobData.put(AppointmentConstants.BALLERINA_ON_ERROR_FUNCTION, onErrorFunction);
JobDetail job = newJob(jobClass).usingJobData(jobData).withIdentity(taskId).build();
CronTrigger trigger = newTrigger().withIdentity(taskId).withSchedule(cronSchedule(cronExpression)).build();
scheduler.scheduleJob(job, trigger);
quartzJobs.put(taskId, job.getKey());
}
Aggregations