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

RAC-401 feat : 기존 배치 리스너 추가 및 수동 실행 추가 #290

Merged
merged 3 commits into from
Jun 20, 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
@@ -0,0 +1,37 @@
package com.postgraduate.admin.application.usecase;

import com.postgraduate.batch.scheduler.JobSchedulerConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class AdminBatchUseCase {
private final JobSchedulerConfig jobSchedulerConfig;

public void startSalaryBatch() {
try {
jobSchedulerConfig.launchSalaryJob();
} catch (Exception e) {
log.error("Create Salary Batch Exception : {}", e.getStackTrace());
}
}

public void startMentoringDoneBatch() {
try {
jobSchedulerConfig.launchDoneJob();
} catch (Exception e) {
log.error("Create Salary Batch Exception : {}", e.getStackTrace());
}
}

public void startMentoringCancelBatch() {
try {
jobSchedulerConfig.launchCancelJob();
} catch (Exception e) {
log.error("Create Salary Batch Exception : {}", e.getStackTrace());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AdminWithThymeLeafController {
private final AdminMentoringUseCase adminMentoringUseCase;
private final AdminSalaryUseCase adminSalaryUseCase;
private final AdminPaymentUseCase adminPaymentUseCase;
private final AdminBatchUseCase adminBatchUseCase;
private final JwtUseCase jwtUseCase;

@GetMapping("/loginForm")
Expand Down Expand Up @@ -166,4 +167,27 @@ public String sendMessage(@RequestBody SendMessageRequest messageRequest) {
adminUserUseCase.sendMatchingMessage(messageRequest);
return "adminEmpty";
}

@GetMapping("/batch")
public String batchManage() {
return "adminBatch";
}

@PostMapping("/batch/salary")
public String startSalaryBatch() {
adminBatchUseCase.startSalaryBatch();
return "adminEmpty";
}

@PostMapping("/batch/mentoring/done")
public String startMentoringDone() {
adminBatchUseCase.startMentoringDoneBatch();
return "adminEmpty";
}

@PostMapping("/batch/mentoring/cancel")
public String startMentoringCancel() {
adminBatchUseCase.startMentoringCancelBatch();
return "adminEmpty";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CancelJobConfig {
private final CancelMentoringProcessor cancelMentoringProcessor;
private final CancelMentoringWriter cancelMentoringWriter;
private final EntityManagerFactory entityManagerFactory;
private final CancelMentoringSkipListener cancelMentoringSkipListener;

private static final int CHUNK_SIZE = 50;

Expand All @@ -54,6 +55,7 @@ public Step cancelStep() {
.faultTolerant()
.skip(Exception.class)
.skipLimit(Integer.MAX_VALUE)
.listener(cancelMentoringSkipListener)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.postgraduate.batch.cancel;

import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.global.slack.SlackErrorMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.SkipListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class CancelMentoringSkipListener implements SkipListener<Mentoring, CancelMentoring> {
private final SlackErrorMessage slackErrorMessage;

@Override
public void onSkipInRead(Throwable t) {
log.error("멘토링 자동 완료 ItemReader Skip message : {}", t.getMessage());
}

@Override
public void onSkipInProcess(Mentoring mentoring, Throwable t) {
log.error("mentoringId : {} 자동 취소 실패, message : {}", mentoring.getMentoringId(), t.getMessage());
slackErrorMessage.sendSlackMentoringError(mentoring.getMentoringId(), t);
}

@Override
public void onSkipInWrite(CancelMentoring cancelMentoring, Throwable t) {
log.error("mentoringId : {} 자동 취소 실패, message : {}", cancelMentoring.mentoringId(), t.getMessage());
slackErrorMessage.sendSlackMentoringError(cancelMentoring.mentoringId(), t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ public Step createSalaryStep() {
.skip(Exception.class)
.skipLimit(Integer.MAX_VALUE)
.listener(createSalarySkipListener)
.listener(new CreateSalaryStepListener())
.build();
}

@Bean
public QueryDslZeroPagingItemReader<CreateSalary> salaryReader() {
LocalDate date = getSalaryDate().plusDays(7);
log.info("not in date : {}", date);
return new QueryDslZeroPagingItemReader<>(entityManagerFactory, CHUNK_SIZE, queryFactory ->
queryFactory.select(Projections.constructor(CreateSalary.class,
senior.seniorId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.postgraduate.batch.salary;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.*;

@Slf4j
public class CreateSalaryStepListener implements StepExecutionListener {
@Override
public void beforeStep(StepExecution stepExecution) {
log.info("createSalaryStep Start");
}

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
log.info("salary total read : {} and total write : {}", stepExecution.getReadCount(), stepExecution.getWriteCount());
return stepExecution.getExitStatus();
}
}
42 changes: 42 additions & 0 deletions src/main/resources/templates/adminBatch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<link th:href="@{/css/bootstrap.min.css}" href="css/bootstrap.min.css" rel="stylesheet">
<style>
.outer {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
padding-top: 30px;
}

.inner {
text-align: center;
}

label, input {
display: block;
margin: 0 auto 10px;
}

input {
margin-top: 10px;
}
</style>
</head>
<body>
<div class="outer">
<div class="inner">
<label><h1>정산 자동 생성 배치 재시도</h1></label>
<button th:onclick="goToPost('정산 자동 생성 배치를 재시도 하시겠습니까?', '/adminServer/batch/salary')"><h3>정산 자동 생성</h3></button>
<label><h1>멘토링 자동 완료 배치 재시도</h1></label>
<button th:onclick="goToPost('정산 자동 생성 배치를 재시도 하시겠습니까?', '/adminServer/batch/mentoring/done')"><h3>멘토링 자동 완료</h3></button>
<label><h1>멘토링 자동 취소 배치 재시도</h1></label>
<button th:onclick="goToPost('정산 자동 생성 배치를 재시도 하시겠습니까?', '/adminServer/batch/mentoring/cancel')"><h3>멘토링 자동 취소</h3></button>
</div>
</div>
</body>
</html>
8 changes: 8 additions & 0 deletions src/main/resources/templates/adminMain.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@
type="button">알림톡 전송</button>
</div>
</div>

<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg"
onclick="goToGet('/adminServer/batch')"
type="button">배치 재시도 -주의- 개발팀 담당</button>
</div>
</div>
</div>
<div id="output" class="center">
<!-- 서버에서 받은 데이터가 여기에 표시됩니다. -->
Expand Down
Loading