Merge branch 'refs/heads/1.2.0-beta2'
This commit is contained in:
commit
b76cf9efa0
6
pom.xml
6
pom.xml
@ -44,17 +44,17 @@
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>snail-job-client-starter</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.2.0-beta2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>snail-job-client-retry-core</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.2.0-beta2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aizuda</groupId>
|
||||
<artifactId>snail-job-client-job-core</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>1.2.0-beta2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.aviator</groupId>
|
||||
|
130
src/main/java/com/example/snailjob/controller/JobController.java
Normal file
130
src/main/java/com/example/snailjob/controller/JobController.java
Normal file
@ -0,0 +1,130 @@
|
||||
package com.example.snailjob.controller;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobResponseVO;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* @author opensnail
|
||||
* @date 2024-10-19 10:41:25
|
||||
* @since sj_1.2.0-beta2
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/open-api/job")
|
||||
@Tag(name = "JobOpenApi", description = "通过OpenApi可以灵活的实现对Job的增、改、查功能")
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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,126 @@
|
||||
package com.example.snailjob.handler;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
||||
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
|
||||
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
|
||||
import com.aizuda.snailjob.common.core.enums.BlockStrategyEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestAddJobHandler {
|
||||
|
||||
/**
|
||||
* 新增集群模式的任务
|
||||
*
|
||||
* @param jobName 任务名称
|
||||
* @return 任务id
|
||||
*/
|
||||
public Long addClusterJob(String jobName) {
|
||||
return SnailJobOpenApi.addClusterJob()
|
||||
.setRouteKey(AllocationAlgorithmEnum.RANDOM)
|
||||
.setJobName(jobName)
|
||||
.setExecutorInfo("testJobExecutor")
|
||||
.setExecutorTimeout(30)
|
||||
.setDescription("add")
|
||||
.setBlockStrategy(BlockStrategyEnum.DISCARD)
|
||||
.setMaxRetryTimes(1)
|
||||
.setTriggerType(TriggerTypeEnum.SCHEDULED_TIME)
|
||||
.setTriggerInterval(String.valueOf(60))
|
||||
.addArgsStr("测试数据", 123)
|
||||
.addArgsStr("addArg", "args")
|
||||
.setRetryInterval(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增集群模式的任务
|
||||
*
|
||||
* @param jobName 任务名称
|
||||
* @return 任务id
|
||||
*/
|
||||
public Long addBroadcastJob(String jobName) {
|
||||
return SnailJobOpenApi.addBroadcastJob()
|
||||
.setJobName(jobName)
|
||||
.setExecutorInfo("testJobExecutor")
|
||||
.setExecutorTimeout(30)
|
||||
.setDescription("add")
|
||||
.setBlockStrategy(BlockStrategyEnum.DISCARD)
|
||||
.setMaxRetryTimes(1)
|
||||
.setTriggerType(TriggerTypeEnum.CRON)
|
||||
.setTriggerInterval("afas")
|
||||
.addArgsStr("测试数据", 123)
|
||||
.addArgsStr("addArg", "args")
|
||||
.setRetryInterval(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增Sharding模式的任务
|
||||
*
|
||||
* @param jobName 任务名称
|
||||
* @return 任务id
|
||||
*/
|
||||
public Long addShardingJob(String jobName) {
|
||||
return SnailJobOpenApi.addShardingJob()
|
||||
.setJobName(jobName)
|
||||
.setExecutorInfo("testJobExecutor")
|
||||
.setExecutorTimeout(30)
|
||||
.setDescription("add")
|
||||
.setBlockStrategy(BlockStrategyEnum.DISCARD)
|
||||
.setMaxRetryTimes(1)
|
||||
.setTriggerType(TriggerTypeEnum.SCHEDULED_TIME)
|
||||
.setTriggerInterval(60)
|
||||
.addShardingArgs("分片1", "分片2", "分片3")
|
||||
.setParallelNum(1)
|
||||
.setRetryInterval(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增MapReduce模式的任务
|
||||
*
|
||||
* @param jobName 任务名称
|
||||
* @return 任务id
|
||||
*/
|
||||
public Long addMapJob(String jobName) {
|
||||
return SnailJobOpenApi.addMapJob()
|
||||
.setJobName(jobName)
|
||||
.setExecutorInfo("testJobExecutor")
|
||||
.setExecutorTimeout(30)
|
||||
.setDescription("add")
|
||||
.setBlockStrategy(BlockStrategyEnum.DISCARD)
|
||||
.setMaxRetryTimes(1)
|
||||
.setTriggerType(TriggerTypeEnum.SCHEDULED_TIME)
|
||||
.setTriggerInterval(String.valueOf(60))
|
||||
.setParallelNum(3)
|
||||
.setRetryInterval(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增MapReduce模式的任务
|
||||
*
|
||||
* @param jobName 任务名称
|
||||
* @return 任务id
|
||||
*/
|
||||
public Long addMapReduceJob(String jobName) {
|
||||
return SnailJobOpenApi.addMapReduceJob()
|
||||
.setJobName(jobName)
|
||||
.setExecutorInfo("testJobExecutor")
|
||||
.setExecutorTimeout(30)
|
||||
.setDescription("add")
|
||||
.setBlockStrategy(BlockStrategyEnum.DISCARD)
|
||||
.setMaxRetryTimes(1)
|
||||
.setTriggerType(TriggerTypeEnum.SCHEDULED_TIME)
|
||||
.setTriggerInterval(String.valueOf(60))
|
||||
.setParallelNum(3)
|
||||
.setShardNum(2)
|
||||
.setRetryInterval(3)
|
||||
.execute();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.example.snailjob.handler;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.dto.JobResponseVO;
|
||||
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestQueryJobHandler {
|
||||
|
||||
/**
|
||||
* 查看任务详情
|
||||
*
|
||||
* @param jobId
|
||||
* @return 任务详情
|
||||
*/
|
||||
public JobResponseVO queryJob(Long jobId){
|
||||
return SnailJobOpenApi.getJobDetail(jobId).execute();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.example.snailjob.handler;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestTriggerJobHandler {
|
||||
|
||||
/**
|
||||
* 手动调度任务
|
||||
*
|
||||
* @param jobId 任务ID
|
||||
* @return
|
||||
*/
|
||||
public Boolean triggerJob(Long jobId){
|
||||
return SnailJobOpenApi.triggerJob(jobId).execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动调度工作流任务
|
||||
*
|
||||
* @param workFlowId 工作流任务ID
|
||||
* @return
|
||||
*/
|
||||
public Boolean triggerWorkFlow(Long workFlowId){
|
||||
return SnailJobOpenApi.triggerWorkFlow(workFlowId).execute();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.example.snailjob.handler;
|
||||
|
||||
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
|
||||
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestUpdateJobStatusHandler {
|
||||
|
||||
/**
|
||||
* 更新定时任务状态
|
||||
*
|
||||
* @param jobId 定时任务ID
|
||||
* @return
|
||||
*/
|
||||
public Boolean updateJobStatus(Long jobId, Long status) {
|
||||
return SnailJobOpenApi
|
||||
.updateJobStatus(jobId)
|
||||
.setStatus(StatusEnum.YES.getStatus().equals(status.intValue()) ? StatusEnum.YES : StatusEnum.NO)
|
||||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新工作流任务状态
|
||||
*
|
||||
* @param workFlowId 工作流ID
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public Boolean updateWorkFlowStatus(Long workFlowId, Long status) {
|
||||
return SnailJobOpenApi
|
||||
.updateWorkFlowStatus(workFlowId)
|
||||
.setStatus(StatusEnum.YES.getStatus().equals(status.intValue()) ? StatusEnum.YES : StatusEnum.NO)
|
||||
.execute();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user