Skip to content

Commit

Permalink
Feat : 로그 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonda02 committed Aug 31, 2024
1 parent 6f4fdf8 commit 0cf4d77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/java/hsu/umc/server/aws/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,7 @@
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -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<Photo> 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());
Expand Down

0 comments on commit 0cf4d77

Please sign in to comment.