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

[fix] 걱정 전송 기능 수정 및 비동기 적용 #119

Merged
merged 2 commits into from
Aug 13, 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
25 changes: 25 additions & 0 deletions src/main/java/com/telepigeon/server/config/AsyncConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.telepigeon.server.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {

@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(5);
executor.setQueueCapacity(10);

executor.setThreadNamePrefix("FCMExecutor-");
executor.initialize();
return executor;
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/telepigeon/server/domain/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Profile {

private LocalDateTime updatedAt;

@ManyToOne(targetEntity= User.class, fetch=FetchType.LAZY)
@ManyToOne(targetEntity= User.class, fetch=FetchType.EAGER)
@JoinColumn(name="user_id")
private User user;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/telepigeon/server/domain/Worry.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Worry {

private LocalDateTime updatedAt;

@ManyToOne(targetEntity=Profile.class, fetch=FetchType.LAZY)
@ManyToOne(targetEntity=Profile.class, fetch=FetchType.EAGER)
@JoinColumn(name="profile_id")
private Profile profile;

Expand Down Expand Up @@ -59,8 +59,8 @@ public FcmMessageDto toFcmMessageDto() {
.title(this.name)
.body(this.content)
.type("worry")
.id(this.getProfile().getRoom().getId())
.clickAction("ROOM_CLICK")
.id(this.id)
.clickAction("WorryDetailActivity")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.telepigeon.server.service.worry.WorryRetriever;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.telepigeon.server.service.profile.ProfileRetriever;
Expand All @@ -24,6 +25,7 @@ public class ScheduleService {
private final WorryRetriever worryRetriever;
private final FcmService fcmService;

@Async
@Scheduled(cron="0 0 12 * * *")
public void createSchedule() {
for (Profile profile : profileRetriever.findAll()) {
Expand All @@ -35,6 +37,7 @@ public void createSchedule() {
}
}

@Async
@Scheduled(cron="0 0 * * * *")
public void sendWorries() {
String currentHour = LocalTime.now().format(DateTimeFormatter.ofPattern("HH시"));
Expand All @@ -43,7 +46,7 @@ public void sendWorries() {
try {
sendWorry(worry);
} catch (Exception e) {
log.error("Failed to send worry for worry {}", worry.getId());
log.error("Failed to send worry for worry {}", worry.getId(), e);
}
}
}
Expand Down
Loading