Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 서버 배포 #276

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ImageDeleteJobExecutionListener implements JobExecutionListener {
public void beforeJob(JobExecution jobExecution) {
LocalDateTime now = LocalDateTime.now();
log.info(
"[{}] - 14일이 지난 이미지 삭제 배치 작업을 시작합니다.",
"[{}] - 14일이 지났거나 연결된 그룹이 없는 이미지 삭제 배치 작업을 시작합니다.",
now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void fetchNext() {
LocalDateTime twoWeeksAgo = LocalDateTime.now().minusDays(14);
TypedQuery<ImageEntity> query =
em.createQuery(
"SELECT v FROM ImageEntity v WHERE v.createdAt <= (:twoWeeksAgo)",
"SELECT v FROM ImageEntity v WHERE v.createdAt <= (:twoWeeksAgo) OR v.group IS NULL",
ImageEntity.class)
.setParameter("twoWeeksAgo", twoWeeksAgo)
.setFirstResult(curIdx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class OldImageDeleteJobConfig {

@Bean
@JobScope
public Step oldImageDeleteStep(JobRepository jobRepository) {
return new StepBuilder("oldImageDeleteStep", jobRepository)
public Step oldOrRemovedImageDeleteStep(JobRepository jobRepository) {
return new StepBuilder("oldOrRemovedImageDeleteStep", jobRepository)
.<ImageEntity, ImageEntity>chunk(10, transactionManager)
.reader(itemReader)
.processor(itemProcessor)
Expand All @@ -34,10 +34,10 @@ public Step oldImageDeleteStep(JobRepository jobRepository) {
}

@Bean
public Job oldImageDeleteJob(JobRepository jobRepository) {
return new JobBuilder("oldImageDeleteJob", jobRepository)
public Job oldOrRemovedImageDeleteJob(JobRepository jobRepository) {
return new JobBuilder("oldOrRemovedImageDeleteJob", jobRepository)
.listener(imageDeleteJobExecutionListener)
.start(oldImageDeleteStep(jobRepository))
.start(oldOrRemovedImageDeleteStep(jobRepository))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void runJob() {
oldMediaDeleteJobConfig.oldMediaDeleteJob(jobRepository), jobParameters);

jobLauncher.run(
oldImageDeleteJobConfig.oldImageDeleteJob(jobRepository), jobParameters);
oldImageDeleteJobConfig.oldOrRemovedImageDeleteJob(jobRepository),
jobParameters);

} catch (JobExecutionAlreadyRunningException
| JobInstanceAlreadyCompleteException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void deleteGroupMember(Long memberId, Long groupId) {
// 방장 퇴장
groupMemberRepository.deleteByGroupId(groupId);
cctvRepository.deleteByGroupId(groupId);
imageRepository.deleteByGroupId(groupId);
imageRepository.updateGroupNull(groupId);
groupRepository.deleteById(groupId);
} else {
// 참여자 퇴장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ImageEntity {
@Column(nullable = false, length = 50)
private String imageName;

@JoinColumn(nullable = false)
@JoinColumn
@ManyToOne(fetch = FetchType.LAZY)
private GroupEntity group;

Expand All @@ -35,10 +35,11 @@ public class ImageEntity {
private LocalDateTime createdAt;

@Builder
public ImageEntity(String imageName, GroupEntity group, String imagePath) {

public ImageEntity(
String imageName, GroupEntity group, String imagePath, LocalDateTime createdAt) {
this.imageName = imageName;
this.group = group;
this.imagePath = imagePath;
this.createdAt = createdAt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ImageRepository {
ImageEntity save(ImageEntity imageEntity);

void deleteByGroupId(Long groupId);

void updateGroupNull(Long groupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ public ImageEntity save(ImageEntity imageEntity) {
public void deleteByGroupId(Long groupId) {
imageJpaRepository.deleteByGroupId(groupId);
}

@Override
public void updateGroupNull(Long groupId) {
queryFactory
.update(imageEntity)
.setNull(imageEntity.group)
.where(imageEntity.group.id.eq(groupId))
.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public void deleteMember(String authHeader, Long memberId) {
cctvRepository.deleteByGroupId(groupId);
log.info("[방장 회원 탈퇴] {}", "GroupId 기준으로 CCTV 목록을 삭제하였습니다.");

// Image 목록 삭제
imageRepository.deleteByGroupId(groupId);
log.info("[방장 회원 탈퇴] {}", "GroupId 기준으로 Image 목록을 삭제하였습니다.");
// Image 목록 group 필드 null
imageRepository.updateGroupNull(groupId);
log.info("[방장 회원 탈퇴] {}", "GroupId 기준으로 Image 목록의 Group 필드를 Null로 변경하였습니다.");

// GroupId 기준으로 groupMember 모두 찾아 삭제
groupMemberRepository.deleteAllByGroupId(groupId);
Expand Down
Loading