Search in sources :

Example 6 with CronTrigger

use of org.springframework.scheduling.support.CronTrigger in project hub-alert by blackducksoftware.

the class ScheduledTask method scheduleExecution.

public void scheduleExecution(String cron) {
    if (StringUtils.isNotBlank(cron)) {
        try {
            CronTrigger cronTrigger = new CronTrigger(cron, TimeZone.getTimeZone("UTC"));
            unscheduleTask();
            logger.info("Scheduling {} with cron : {}", getTaskName(), cron);
            future = taskScheduler.schedule(this, cronTrigger);
        } catch (IllegalArgumentException e) {
            logger.error(e.getMessage(), e);
        }
    } else {
        if (future != null) {
            logger.info("Un-Scheduling {}", getTaskName());
            unscheduleTask();
        }
    }
}
Also used : CronTrigger(org.springframework.scheduling.support.CronTrigger)

Example 7 with CronTrigger

use of org.springframework.scheduling.support.CronTrigger in project benchmark by seelunzi.

the class DynamicScheduledTask method configureTasks.

@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
    // taskRegistrar.addTriggerTask(new Runnable() {
    // @Override
    // public void run() {
    // if (!cron.equals(DEFAULT_CRON)) {
    // 
    // }
    // // 定时任务的业务逻辑
    // System.out.println("动态修改定时任务cron参数,当前时间:" + dateFormat.format(new Date()));
    // }
    // }, new Trigger() {
    // @Override
    // public Date nextExecutionTime(TriggerContext triggerContext) {
    // // 定时任务触发,可修改定时任务的执行周期
    // CronTrigger trigger = new CronTrigger(cron);
    // Date nextExecDate = trigger.nextExecutionTime(triggerContext);
    // return nextExecDate;
    // }
    // });
    taskRegistrar.addTriggerTask(() -> {
        if (!cron.equals(DEFAULT_CRON)) {
        }
        // 定时任务的业务逻辑
        System.out.println("动态修改定时任务cron参数,当前时间:" + dateFormat.format(new Date()));
    }, (triggerContext) -> {
        CronTrigger trigger = new CronTrigger(cron);
        Date nextExecDate = trigger.nextExecutionTime(triggerContext);
        return nextExecDate;
    });
}
Also used : CronTrigger(org.springframework.scheduling.support.CronTrigger) Date(java.util.Date)

Example 8 with CronTrigger

use of org.springframework.scheduling.support.CronTrigger in project camel by apache.

the class SpringScheduledPollConsumerScheduler method doStart.

@Override
protected void doStart() throws Exception {
    ObjectHelper.notEmpty(cron, "cron", this);
    trigger = new CronTrigger(getCron(), getTimeZone());
    if (taskScheduler == null) {
        taskScheduler = new CamelThreadPoolTaskScheduler(getCamelContext(), consumer, consumer.getEndpoint().getEndpointUri());
        taskScheduler.afterPropertiesSet();
        destroyTaskScheduler = true;
    }
    LOG.debug("Scheduling cron trigger {}", getCron());
    future = taskScheduler.schedule(runnable, trigger);
}
Also used : CamelThreadPoolTaskScheduler(org.apache.camel.spring.util.CamelThreadPoolTaskScheduler) CronTrigger(org.springframework.scheduling.support.CronTrigger)

Example 9 with CronTrigger

use of org.springframework.scheduling.support.CronTrigger in project gravitee-management-rest-api by gravitee-io.

the class ScheduledSubscriptionsService method doStart.

@Override
protected void doStart() throws Exception {
    if (enabled) {
        super.doStart();
        logger.info("Subscriptions Refresher service has been initialized with cron [{}]", cronTrigger);
        scheduler.schedule(this, new CronTrigger(cronTrigger));
    } else {
        logger.warn("Subscriptions Refresher service has been disabled");
    }
}
Also used : CronTrigger(org.springframework.scheduling.support.CronTrigger)

Example 10 with CronTrigger

use of org.springframework.scheduling.support.CronTrigger in project gravitee-management-rest-api by gravitee-io.

the class ScheduledSyncService method doStart.

@Override
protected void doStart() throws Exception {
    if (!localRegistryEnabled) {
        if (enabled) {
            super.doStart();
            logger.info("Sync service has been initialized with cron [{}]", cronTrigger);
            // Sync must start only when doStart() is invoked, that's the reason why we are not
            // using @Scheduled annotation on doSync() method.
            scheduler.schedule(this, new CronTrigger(cronTrigger));
        } else {
            logger.warn("Sync service has been disabled");
        }
    } else {
        logger.warn("Sync service is disabled because local registry mode is enabled");
    }
}
Also used : CronTrigger(org.springframework.scheduling.support.CronTrigger)

Aggregations

CronTrigger (org.springframework.scheduling.support.CronTrigger)14 Date (java.util.Date)4 Trigger (org.springframework.scheduling.Trigger)2 CronTask (org.springframework.scheduling.config.CronTask)2 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)2 SyncHandler (io.gravitee.gateway.services.sync.handler.SyncHandler)1 Method (java.lang.reflect.Method)1 Calendar (java.util.Calendar)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 TimeZone (java.util.TimeZone)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)1 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)1 CamelThreadPoolTaskScheduler (org.apache.camel.spring.util.CamelThreadPoolTaskScheduler)1 Lock (org.jumpmind.symmetric.model.Lock)1 Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1