Compare commits
2 Commits
dc8a8e9b4c
...
v0.1.15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d3cd1b5d5f | ||
|
|
51dcacc728 |
@@ -3,6 +3,7 @@ package com.tasteby.service;
|
||||
import com.tasteby.domain.DaemonConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -22,6 +23,9 @@ public class DaemonScheduler {
|
||||
private final PipelineService pipelineService;
|
||||
private final CacheService cacheService;
|
||||
|
||||
@Value("${app.daemon.enabled:true}")
|
||||
private boolean instanceEnabled;
|
||||
|
||||
public DaemonScheduler(DaemonConfigService daemonConfigService,
|
||||
YouTubeService youTubeService,
|
||||
PipelineService pipelineService,
|
||||
@@ -34,6 +38,10 @@ public class DaemonScheduler {
|
||||
|
||||
@Scheduled(fixedDelay = 30_000) // Check every 30 seconds
|
||||
public void run() {
|
||||
// 인스턴스 차원 차단(dev/prod 동일 DB 공유 환경에서 dev 쪽 동시 폴링 방지).
|
||||
// dev .env: DAEMON_ENABLED=false → 이 인스턴스는 스케줄러 동작 안 함.
|
||||
// prod: 미설정 → 기본 true.
|
||||
if (!instanceEnabled) return;
|
||||
try {
|
||||
var config = getConfig();
|
||||
if (config == null) return;
|
||||
|
||||
@@ -59,6 +59,7 @@ public class YouTubeService {
|
||||
String uploadsPlaylistId = "UU" + channelId.substring(2);
|
||||
List<Map<String, Object>> allVideos = new ArrayList<>();
|
||||
String nextPage = null;
|
||||
boolean stopPaging = false;
|
||||
|
||||
try {
|
||||
do {
|
||||
@@ -88,7 +89,7 @@ public class YouTubeService {
|
||||
// publishedAfter 필터: 이미 스캔한 영상 이후만
|
||||
if (publishedAfter != null && publishedAt.compareTo(publishedAfter) <= 0) {
|
||||
// 업로드 재생목록은 최신순이므로 이전 날짜 만나면 중단
|
||||
nextPage = null;
|
||||
stopPaging = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -105,7 +106,9 @@ public class YouTubeService {
|
||||
}
|
||||
allVideos.addAll(pageVideos);
|
||||
|
||||
if (nextPage != null || data.has("nextPageToken")) {
|
||||
if (stopPaging) {
|
||||
nextPage = null;
|
||||
} else {
|
||||
nextPage = data.has("nextPageToken") ? data.path("nextPageToken").asText() : null;
|
||||
}
|
||||
} while (nextPage != null);
|
||||
|
||||
@@ -59,6 +59,11 @@ app:
|
||||
cache:
|
||||
ttl-seconds: 600
|
||||
|
||||
daemon:
|
||||
# 인스턴스 차원 스케줄러 활성화. dev/prod가 같은 DB를 공유하므로
|
||||
# dev .env에 DAEMON_ENABLED=false를 설정해 dev 폴링을 끄고 prod만 동작시킨다.
|
||||
enabled: ${DAEMON_ENABLED:true}
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mybatis/mapper/*.xml
|
||||
config-location: classpath:mybatis/mybatis-config.xml
|
||||
|
||||
Reference in New Issue
Block a user