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