Skip to content

Commit 9c0b516

Browse files
committed
[Hotfix] 파일서버스캔 수정
1 parent 44047c1 commit 9c0b516

2 files changed

Lines changed: 40 additions & 17 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.lastcommit.piilot.domain.filescan.service;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.scheduling.annotation.Async;
6+
import org.springframework.stereotype.Component;
7+
8+
/**
9+
* 파일 스캔 비동기 실행기.
10+
* <p>
11+
* Spring @Async는 같은 클래스 내 자기호출(self-invocation) 시 프록시를 거치지 않아 무시됩니다.
12+
* DB 스캔의 DbTableAsyncScanner처럼 별도 빈으로 분리하여 @Async가 정상 동작하도록 합니다.
13+
* </p>
14+
*/
15+
@Slf4j
16+
@Component
17+
@RequiredArgsConstructor
18+
public class FileScanAsyncExecutor {
19+
20+
private final FileScanService fileScanService;
21+
22+
@Async("fileScanExecutor")
23+
public void executeScanAsync(Long connectionId, Long scanHistoryId) {
24+
log.info("Starting async file scan for connectionId={}", connectionId);
25+
26+
try {
27+
fileScanService.executeScan(connectionId, scanHistoryId);
28+
} catch (Exception e) {
29+
log.error("File scan failed for connectionId={}: {}", connectionId, e.getMessage(), e);
30+
fileScanService.markScanFailed(scanHistoryId);
31+
} finally {
32+
fileScanService.markScanStopped(connectionId);
33+
}
34+
}
35+
}

‎src/main/java/com/lastcommit/piilot/domain/filescan/service/FileScanService.java‎

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.lastcommit.piilot.global.util.AesEncryptor;
1515
import lombok.RequiredArgsConstructor;
1616
import lombok.extern.slf4j.Slf4j;
17-
import org.springframework.scheduling.annotation.Async;
1817
import org.springframework.stereotype.Service;
1918
import org.springframework.transaction.annotation.Transactional;
2019

@@ -38,6 +37,7 @@ public class FileScanService {
3837
private final FileEncryptionChecker fileEncryptionChecker;
3938
private final FileAiServerClient fileAiServerClient;
4039
private final AesEncryptor aesEncryptor;
40+
private final FileScanAsyncExecutor fileScanAsyncExecutor;
4141

4242
@Transactional
4343
public FileScanResponseDTO startScan(Long connectionId) {
@@ -68,26 +68,14 @@ public FileScanResponseDTO startScan(Long connectionId) {
6868
.build();
6969
scanHistory = scanHistoryRepository.save(scanHistory);
7070

71-
// 6. Start async scan
72-
executeScanAsync(connectionId, scanHistory.getId());
71+
// 6. Start async scan (별도 빈을 통해 호출해야 @Async 프록시가 동작함)
72+
fileScanAsyncExecutor.executeScanAsync(connectionId, scanHistory.getId());
7373

7474
return FileScanResponseDTO.from(scanHistory);
7575
}
7676

77-
@Async("fileScanExecutor")
78-
public void executeScanAsync(Long connectionId, Long scanHistoryId) {
79-
log.info("Starting file scan for connectionId={}", connectionId);
80-
81-
try {
82-
executeScan(connectionId, scanHistoryId);
83-
} catch (Exception e) {
84-
log.error("File scan failed for connectionId={}: {}", connectionId, e.getMessage(), e);
85-
markScanFailed(scanHistoryId);
86-
} finally {
87-
// 스캔 완료/실패 시 isScanning = false
88-
markScanStopped(connectionId);
89-
}
90-
}
77+
// executeScanAsync는 FileScanAsyncExecutor로 이동됨
78+
// (같은 클래스 내 @Async 자기호출은 Spring 프록시를 거치지 않아 동기 실행됨)
9179

9280
@Transactional
9381
public void markScanStopped(Long connectionId) {

0 commit comments

Comments
 (0)