mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: copy job API
This commit is contained in:
parent
aee69a4167
commit
0c424b52df
@ -19,6 +19,7 @@ public class OpenAPIConstant {
|
||||
/* ************* JOB 区 ************* */
|
||||
|
||||
public static final String SAVE_JOB = "/saveJob";
|
||||
public static final String COPY_JOB = "/copyJob";
|
||||
public static final String FETCH_JOB = "/fetchJob";
|
||||
public static final String FETCH_ALL_JOB = "/fetchAllJob";
|
||||
public static final String QUERY_JOB = "/queryJob";
|
||||
|
@ -57,7 +57,7 @@ public class JobService {
|
||||
*
|
||||
* @param request 任务请求
|
||||
* @return 创建的任务ID(jobId)
|
||||
* @throws ParseException 异常
|
||||
* @exception ParseException 异常
|
||||
*/
|
||||
public Long saveJob(SaveJobInfoRequest request) throws ParseException {
|
||||
|
||||
@ -96,6 +96,31 @@ public class JobService {
|
||||
return res.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制任务
|
||||
* @param jobId 目标任务ID
|
||||
* @return 复制后的任务 ID
|
||||
*/
|
||||
public JobInfoDO copyJob(Long jobId) {
|
||||
|
||||
JobInfoDO origin = jobInfoRepository.findById(jobId).orElseThrow(() -> new IllegalArgumentException("can't find job by jobId: " + jobId));
|
||||
JobInfoDO copyJob = new JobInfoDO();
|
||||
// 值拷贝
|
||||
BeanUtils.copyProperties(origin, copyJob);
|
||||
// 填充默认值,理论上应该不需要
|
||||
fillDefaultValue(copyJob);
|
||||
// 修正创建时间以及更新时间
|
||||
copyJob.setId(null);
|
||||
copyJob.setJobName(copyJob.getJobName()+"_COPY");
|
||||
copyJob.setGmtCreate(new Date());
|
||||
copyJob.setGmtModified(new Date());
|
||||
|
||||
copyJob = jobInfoRepository.saveAndFlush(copyJob);
|
||||
return copyJob;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public JobInfoDTO fetchJob(Long jobId) {
|
||||
return convert(jobInfoRepository.findById(jobId).orElseThrow(() -> new IllegalArgumentException("can't find job by jobId: " + jobId)));
|
||||
}
|
||||
@ -156,7 +181,7 @@ public class JobService {
|
||||
* 启用某个任务
|
||||
*
|
||||
* @param jobId 任务ID
|
||||
* @throws ParseException 异常(CRON表达式错误)
|
||||
* @exception ParseException 异常(CRON表达式错误)
|
||||
*/
|
||||
public void enableJob(Long jobId) throws ParseException {
|
||||
JobInfoDO jobInfoDO = jobInfoRepository.findById(jobId).orElseThrow(() -> new IllegalArgumentException("can't find job by jobId:" + jobId));
|
||||
@ -197,7 +222,7 @@ public class JobService {
|
||||
executeLogs.forEach(instance -> {
|
||||
try {
|
||||
// 重复查询了数据库,不过问题不大,这个调用量很小
|
||||
instanceService.stopInstance(instance.getAppId(),instance.getInstanceId());
|
||||
instanceService.stopInstance(instance.getAppId(), instance.getInstanceId());
|
||||
} catch (Exception ignore) {
|
||||
// ignore exception
|
||||
}
|
||||
|
@ -44,8 +44,14 @@ public class JobController {
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
@PostMapping("/copy")
|
||||
public ResultDTO<JobInfoVO> copyJob(String jobId) {
|
||||
return ResultDTO.success(JobInfoVO.from(jobService.copyJob(Long.valueOf(jobId))));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/disable")
|
||||
public ResultDTO<Void> disableJob(String jobId) throws Exception {
|
||||
public ResultDTO<Void> disableJob(String jobId) {
|
||||
jobService.disableJob(Long.valueOf(jobId));
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
@ -86,7 +92,7 @@ public class JobController {
|
||||
result.setTotalItems(1);
|
||||
result.setTotalPages(1);
|
||||
result.setData(Lists.newArrayList(JobInfoVO.from(jobInfoOpt.get())));
|
||||
}else {
|
||||
} else {
|
||||
result.setTotalPages(0);
|
||||
result.setTotalItems(0);
|
||||
result.setData(Lists.newLinkedList());
|
||||
|
@ -17,6 +17,7 @@ import com.github.kfcfans.powerjob.common.response.*;
|
||||
import com.github.kfcfans.powerjob.common.request.http.AddWorkflowNodeRequest;
|
||||
import com.github.kfcfans.powerjob.common.request.http.ModifyWorkflowNodeRequest;
|
||||
import com.github.kfcfans.powerjob.common.request.http.SaveWorkflowDAGRequest;
|
||||
import com.github.kfcfans.powerjob.server.web.response.JobInfoVO;
|
||||
import com.github.kfcfans.powerjob.server.web.response.WorkflowInfoVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -64,6 +65,11 @@ public class OpenAPIController {
|
||||
return ResultDTO.success(jobService.saveJob(request));
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.COPY_JOB)
|
||||
public ResultDTO<JobInfoVO> copyJob(Long jobId) {
|
||||
return ResultDTO.success(JobInfoVO.from(jobService.copyJob(jobId)));
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.FETCH_JOB)
|
||||
public ResultDTO<JobInfoDTO> fetchJob(Long jobId, Long appId) {
|
||||
checkJobIdValid(jobId, appId);
|
||||
@ -86,12 +92,14 @@ public class OpenAPIController {
|
||||
jobService.deleteJob(jobId);
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.DISABLE_JOB)
|
||||
public ResultDTO<Void> disableJob(Long jobId, Long appId) {
|
||||
checkJobIdValid(jobId, appId);
|
||||
jobService.disableJob(jobId);
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.ENABLE_JOB)
|
||||
public ResultDTO<Void> enableJob(Long jobId, Long appId) throws ParseException {
|
||||
checkJobIdValid(jobId, appId);
|
||||
@ -110,7 +118,7 @@ public class OpenAPIController {
|
||||
@PostMapping(OpenAPIConstant.STOP_INSTANCE)
|
||||
public ResultDTO<Void> stopInstance(Long instanceId, Long appId) {
|
||||
checkInstanceIdValid(instanceId, appId);
|
||||
instanceService.stopInstance(appId,instanceId);
|
||||
instanceService.stopInstance(appId, instanceId);
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
@ -153,7 +161,7 @@ public class OpenAPIController {
|
||||
|
||||
@PostMapping(OpenAPIConstant.COPY_WORKFLOW)
|
||||
public ResultDTO<Long> copy(Long workflowId, Long appId) {
|
||||
return ResultDTO.success(workflowService.copyWorkflow(workflowId,appId));
|
||||
return ResultDTO.success(workflowService.copyWorkflow(workflowId, appId));
|
||||
}
|
||||
|
||||
|
||||
@ -167,11 +175,13 @@ public class OpenAPIController {
|
||||
workflowService.deleteWorkflow(workflowId, appId);
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.DISABLE_WORKFLOW)
|
||||
public ResultDTO<Void> disableWorkflow(Long workflowId, Long appId) {
|
||||
workflowService.disableWorkflow(workflowId, appId);
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.ENABLE_WORKFLOW)
|
||||
public ResultDTO<Void> enableWorkflow(Long workflowId, Long appId) {
|
||||
workflowService.enableWorkflow(workflowId, appId);
|
||||
@ -215,8 +225,8 @@ public class OpenAPIController {
|
||||
}
|
||||
|
||||
@PostMapping(OpenAPIConstant.MARK_WORKFLOW_NODE_AS_SUCCESS)
|
||||
public ResultDTO<Void> markWorkflowNodeAsSuccess(Long wfInstanceId,Long nodeId, Long appId) {
|
||||
workflowInstanceService.markNodeAsSuccess(appId,wfInstanceId,nodeId);
|
||||
public ResultDTO<Void> markWorkflowNodeAsSuccess(Long wfInstanceId, Long nodeId, Long appId) {
|
||||
workflowInstanceService.markNodeAsSuccess(appId, wfInstanceId, nodeId);
|
||||
return ResultDTO.success(null);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user