Java Code Examples for org.springframework.scheduling.config.ScheduledTaskRegistrar#addTriggerTask()

The following examples show how to use org.springframework.scheduling.config.ScheduledTaskRegistrar#addTriggerTask() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchedulerConfig.java    From WeBASE-Transaction with Apache License 2.0 6 votes vote down vote up
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
    if (constants.isIfDeleteData()) {
        taskRegistrar.addTriggerTask(() -> scheduleService.deleteDataSchedule(),
            (context) -> new CronTrigger(constants.getCronDeleteData())
                .nextExecutionTime(context));
    }
    if (!constants.isIfDistributedTask()) {
        taskRegistrar.addTriggerTask(() -> scheduleService.deploySchedule(),
            (context) -> new CronTrigger(constants.getCronTrans())
                .nextExecutionTime(context));
        taskRegistrar.addTriggerTask(() -> scheduleService.transSchedule(),
            (context) -> new CronTrigger(constants.getCronTrans())
                .nextExecutionTime(context));
    }
}
 
Example 2
Source File: ScheduleConfig.java    From lion with Apache License 2.0 6 votes vote down vote up
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {

    final List<Schedule> scheduleList = scheduleMapper.getScheduleListByAppName(applicationName);

    if (null != scheduleList && !scheduleList.isEmpty()) {
        log.info("定时任务即将启动,预计启动任务数量[" + scheduleList.size() + "],时间:" + DateUtil.getCurrentDateTime());
        for (Schedule schedule : scheduleList) {
            // 判断任务是否有效
            if (schedule.getValid()) {
                // 执行定时任务
                taskRegistrar.addTriggerTask(getRunnable(schedule), getTrigger(schedule));
                scheduleTaskCount++;
            }
        }
        log.info("定时任务实际启动数量[" + scheduleTaskCount + "],时间:" + DateUtil.getCurrentDateTime());
    }
}
 
Example 3
Source File: AbstractJob.java    From chronus with Apache License 2.0 5 votes vote down vote up
protected void configureTasks(ScheduledTaskRegistrar taskRegistrar, Runnable task, String cron) {
    taskRegistrar.addTriggerTask(task, (TriggerContext triggerContext) -> {
        CronTrigger trigger = new CronTrigger(cron);
        Date nextExec = trigger.nextExecutionTime(triggerContext);
        return nextExec;
    });
}
 
Example 4
Source File: ScheduledConfig2.java    From SpringBoot2.0 with Apache License 2.0 5 votes vote down vote up
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
    taskRegistrar.setScheduler(taskExecutor());
    taskRegistrar.addTriggerTask(
            () -> myTask().work(),
            new CustomTrigger()
    );
}
 
Example 5
Source File: GemTaskServiceImpl.java    From gem with MIT License 5 votes vote down vote up
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
	taskRegistrar.addTriggerTask(() -> {
		// 定时任务的业务逻辑
		System.out.println("动态修改定时任务cron参数,当前时间:" + dateFormat.format(new Date()));
	}, (triggerContext) -> {
		// 定时任务触发,可修改定时任务的执行周期
		CronTrigger trigger = new CronTrigger(cron);
		Date nextExecDate = trigger.nextExecutionTime(triggerContext);
		return nextExecDate;
	});
}