forked from solid-connection/solid-connect-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateViewCountScheduler.java
More file actions
36 lines (29 loc) · 1.32 KB
/
UpdateViewCountScheduler.java
File metadata and controls
36 lines (29 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.example.solidconnection.scheduler;
import static com.example.solidconnection.redis.RedisConstants.VIEW_COUNT_KEY_PATTERN;
import com.example.solidconnection.community.post.service.UpdateViewCountService;
import com.example.solidconnection.util.RedisUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
@RequiredArgsConstructor
@Component
@EnableScheduling
@EnableAsync
public class UpdateViewCountScheduler {
private final RedisUtils redisUtils;
private final ThreadPoolTaskExecutor asyncExecutor;
private final UpdateViewCountService updateViewCountService;
@Async
@Scheduled(fixedDelayString = "${view.count.scheduling.delay}")
public void updateViewCount() {
List<String> itemViewCountKeys = redisUtils.getKeysOrderByExpiration(VIEW_COUNT_KEY_PATTERN.getValue());
itemViewCountKeys.forEach(key -> asyncExecutor.submit(() -> {
updateViewCountService.updateViewCount(key);
}));
}
}