补充更新功能
This commit is contained in:
parent
503c401e09
commit
72599676e1
@ -1,10 +1,8 @@
|
||||
package com.example.snailjob.controller;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobResponseVO;
|
||||
import com.example.snailjob.handler.TestAddJobHandler;
|
||||
import com.example.snailjob.handler.TestQueryJobHandler;
|
||||
import com.example.snailjob.handler.TestTriggerJobHandler;
|
||||
import com.example.snailjob.handler.TestUpdateJobStatusHandler;
|
||||
import com.example.snailjob.handler.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -20,47 +18,113 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequiredArgsConstructor
|
||||
public class JobController {
|
||||
private final TestAddJobHandler testAddJobHandler;
|
||||
private final TestUpdateJobHandler testUpdateJobHandler;
|
||||
private final TestQueryJobHandler testQueryJobHandler;
|
||||
private final TestTriggerJobHandler testTriggerJobHandler;
|
||||
private final TestUpdateJobStatusHandler testUpdateJobStatusHandler;
|
||||
|
||||
@Operation(
|
||||
description = "添加集群模式的定时任务"
|
||||
)
|
||||
@PostMapping("/custer/add")
|
||||
public Long addClusterJob(@RequestBody String jobName) {
|
||||
return testAddJobHandler.addClusterJob(jobName);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "添加广播模式的定时任务"
|
||||
)
|
||||
@PostMapping("/broadcast/add")
|
||||
public Long addBroadcastJob(@RequestBody String jobName) {
|
||||
return testAddJobHandler.addBroadcastJob(jobName);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "添加静态分片模式的定时任务"
|
||||
)
|
||||
@PostMapping("/sharding/add")
|
||||
public Long addShardingJob(@RequestBody String jobName) {
|
||||
return testAddJobHandler.addShardingJob(jobName);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "添加Map模式的定时任务"
|
||||
)
|
||||
@PostMapping("/map/add")
|
||||
public Long addMapJob(@RequestBody String jobName) {
|
||||
return testAddJobHandler.addMapJob(jobName);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "添加MapReduce模式的定时任务"
|
||||
)
|
||||
@PostMapping("/map-reduce/add")
|
||||
public Long addMapReduceJob(@RequestBody String jobName) {
|
||||
return testAddJobHandler.addMapReduceJob(jobName);
|
||||
}
|
||||
|
||||
@GetMapping("/detail/id")
|
||||
public JobResponseVO addMapReduceJob(@RequestParam("id") Long id) {
|
||||
@Operation(
|
||||
description = "更新集群模式的定时任务"
|
||||
)
|
||||
@PutMapping("/custer/update")
|
||||
public Boolean updateClusterJob(@RequestBody Long id) {
|
||||
return testUpdateJobHandler.updateClusterJob(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "更新广播模式的定时任务"
|
||||
)
|
||||
@PutMapping("/broadcast/update")
|
||||
public Boolean updateBroadcastJob(@RequestBody Long id) {
|
||||
return testUpdateJobHandler.updateBroadcastJob(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "更新静态分片模式的定时任务"
|
||||
)
|
||||
@PutMapping("/sharding/update")
|
||||
public Boolean addShardingJob(@RequestBody Long id) {
|
||||
return testUpdateJobHandler.updateShardingJob(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "更新Map模式的定时任务"
|
||||
)
|
||||
@PutMapping("/map/update")
|
||||
public Boolean updateMapJob(@RequestBody Long id) {
|
||||
return testUpdateJobHandler.updateMapJob(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "更新MapReduce模式的定时任务"
|
||||
)
|
||||
@PutMapping("/map-reduce/update")
|
||||
public Boolean updateMapReduceJob(@RequestBody Long id) {
|
||||
return testUpdateJobHandler.updateMapReduceJob(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "通过任务id查询任务的详情"
|
||||
)
|
||||
@GetMapping("/detail/{id}")
|
||||
public JobResponseVO addMapReduceJob(@PathVariable("id") Long id) {
|
||||
return testQueryJobHandler.queryJob(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "手动触发任务"
|
||||
)
|
||||
@PostMapping("/trigger/{id}")
|
||||
public Boolean triggerJob(@PathVariable("id") Long id) {
|
||||
return testTriggerJobHandler.triggerJob(id);
|
||||
}
|
||||
|
||||
@PutMapping("/update/status/{id}")
|
||||
public Boolean updateJob(@PathVariable("id") Long id) {
|
||||
return testUpdateJobStatusHandler.updateJobStatus(id);
|
||||
@Operation(
|
||||
description = "根据id更新任务的状态",
|
||||
summary = "0:关闭 1:开启"
|
||||
)
|
||||
@PutMapping("/update/status/{id}/{status}")
|
||||
public Boolean updateJob(@PathVariable("id") Long id, @PathVariable("status") Long status) {
|
||||
return testUpdateJobStatusHandler.updateJobStatus(id, status);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.example.snailjob.controller;
|
||||
|
||||
import com.example.snailjob.handler.TestTriggerJobHandler;
|
||||
import com.example.snailjob.handler.TestUpdateJobStatusHandler;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-10-19 10:41:25
|
||||
* @since sj_1.2.0-beta2
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/open-api/workflow")
|
||||
@Tag(name = "JobOpenApi", description = "通过OpenApi可以灵活的实现对的Workflow触发和更新状态功能")
|
||||
@RequiredArgsConstructor
|
||||
public class WorkflowController {
|
||||
private final TestTriggerJobHandler testTriggerJobHandler;
|
||||
private final TestUpdateJobStatusHandler testUpdateJobStatusHandler;
|
||||
|
||||
@Operation(
|
||||
description = "手动触发任务"
|
||||
)
|
||||
@PostMapping("/trigger/{id}")
|
||||
public Boolean triggerJob(@PathVariable("id") Long id) {
|
||||
return testTriggerJobHandler.triggerWorkFlow(id);
|
||||
}
|
||||
|
||||
@Operation(
|
||||
description = "根据id更新任务的状态",
|
||||
summary = "0:关闭 1:开启"
|
||||
)
|
||||
@PutMapping("/update/status/{id}/{status}")
|
||||
public Boolean updateJob(@PathVariable("id") Long id, @PathVariable("status") Long status) {
|
||||
return testUpdateJobStatusHandler.updateWorkFlowStatus(id, status);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.example.snailjob.handler;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Component
|
||||
public class TestUpdateJobHandler {
|
||||
|
||||
/**
|
||||
* 新增集群模式的任务
|
||||
*
|
||||
* @return 任务id
|
||||
*/
|
||||
public Boolean updateClusterJob(Long jobId) {
|
||||
return SnailJobOpenApi.updateClusterJob(jobId)
|
||||
.setMaxRetryTimes(1)
|
||||
.setTriggerType(TriggerTypeEnum.SCHEDULED_TIME)
|
||||
.setTriggerInterval(String.valueOf(60))
|
||||
.addArgsStr("update测试数据", new Random().nextInt(1000))
|
||||
.addArgsStr("updateArg", "args")
|
||||
.setRetryInterval(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增集群模式的任务
|
||||
*
|
||||
* @return 任务id
|
||||
*/
|
||||
public Boolean updateBroadcastJob(Long jobId) {
|
||||
return SnailJobOpenApi.updateBroadcastJob(jobId)
|
||||
.addArgsStr("update测试数据", new Random().nextInt(1000))
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增Sharding模式的任务
|
||||
*
|
||||
* @return 任务id
|
||||
*/
|
||||
public Boolean updateShardingJob(Long jobId) {
|
||||
return SnailJobOpenApi.updateShardingJob(jobId)
|
||||
.addShardingArgs("update分片1", "update分片2", "update分片3")
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增MapReduce模式的任务
|
||||
*
|
||||
* @return 任务id
|
||||
*/
|
||||
public Boolean updateMapJob(Long jobId) {
|
||||
return SnailJobOpenApi.updateMapJob(jobId)
|
||||
.addArgsStr("update测试数据", new Random().nextInt(1000))
|
||||
.setParallelNum(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增MapReduce模式的任务
|
||||
*
|
||||
* @return 任务id
|
||||
*/
|
||||
public Boolean updateMapReduceJob(Long jobId) {
|
||||
return SnailJobOpenApi.updateMapReduceJob(jobId)
|
||||
.addArgsStr("update测试数据", new Random().nextInt(1000))
|
||||
.execute();
|
||||
|
||||
}
|
||||
}
|
@ -13,10 +13,10 @@ public class TestUpdateJobStatusHandler {
|
||||
* @param jobId 定时任务ID
|
||||
* @return
|
||||
*/
|
||||
public Boolean updateJobStatus(Long jobId){
|
||||
public Boolean updateJobStatus(Long jobId, Long status) {
|
||||
return SnailJobOpenApi
|
||||
.updateJobStatus(jobId)
|
||||
.setStatus(StatusEnum.YES)
|
||||
.setStatus(StatusEnum.YES.getStatus().equals(status.intValue()) ? StatusEnum.YES : StatusEnum.NO)
|
||||
.execute();
|
||||
}
|
||||
|
||||
@ -24,12 +24,13 @@ public class TestUpdateJobStatusHandler {
|
||||
* 更新工作流任务状态
|
||||
*
|
||||
* @param workFlowId 工作流ID
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public Boolean updateWorkFlowStatus(Long workFlowId){
|
||||
public Boolean updateWorkFlowStatus(Long workFlowId, Long status) {
|
||||
return SnailJobOpenApi
|
||||
.updateWorkFlowStatus(workFlowId)
|
||||
.setStatus(StatusEnum.YES)
|
||||
.setStatus(StatusEnum.YES.getStatus().equals(status.intValue()) ? StatusEnum.YES : StatusEnum.NO)
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user