🚀 feat(新增): 暂停任务
This commit is contained in:
parent
29b396c245
commit
cd3157a751
|
@ -0,0 +1,19 @@
|
||||||
|
package cn.bunny.dto.quartz;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class QuartzAddDto {
|
||||||
|
private String jobName;// 任务名称
|
||||||
|
private String jobGroup;// 任务分组
|
||||||
|
private String cronExpression;// 执行时间
|
||||||
|
private String description;// 任务描述
|
||||||
|
private String jobMethodName;// 执行方法
|
||||||
|
private String jobClassName;// 执行类
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package cn.bunny.dto.quartz;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
public class QuartzPauseDto {
|
||||||
|
private String jobName;// 任务名称
|
||||||
|
private String jobGroup;// 任务分组
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/blobTriggers")
|
|
||||||
public class BlobTriggersController {
|
|
||||||
// qrtz_job_details
|
|
||||||
// qrtz_triggers
|
|
||||||
// qrtz_cron_triggers
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/calendars")
|
|
||||||
public class CalendarsController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/cronTriggers")
|
|
||||||
public class CronTriggersController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/firedTriggers")
|
|
||||||
public class FiredTriggersController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +1,13 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
package cn.bunny.service.controller.quartz;
|
||||||
|
|
||||||
import cn.bunny.dto.quartz.QuartzDto;
|
import cn.bunny.dto.quartz.QuartzAddDto;
|
||||||
|
import cn.bunny.dto.quartz.QuartzPauseDto;
|
||||||
import cn.bunny.pojo.result.Result;
|
import cn.bunny.pojo.result.Result;
|
||||||
import cn.bunny.service.service.quartz.JobService;
|
import cn.bunny.service.service.quartz.JobService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@Tag(name = "Quartz定时任务")
|
@Tag(name = "Quartz定时任务")
|
||||||
@RestController
|
@RestController
|
||||||
|
@ -21,8 +19,15 @@ public class JobController {
|
||||||
|
|
||||||
@Operation(summary = "添加任务", description = "添加任务")
|
@Operation(summary = "添加任务", description = "添加任务")
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
public Result<String> addJob(@RequestBody QuartzDto dto) {
|
public Result<String> addJob(@RequestBody QuartzAddDto dto) {
|
||||||
jobService.addJob(dto);
|
jobService.addJob(dto);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "暂停任务", description = "暂停任务")
|
||||||
|
@PutMapping("/pause")
|
||||||
|
public Result<String> pause(@RequestBody QuartzPauseDto dto) {
|
||||||
|
jobService.pause(dto);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/locks")
|
|
||||||
public class LocksController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/pausedTriggerGrps")
|
|
||||||
public class PausedTriggerGrpsController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/schedulerState")
|
|
||||||
public class SchedulerStateController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/simpleTriggers")
|
|
||||||
public class SimpleTriggersController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/simpropTriggers")
|
|
||||||
public class SimpropTriggersController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
package cn.bunny.service.controller.quartz;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* 前端控制器
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Bunny
|
|
||||||
* @since 2024-07-25
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/triggers")
|
|
||||||
public class TriggersController {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.bunny.service.service.quartz;
|
package cn.bunny.service.service.quartz;
|
||||||
|
|
||||||
import cn.bunny.dto.quartz.QuartzDto;
|
import cn.bunny.dto.quartz.QuartzAddDto;
|
||||||
|
import cn.bunny.dto.quartz.QuartzPauseDto;
|
||||||
import cn.bunny.entity.system.quartz.JobDetails;
|
import cn.bunny.entity.system.quartz.JobDetails;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
@ -11,5 +12,12 @@ public interface JobService extends IService<JobDetails> {
|
||||||
*
|
*
|
||||||
* @param dto 添加任务
|
* @param dto 添加任务
|
||||||
*/
|
*/
|
||||||
void addJob(QuartzDto dto);
|
void addJob(QuartzAddDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 暂停任务
|
||||||
|
*
|
||||||
|
* @param dto 暂停任务
|
||||||
|
*/
|
||||||
|
void pause(QuartzPauseDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cn.bunny.service.service.quartz.impl;
|
package cn.bunny.service.service.quartz.impl;
|
||||||
|
|
||||||
import cn.bunny.dto.quartz.QuartzDto;
|
import cn.bunny.dto.quartz.QuartzAddDto;
|
||||||
|
import cn.bunny.dto.quartz.QuartzPauseDto;
|
||||||
import cn.bunny.entity.system.quartz.JobDetails;
|
import cn.bunny.entity.system.quartz.JobDetails;
|
||||||
import cn.bunny.service.mapper.quartz.JobDetailsMapper;
|
import cn.bunny.service.mapper.quartz.JobDetailsMapper;
|
||||||
import cn.bunny.service.service.quartz.JobService;
|
import cn.bunny.service.service.quartz.JobService;
|
||||||
|
@ -28,7 +29,7 @@ public class JobServiceImpl extends ServiceImpl<JobDetailsMapper, JobDetails> im
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void addJob(QuartzDto dto) {
|
public void addJob(QuartzAddDto dto) {
|
||||||
String jobGroup = dto.getJobGroup();
|
String jobGroup = dto.getJobGroup();
|
||||||
String jobName = dto.getJobName();
|
String jobName = dto.getJobName();
|
||||||
String cronExpression = dto.getCronExpression();
|
String cronExpression = dto.getCronExpression();
|
||||||
|
@ -53,4 +54,16 @@ public class JobServiceImpl extends ServiceImpl<JobDetailsMapper, JobDetails> im
|
||||||
.startNow().withSchedule(cronScheduleBuilder).build();
|
.startNow().withSchedule(cronScheduleBuilder).build();
|
||||||
scheduler.scheduleJob(jobDetail, trigger);
|
scheduler.scheduleJob(jobDetail, trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 暂停任务
|
||||||
|
*
|
||||||
|
* @param dto 暂停任务
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public void pause(QuartzPauseDto dto) {
|
||||||
|
JobKey key = new JobKey(dto.getJobName(), dto.getJobGroup());
|
||||||
|
scheduler.pauseJob(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue