Merge pull request 'job 로그 추가(에러확인)' (#376) from dev into prd-deploy
Reviewed-on: #376
This commit is contained in:
commit
5d36080327
@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -74,6 +75,7 @@ public class JobLauncherController {
|
|||||||
JobParametersInvalidException, JobRestartException {
|
JobParametersInvalidException, JobRestartException {
|
||||||
|
|
||||||
|
|
||||||
|
log.info("Manual launch requested for job: {}", jobName);
|
||||||
Job job = jobs.get(jobName);
|
Job job = jobs.get(jobName);
|
||||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||||
if (job == null) {
|
if (job == null) {
|
||||||
@ -98,6 +100,7 @@ public class JobLauncherController {
|
|||||||
.addDate("time", new Date()).toJobParameters();
|
.addDate("time", new Date()).toJobParameters();
|
||||||
|
|
||||||
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
|
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
|
||||||
|
log.info("Job {} started with execution id {}", jobName, jobExecution.getId());
|
||||||
|
|
||||||
BatchStatus status = jobExecution.getStatus();
|
BatchStatus status = jobExecution.getStatus();
|
||||||
ExitStatus exitStatus = jobExecution.getExitStatus();
|
ExitStatus exitStatus = jobExecution.getExitStatus();
|
||||||
@ -108,6 +111,7 @@ public class JobLauncherController {
|
|||||||
// return "Job " + jobName + " started";
|
// return "Job " + jobName + " started";
|
||||||
return resultMap;
|
return resultMap;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
logExceptionDetails("Manual launch failed", jobName, e);
|
||||||
resultMap.put("code", "FAILED");
|
resultMap.put("code", "FAILED");
|
||||||
resultMap.put("message", e.getMessage());
|
resultMap.put("message", e.getMessage());
|
||||||
return resultMap;
|
return resultMap;
|
||||||
@ -302,12 +306,14 @@ public class JobLauncherController {
|
|||||||
|
|
||||||
log.info("Job {} 실행 시도 (재시도 {}/{})", jobName, retryCount + 1, maxRetries);
|
log.info("Job {} 실행 시도 (재시도 {}/{})", jobName, retryCount + 1, maxRetries);
|
||||||
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
|
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
|
||||||
|
log.info("Job {} started with execution id {}", jobName, jobExecution.getId());
|
||||||
|
|
||||||
log.info("Job {} 완료 상태: {}", jobName, jobExecution.getExitStatus().getExitCode());
|
log.info("Job {} 완료 상태: {}", jobName, jobExecution.getExitStatus().getExitCode());
|
||||||
return jobName + " executed successfully";
|
return jobName + " executed successfully";
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
retryCount++;
|
retryCount++;
|
||||||
|
logExceptionDetails("Scheduled launch failed", jobName, e);
|
||||||
|
|
||||||
// 데드락 오류인지 확인
|
// 데드락 오류인지 확인
|
||||||
boolean isDeadlock = e.getCause() != null &&
|
boolean isDeadlock = e.getCause() != null &&
|
||||||
@ -341,6 +347,7 @@ public class JobLauncherController {
|
|||||||
*/
|
*/
|
||||||
private boolean isJobRunning(String jobName) {
|
private boolean isJobRunning(String jobName) {
|
||||||
try {
|
try {
|
||||||
|
log.debug("Checking running executions for job: {}", jobName);
|
||||||
Set<JobExecution> runningExecutions = jobExplorer.findRunningJobExecutions(jobName);
|
Set<JobExecution> runningExecutions = jobExplorer.findRunningJobExecutions(jobName);
|
||||||
if (runningExecutions.isEmpty()) {
|
if (runningExecutions.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
@ -380,4 +387,18 @@ public class JobLauncherController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logExceptionDetails(String context, String jobName, Exception e) {
|
||||||
|
Throwable root = e;
|
||||||
|
while (root.getCause() != null) {
|
||||||
|
root = root.getCause();
|
||||||
|
}
|
||||||
|
if (root instanceof SQLException) {
|
||||||
|
SQLException sqlEx = (SQLException) root;
|
||||||
|
log.error("{} for job {}: SQLState={}, errorCode={}, message={}",
|
||||||
|
context, jobName, sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), e);
|
||||||
|
} else {
|
||||||
|
log.error("{} for job {}: {}", context, jobName, root.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user