@@ -43,7 +43,6 @@ public class SourceService implements SourcePublicApi {
4343 private final MemberPublicApi memberPublicApi ;
4444 private final SourceFolderPublicApi sourceFolderPublicApi ;
4545 private final ApplicationEventPublisher eventPublisher ;
46- private final SourceService self ;
4746
4847 @ Override
4948 public SourceUploadResponse generateUploadUrl (
@@ -121,7 +120,7 @@ public InputStream getContentStream(Long sourceId, Long memberId) {
121120 try {
122121 return s3PublicApi .downloadFileAsStream (source .getFilePath ());
123122 } catch (NoSuchKeyException e ) {
124- self . markSourceAsError (source .getId ());
123+ markSourceAsNotExist (source .getId ());
125124 throw S3FileNotFoundForSourceException .bySourceIdAndFilePath (sourceId , source .getFilePath ());
126125 }
127126 }
@@ -136,7 +135,7 @@ public Path downloadFileToTemp(long sourceId, long memberId) throws IOException
136135 try {
137136 return s3PublicApi .downloadFileToTemp (source .getFilePath ());
138137 } catch (NoSuchKeyException e ) {
139- self . markSourceAsError (source .getId ());
138+ markSourceAsNotExist (source .getId ());
140139 throw S3FileNotFoundForSourceException .bySourceIdAndFilePath (sourceId , source .getFilePath ());
141140 }
142141 }
@@ -178,6 +177,17 @@ public void markSourceAsError(Long sourceId) {
178177 });
179178 }
180179
180+ @ Transactional (propagation = Propagation .REQUIRES_NEW )
181+ public void markSourceAsNotExist (Long sourceId ) {
182+ sourceRepository
183+ .findById (sourceId )
184+ .ifPresent (
185+ source -> {
186+ source .markAsNotExist ();
187+ log .warn ("Source ID {}의 상태를 NOT_EXIST로 변경했습니다." , sourceId );
188+ });
189+ }
190+
181191 @ Transactional
182192 public void synchronizeS3Files () {
183193 log .info ("DB에 READY 상태이지만 S3에 존재하지 않는 Source 데이터 정리를 시작합니다." );
@@ -207,15 +217,14 @@ public void synchronizeS3Files() {
207217 @ Transactional
208218 public void migrateUploadedSourcesToReady () {
209219 log .info ("기존 UPLOADED 상태의 소스 데이터 마이그레이션을 시작합니다." );
210- List <Source > uploadedSources = findUploadedSources ( );
220+ List <Source > uploadedSources = sourceRepository . findByStatus ( SourceStatus . UPLOADED );
211221
212222 int successCount = processMigrationForSources (uploadedSources );
213223
214- logMigrationSummary (uploadedSources .size (), successCount );
215- }
216-
217- private List <Source > findUploadedSources () {
218- return sourceRepository .findByStatus (SourceStatus .UPLOADED );
224+ log .info (
225+ "소스 데이터 마이그레이션을 완료했습니다. 총 {}개의 소스 중 {}개의 상태를 READY로 변경했습니다." ,
226+ uploadedSources .size (),
227+ successCount );
219228 }
220229
221230 private int processMigrationForSources (List <Source > sources ) {
@@ -232,44 +241,25 @@ private boolean tryMigrateSingleSource(Source source) {
232241 try {
233242 return migrateSourceIfFileExists (source );
234243 } catch (Exception e ) {
235- logMigrationError (source , e );
244+ log .error (
245+ "마이그레이션 중 Source ID {} 처리 오류 발생. 파일 경로: {}" , source .getId (), source .getFilePath (), e );
236246 return false ;
237247 }
238248 }
239249
240250 private boolean migrateSourceIfFileExists (Source source ) {
241251 if (s3PublicApi .fileExists (source .getFilePath ())) {
242- updateSourceStatusToReady (source );
243- logMigrationSuccess (source );
252+ source .markAsReady ();
253+ sourceRepository .save (source );
254+ log .info ("Source ID {}의 상태를 READY로 변경했습니다. 파일 경로: {}" , source .getId (), source .getFilePath ());
244255 return true ;
245256 }
246257
247- logS3FileNotFound (source );
248- return false ;
249- }
250-
251- private void updateSourceStatusToReady (Source source ) {
252- source .markAsReady ();
253- sourceRepository .save (source );
254- }
255-
256- private void logMigrationSuccess (Source source ) {
257- log .info ("Source ID {}의 상태를 READY로 변경했습니다. 파일 경로: {}" , source .getId (), source .getFilePath ());
258- }
259-
260- private void logS3FileNotFound (Source source ) {
261258 log .warn (
262259 "S3에 파일이 존재하지 않아 Source ID {}의 상태를 변경하지 않았습니다. 파일 경로: {}" ,
263260 source .getId (),
264261 source .getFilePath ());
265- }
266-
267- private void logMigrationError (Source source , Exception e ) {
268- log .error ("마이그레이션 중 Source ID {} 처리 오류 발생. 파일 경로: {}" , source .getId (), source .getFilePath (), e );
269- }
270-
271- private void logMigrationSummary (int total , int success ) {
272- log .info ("소스 데이터 마이그레이션을 완료했습니다. 총 {}개의 소스 중 {}개의 상태를 READY로 변경했습니다." , total , success );
262+ return false ;
273263 }
274264
275265 private Source getOrElseThrow (Long sourceId , Long memberId ) {
0 commit comments