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);
}
}
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);
}
}
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);
});
}
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("抢锁失败,跳过 ......");
}
}
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("抢锁失败,跳过 ......");
}
}
Aggregations