Skip to content

Commit

Permalink
RAC-451 fix : 정산 자동 생성시 성공 여부 확인 후 재시도 하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ywj9811 committed Oct 28, 2024
1 parent ac57a30 commit 3f15399
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.postgraduate.batch.scheduler;

import com.postgraduate.domain.member.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.salary.domain.service.SalaryGetService;
import com.postgraduate.global.slack.SlackErrorMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
Expand All @@ -20,6 +23,8 @@
@Slf4j
@RequiredArgsConstructor
public class JobSchedulerConfig {
private static final int MAX_RETRIES = 5;

private final JobLauncher jobLauncher;
@Qualifier("cancelJob")
private final Job cancelJob;
Expand All @@ -30,6 +35,10 @@ public class JobSchedulerConfig {
@Qualifier("salaryJobWithAdmin")
private final Job salaryJobWithAdmin;

private final SeniorGetService seniorGetService;
private final SalaryGetService salaryGetService;
private final SlackErrorMessage slackErrorMessage;

@Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul")
public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
JobParameters jobParameters = new JobParametersBuilder()
Expand All @@ -52,12 +61,32 @@ public void launchSalaryJob() throws JobInstanceAlreadyCompleteException, JobExe
.addLocalDateTime("date", LocalDateTime.now())
.toJobParameters();
jobLauncher.run(salaryJob, jobParameters);
checkSalaryJobSuccess(jobParameters);
}

public void launchSalaryJobWithAdmin() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
JobParameters jobParameters = new JobParametersBuilder()
.addLocalDateTime("date", LocalDateTime.now())
.toJobParameters();
jobLauncher.run(salaryJobWithAdmin, jobParameters);
checkSalaryJobSuccess(jobParameters);
}

private void checkSalaryJobSuccess(JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
int retries = 0;
boolean success = false;
int seniorSize = seniorGetService.allSeniorId()
.size();
while (retries < MAX_RETRIES){
int salarySize = salaryGetService.findAllNext()
.size();
if (salarySize == seniorSize) {
success = true;
break;
}
jobLauncher.run(salaryJobWithAdmin, jobParameters);
}
if (!success) {
slackErrorMessage.sendSlackSalaryError();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
public interface SalaryRepository extends JpaRepository<Salary, Long>, SalaryDslRepository {
Optional<Salary> findBySeniorAndSalaryDateAndSenior_User_IsDeleteIsFalse(Senior senior, LocalDate salaryDate);
List<Salary> findAllBySenior(Senior senior);
List<Salary> findAllBySalaryDate(LocalDate salaryDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ public List<Salary> findAllLast() {
log.info("salaryDate : {}", salaryDate);
return salaryRepository.findAllLastSalary(salaryDate);
}

public List<Salary> findAllNext() {
LocalDate salaryDate = SalaryUtil.getSalaryDate()
.plusDays(7);
return salaryRepository.findAllBySalaryDate(salaryDate);
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ public void sendSlackSalaryError(Long seniorId, Throwable ex) {
}
}

public void sendSlackSalaryError() {
try {
slackClient.send(logWebHookUrl, Payload.builder()
.text("정산 자동 생성 에러 발생!! 백엔드팀 확인 요망!!")
.attachments(
List.of(generateSalaryErrorSlackAttachment())
)
.build());
} catch (IOException e) {
log.error("slack 전송 오류");
}
}

public void sendSlackBizppurioError(String phoneNumber) {
try {
slackClient.send(logWebHookUrl, Payload.builder()
Expand Down Expand Up @@ -99,6 +112,18 @@ private Attachment generateSalaryErrorSlackAttachment(Long seniorId, Throwable e
))
.build();
}

private Attachment generateSalaryErrorSlackAttachment() {
String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now());
return Attachment.builder()
.color("ff0000")
.title(requestTime + "에 발생한 에러 로그")
.fields(List.of(
generateSlackField("정산 자동 생성 실패")
))
.build();
}

private Attachment generateBizppurioErrorSlackAttachment(String phoneNumber) {
String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now());
return Attachment.builder()
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/postgraduate/global/slack/SlackUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ public static Field generateSlackField(String title, String value) {
.valueShortEnough(false)
.build();
}

public static Field generateSlackField(String title) {
return Field.builder()
.title(title)
.valueShortEnough(false)
.build();
}
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/adminPayment.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<td><button th:paymentId="${paymentInfo.paymentId()}"
th:onclick="goToPost('정말 환불하겠습니까??', '/adminServer/payment/refund/' + this.getAttribute('paymentId'))">
환불/취소</button></td>
<td th:text="${paymentInfo.mentoringStatus()}">mentoringStatus</td>
<td th:text="${paymentInfo.status()}">mentoringStatus</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 3f15399

Please sign in to comment.