diff --git a/src/main/java/hsu/umc/server/aws/s3/AmazonS3Manager.java b/src/main/java/hsu/umc/server/aws/s3/AmazonS3Manager.java index 2093619..5421c87 100644 --- a/src/main/java/hsu/umc/server/aws/s3/AmazonS3Manager.java +++ b/src/main/java/hsu/umc/server/aws/s3/AmazonS3Manager.java @@ -28,7 +28,13 @@ public String uploadFile(String keyName, MultipartFile file)throws IOException { } public void deleteFile(String photoUrl){ String s3Key = photoUrl.replace("https://umc-7th.s3.ap-northeast-2.amazonaws.com/", ""); - amazonS3.deleteObject(new DeleteObjectRequest(amazonConfig.getBucket(), s3Key)); + log.info("삭제할 s3 키 = {}", s3Key); + try { + amazonS3.deleteObject(new DeleteObjectRequest(amazonConfig.getBucket(), s3Key)); + log.info("Successfully deleted file from S3 with key: {}", s3Key); + } catch (Exception e) { + log.error("Error deleting file from S3 with key: {}", s3Key, e); + } } public String generatePhotoKeyName(Uuid uuid) { return amazonConfig.getPhotoPath() + '/' + uuid.getUuid() + ".png"; diff --git a/src/main/java/hsu/umc/server/service/SchedulerServiceImpl.java b/src/main/java/hsu/umc/server/service/SchedulerServiceImpl.java index 2e56883..206ae1b 100644 --- a/src/main/java/hsu/umc/server/service/SchedulerServiceImpl.java +++ b/src/main/java/hsu/umc/server/service/SchedulerServiceImpl.java @@ -6,6 +6,7 @@ import hsu.umc.server.repository.PhotoRepository; import hsu.umc.server.repository.UuidRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,6 +15,7 @@ import java.time.LocalDateTime; import java.util.List; +@Slf4j @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -24,10 +26,12 @@ public class SchedulerServiceImpl implements SchedulerService{ @Scheduled(cron = "${cloud.aws.cron}") @Transactional public void deletePhoto() { + log.info("Scheduled task started for deleting photos"); List photoList = photoRepository.findAll(); photoList.stream() .filter(photo -> Duration.between(photo.getCreatedAt(), LocalDateTime.now()).toMinutes() >= 1) .forEach(photo -> { + log.info("Processing photo with URL: {}", photo.getPhotoUrl()); s3Manager.deleteFile(photo.getPhotoUrl()); String uuidUrl = extractUuidFromPhotoUrl(photo.getPhotoUrl());