Search in sources :

Example 86 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project jhipster-sample-app-mongodb by jhipster.

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);
    }
}
Also used : User(io.github.jhipster.sample.domain.User) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 87 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project jhipster-sample-app-hazelcast by jhipster.

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);
        this.clearUserCaches(user);
    }
}
Also used : User(io.github.jhipster.sample.domain.User) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 88 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project jhipster-sample-app-dto by jhipster.

the class UserService method removeOldPersistentTokens.

/**
 * Persistent Token are used for providing automatic authentication, they should be automatically deleted after
 * 30 days.
 * <p>
 * This is scheduled to get fired everyday, at midnight.
 */
@Scheduled(cron = "0 0 0 * * ?")
public void removeOldPersistentTokens() {
    LocalDate now = LocalDate.now();
    persistentTokenRepository.findByTokenDateBefore(now.minusMonths(1)).forEach(token -> {
        log.debug("Deleting token {}", token.getSeries());
        User user = token.getUser();
        user.getPersistentTokens().remove(token);
        persistentTokenRepository.delete(token);
    });
}
Also used : User(io.github.jhipster.sample.domain.User) LocalDate(java.time.LocalDate) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 89 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project Corgi by kevinYin.

the class ProcessTimeoutTask method process.

/**
 * 每15分钟处理一次
 */
@Scheduled(cron = "0 */15 * * * ?")
public void process() {
    // lock 时间要超过5分钟,防止上一个任务没处理完,新的任务又来了
    // 1800 秒最多可以占 1800/5 次定时任务
    RedisLock redisLock = new RedisLock(redis, "deployment_timeout_task_check", 1800);
    if (redisLock.lock()) {
        logger.info("准备处理超时任务 ...");
        try {
            Date now = new Date();
            Date startTime = DateUtils.addSeconds(now, -Constants.DEPLOY_TASK_TIMEOUT * 3);
            Date endTime = DateUtils.addSeconds(now, -Constants.DEPLOY_TASK_TIMEOUT);
            final int MAX = 1000;
            logger.info("startTime: {}, endTime: {}", startTime, endTime);
            List<DeployHistory> list = deployHistoryService.queryUnfinished(startTime, endTime, MAX);
            if (list.size() > 0) {
                for (DeployHistory history : list) {
                    deployHistoryService.systemCancel(history.getHistoryId());
                }
                logger.info("处理超时任务数量: " + list.size());
            }
        } catch (Exception e) {
            logger.error("处理超时任务出错", e);
        } finally {
            redisLock.unlock();
        }
    } else {
        logger.info("抢锁失败,跳过 ......");
    }
}
Also used : RedisLock(com.ibeiliao.deployment.common.util.redis.RedisLock) DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 90 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project Corgi by kevinYin.

the class StatTask method dailyStat.

/**
 * 每日统计
 */
@Scheduled(cron = "0 0 1 * * ?")
public void dailyStat() {
    RedisLock redisLock = new RedisLock(redis, "task_daily_stat", 120);
    if (redisLock.lock()) {
        try {
            Date yesterday = DateUtils.addDays(new Date(), -1);
            statService.statDate(yesterday);
        } finally {
            redisLock.unlock();
        }
    } else {
        logger.info("抢锁失败,跳过 ......");
    }
}
Also used : RedisLock(com.ibeiliao.deployment.common.util.redis.RedisLock) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Scheduled (org.springframework.scheduling.annotation.Scheduled)140 Date (java.util.Date)38 IOException (java.io.IOException)17 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)12 File (java.io.File)9 List (java.util.List)9 User (io.github.jhipster.sample.domain.User)8 SimpleDateFormat (java.text.SimpleDateFormat)8 LocalDate (java.time.LocalDate)8 Map (java.util.Map)8 Word (ai.elimu.model.content.Word)6 Instant (java.time.Instant)6 SysConfig (com.itrus.portal.db.SysConfig)5 InetAddress (java.net.InetAddress)5 UnknownHostException (java.net.UnknownHostException)5 Contributor (ai.elimu.model.Contributor)4 StoryBookParagraph (ai.elimu.model.content.StoryBookParagraph)4 Language (ai.elimu.model.v2.enums.Language)4 Nabaztag (com.nabalive.data.core.model.Nabaztag)4