Batch 파라미터 request 적용
This commit is contained in:
부모
32af369f23
커밋
0a5e2e56af
@ -1,20 +1,26 @@
|
|||||||
package com.snp.batch.global.controller;
|
package com.snp.batch.global.controller;
|
||||||
|
|
||||||
import com.snp.batch.global.dto.JobExecutionDto;
|
import com.snp.batch.global.dto.JobExecutionDto;
|
||||||
|
import com.snp.batch.global.dto.JobLaunchRequest;
|
||||||
import com.snp.batch.global.dto.ScheduleRequest;
|
import com.snp.batch.global.dto.ScheduleRequest;
|
||||||
import com.snp.batch.global.dto.ScheduleResponse;
|
import com.snp.batch.global.dto.ScheduleResponse;
|
||||||
import com.snp.batch.service.BatchService;
|
import com.snp.batch.service.BatchService;
|
||||||
import com.snp.batch.service.ScheduleService;
|
import com.snp.batch.service.ScheduleService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.Explode;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||||
|
import io.swagger.v3.oas.annotations.enums.ParameterStyle;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springdoc.core.annotations.ParameterObject;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -56,6 +62,39 @@ public class BatchController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "배치 작업 실행", description = "지정된 배치 작업을 즉시 실행합니다. 쿼리 파라미터로 Job Parameters 전달 가능")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "작업 실행 성공"),
|
||||||
|
@ApiResponse(responseCode = "500", description = "작업 실행 실패")
|
||||||
|
})
|
||||||
|
@PostMapping("/jobs/{jobName}/executeJobTest")
|
||||||
|
public ResponseEntity<Map<String, Object>> executeJobTest(
|
||||||
|
@Parameter( description = "실행할 배치 작업 이름", required = true,example = "sampleProductImportJob")
|
||||||
|
@PathVariable String jobName,
|
||||||
|
@ParameterObject JobLaunchRequest request
|
||||||
|
) {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
if (request.getStartDate() != null) params.put("startDate", request.getStartDate());
|
||||||
|
if (request.getStopDate() != null) params.put("stopDate", request.getStopDate());
|
||||||
|
|
||||||
|
log.info("Executing job: {} with params: {}", jobName, params);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Long executionId = batchService.executeJob(jobName, params);
|
||||||
|
return ResponseEntity.ok(Map.of(
|
||||||
|
"success", true,
|
||||||
|
"message", "Job started successfully",
|
||||||
|
"executionId", executionId
|
||||||
|
));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error executing job: {}", jobName, e);
|
||||||
|
return ResponseEntity.internalServerError().body(Map.of(
|
||||||
|
"success", false,
|
||||||
|
"message", "Failed to start job: " + e.getMessage()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "배치 작업 목록 조회", description = "등록된 모든 배치 작업 목록을 조회합니다")
|
@Operation(summary = "배치 작업 목록 조회", description = "등록된 모든 배치 작업 목록을 조회합니다")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "조회 성공")
|
@ApiResponse(responseCode = "200", description = "조회 성공")
|
||||||
|
|||||||
16
src/main/java/com/snp/batch/global/dto/JobLaunchRequest.java
Normal file
16
src/main/java/com/snp/batch/global/dto/JobLaunchRequest.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.snp.batch.global.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class JobLaunchRequest {
|
||||||
|
@Schema(description = "조회 시작일 (ISO 8601)", example = "2023-12-01T00:00:00Z")
|
||||||
|
private String startDate;
|
||||||
|
|
||||||
|
@Schema(description = "조회 종료일 (ISO 8601)", example = "2023-12-02T00:00:00Z")
|
||||||
|
private String stopDate;
|
||||||
|
}
|
||||||
불러오는 중...
Reference in New Issue
Block a user