Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.time.LocalDateTime;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -24,8 +26,15 @@ public class DatePlaceLogScheduler {
private final DatePlaceRepository datePlaceRepository;
private final DatePlaceLogRepository datePlaceLogRepository;

@Async("logTaskExecutor")
@Scheduled(cron = "${scheduler.logs.date-place.sync-cron}")
@Transactional(readOnly = true)
@CacheEvict(
value = "date-place-log",
allEntries = true,
cacheManager = "redisCacheManager",
beforeInvocation = false
)
public void syncPlaceCategoryLogsToDB() {

LocalDate now = LocalDate.from(LocalDateTime.now().minusMinutes(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class LogPlaceCategoryAspect {

private final RedisTemplate<String, Object> redisTemplate;

@Async
@Async("logTaskExecutor")
@AfterReturning("@annotation(org.withtime.be.withtimebe.domain.log.placecategorylog.annotation.LogPlaceCategory)")
public void logPlaceCategory(JoinPoint joinPoint) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.withtime.be.withtimebe.domain.log.placecategorylog.scheduler;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -15,10 +13,9 @@
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.withtime.be.withtimebe.domain.date.entity.PlaceCategory;
import org.withtime.be.withtimebe.domain.date.repository.PlaceCategoryRepository;
import org.withtime.be.withtimebe.domain.log.placecategorylog.converter.PlaceCategoryLogConverter;
import org.withtime.be.withtimebe.domain.log.placecategorylog.model.PlaceCategoryLog;
import org.withtime.be.withtimebe.domain.log.placecategorylog.repository.PlaceCategoryLogRepository;
Expand All @@ -35,10 +32,11 @@ public class PlaceCategoryLogScheduler {
private final RedisTemplate<String, Object> redisTemplate;
private final PlaceCategoryLogRepository placeCategoryLogRepository;

@Scheduled(cron = "${scheduler.logs.place-category.sync-cron}") // 매 5분마다
@Async("logTaskExecutor")
@Scheduled(cron = "${scheduler.logs.place-category.sync-cron}")
@CacheEvict(
value = "place-category-log",
key = "'weekly:' + T(java.time.LocalDate).now().getYear() + '-' + T(java.time.temporal.WeekFields).ISO.weekOfYear().getFrom(T(java.time.LocalDate).now())",
allEntries = true,
cacheManager = "redisCacheManager",
beforeInvocation = false
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.withtime.be.withtimebe.global.config;

import java.util.concurrent.Executor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@EnableAsync
@Configuration
public class AsyncConfig {

@Bean(name = "logTaskExecutor")
public Executor logTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(1);
executor.setMaxPoolSize(3);
executor.setQueueCapacity(5);
executor.setThreadNamePrefix("Executor-Log-");
executor.initialize();
return executor;
}

@Bean(name = "weatherTaskExecutor")
public Executor weatherTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(1);
executor.setMaxPoolSize(3);
executor.setQueueCapacity(5);
executor.setThreadNamePrefix("Executor-Weather-");
executor.initialize();
return executor;
}
}