Search in sources :

Example 21 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project cas by apereo.

the class AbstractServicesManager method load.

/**
 * Load services that are provided by the DAO.
 */
@Scheduled(initialDelayString = "${cas.serviceRegistry.schedule.startDelay:20000}", fixedDelayString = "${cas.serviceRegistry.schedule.repeatInterval:60000}")
@Override
@PostConstruct
public void load() {
    LOGGER.debug("Loading services from [{}]", this.serviceRegistry);
    this.services = this.serviceRegistry.load().stream().collect(Collectors.toConcurrentMap(r -> {
        LOGGER.debug("Adding registered service [{}]", r.getServiceId());
        return r.getId();
    }, Function.identity(), (r, s) -> s == null ? r : s));
    loadInternal();
    publishEvent(new CasRegisteredServicesLoadedEvent(this, getAllServices()));
    evaluateExpiredServiceDefinitions();
    LOGGER.info("Loaded [{}] service(s) from [{}].", this.services.size(), this.serviceRegistry.getName());
}
Also used : CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent) Scheduled(org.springframework.scheduling.annotation.Scheduled) PostConstruct(javax.annotation.PostConstruct)

Example 22 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project cas by apereo.

the class MultifactorAuthenticationTrustStorageCleaner method clean.

/**
 * Clean up expired records.
 */
@Scheduled(initialDelayString = "${cas.authn.mfa.trusted.cleaner.schedule.startDelay:PT10S}", fixedDelayString = "${cas.authn.mfa.trusted.cleaner.schedule.repeatInterval:PT60S}")
public void clean() {
    if (!trustedProperties.getCleaner().getSchedule().isEnabled()) {
        LOGGER.debug("[{}] is disabled. Expired trusted authentication records will not automatically be cleaned up by CAS", getClass().getName());
        return;
    }
    try {
        LOGGER.debug("Proceeding to clean up expired trusted authentication records...");
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        final LocalDate validDate = LocalDate.now().minus(trustedProperties.getExpiration(), DateTimeUtils.toChronoUnit(trustedProperties.getTimeUnit()));
        LOGGER.info("Expiring records that are on/before [{}]", validDate);
        this.storage.expire(validDate);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : LocalDate(java.time.LocalDate) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 23 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project CzechIdMng by bcvsolutions.

the class DefaultAttachmentManager method purgeTempFiles.

/**
 * Purge old temporary files once per day.
 * Temporary files older than configured ttl will be purged.
 *
 * @return purged files count
 */
@Scheduled(fixedDelay = 3600000)
public void purgeTempFiles() {
    int purgedFiles = 0;
    long ttl = attachmentConfiguration.getTempTtl();
    if (ttl == 0) {
        LOG.warn("Removing old temporary files is disabled. Configure property [{}] - time to live in milliseconds (greater than zero).", AttachmentConfiguration.PROPERTY_TEMP_TTL);
        return;
    }
    // 
    // purge older temporary files than purge time
    long purgeTime = System.currentTimeMillis() - ttl;
    File temp = new File(getTempPath());
    if (temp.isDirectory()) {
        File[] files = temp.listFiles();
        if (files != null) {
            for (File f : files) {
                try {
                    if (f.getName().endsWith("." + DEFAULT_TEMP_FILE_EXTENSION) && f.lastModified() < purgeTime) {
                        f.delete();
                        purgedFiles++;
                    }
                } catch (Exception ex) {
                    LOG.error("Removing old temporary [.{}] file [{}] failed", DEFAULT_TEMP_FILE_EXTENSION, f.getName(), ex);
                }
            }
        }
    }
    LOG.debug("Temporary files were purged [{}]", purgedFiles);
}
Also used : File(java.io.File) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 24 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManager method scheduleProcessCreated.

/**
 * Spring schedule new task after previous task ended (don't run concurrently)
 */
@Scheduled(fixedDelayString = "${" + SchedulerConfiguration.PROPERTY_EVENT_QUEUE_PROCESS + ":" + SchedulerConfiguration.DEFAULT_EVENT_QUEUE_PROCESS + "}")
public void scheduleProcessCreated() {
    if (!eventConfiguration.isAsynchronous()) {
        // prevent to debug some messages into log - usable for devs
        return;
    }
    // run as system - called from scheduler internally
    securityService.setSystemAuthentication();
    // 
    // calculate events to process
    String instanceId = configurationService.getInstanceId();
    List<IdmEntityEventDto> events = getCreatedEvents(instanceId);
    LOG.trace("Events to process [{}] on instance [{}].", events.size(), instanceId);
    for (IdmEntityEventDto event : events) {
        // @Transactional
        context.getBean(this.getClass()).executeEvent(event);
        ;
    }
}
Also used : IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 25 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project uplace.es by Uplace.

the class UserService method removeNotActivatedUsers.

/**
 * Not activated users should be automatically deleted after 3 days.
 * <p>
 * This is scheduled to get fired everyday, at 01:00 (am).
 */
@Scheduled(cron = "0 0 1 * * ?")
public void removeNotActivatedUsers() {
    List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(Instant.now().minus(3, ChronoUnit.DAYS));
    for (User user : users) {
        log.debug("Deleting not activated user {}", user.getLogin());
        userRepository.delete(user);
        cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE).evict(user.getLogin());
        cacheManager.getCache(UserRepository.USERS_BY_EMAIL_CACHE).evict(user.getEmail());
    }
}
Also used : User(com.arnaugarcia.uplace.domain.User) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Scheduled (org.springframework.scheduling.annotation.Scheduled)31 Date (java.util.Date)8 Nabaztag (com.nabalive.data.core.model.Nabaztag)4 IOException (java.io.IOException)4 Application (com.nabalive.application.core.Application)3 Status (com.nabalive.server.jabber.Status)3 File (java.io.File)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 DisruptorBindEvent (com.lmax.disruptor.spring.boot.event.DisruptorBindEvent)2 BigDecimal (java.math.BigDecimal)2 DateFormat (java.text.DateFormat)2 LocalDate (java.time.LocalDate)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)2 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)2 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)2 SpeciesListDTO (au.org.ala.spatial.dto.SpeciesListDTO)1 Capture (co.videofirst.vft.capture.model.capture.Capture)1