任务支持更换绑定执行器,方便任务分组转移和管理;

pull/8/MERGE
xuxueli 6 years ago
parent 9cf966c402
commit 32a843534c

@ -1423,7 +1423,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 9、任务暂停、删除优化避免quartz delete不完整导致任务脏数据
- 10、任务回调、心跳注册成功日志优化非核心常规日志调整为debug级别降低冗余日志输出
- 11、执行器回调日志落盘方案复用RPC序列化方案并移除Jackson依赖
- [迭代中]任务支持更换绑定执行器
- 12、任务支持更换绑定执行器方便任务分组转移和管理
- [迭代中]注册中心优化实时性注册发现心跳注册间隔10srefresh失败则首次注册并立即更新注册信息心跳类似30s过期销毁
- [迭代中]脚本任务,支持数据参数,新版本仅支持单参数不支持需要兼容;
- [迭代中]提供执行器Docker镜像

@ -164,11 +164,10 @@ public final class XxlJobDynamicScheduler {
*/
public static void fillJobInfo(XxlJobInfo jobInfo) {
String group = String.valueOf(jobInfo.getJobGroup());
String name = String.valueOf(jobInfo.getId());
// trigger key
TriggerKey triggerKey = TriggerKey.triggerKey(name, group);
TriggerKey triggerKey = TriggerKey.triggerKey(name);
try {
// trigger cron
@ -198,15 +197,14 @@ public final class XxlJobDynamicScheduler {
* add trigger + job
*
* @param jobName
* @param jobGroup
* @param cronExpression
* @return
* @throws SchedulerException
*/
public static boolean addJob(String jobName, String jobGroup, String cronExpression) throws SchedulerException {
public static boolean addJob(String jobName, String cronExpression) throws SchedulerException {
// 1、job key
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
JobKey jobKey = new JobKey(jobName, jobGroup);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
JobKey jobKey = new JobKey(jobName);
// 2、valid
if (scheduler.checkExists(triggerKey)) {
@ -239,16 +237,15 @@ public final class XxlJobDynamicScheduler {
* remove trigger + job
*
* @param jobName
* @param jobGroup
* @return
* @throws SchedulerException
*/
public static boolean removeJob(String jobName, String jobGroup) throws SchedulerException {
public static boolean removeJob(String jobName) throws SchedulerException {
JobKey jobKey = new JobKey(jobName, jobGroup);
JobKey jobKey = new JobKey(jobName);
scheduler.deleteJob(jobKey);
/*TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
/*TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
if (scheduler.checkExists(triggerKey)) {
scheduler.unscheduleJob(triggerKey); // trigger + job
}*/
@ -261,16 +258,15 @@ public final class XxlJobDynamicScheduler {
/**
* updateJobCron
*
* @param jobGroup
* @param jobName
* @param cronExpression
* @return
* @throws SchedulerException
*/
public static boolean updateJobCron(String jobGroup, String jobName, String cronExpression) throws SchedulerException {
public static boolean updateJobCron(String jobName, String cronExpression) throws SchedulerException {
// 1、job key
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
// 2、valid
if (!scheduler.checkExists(triggerKey)) {
@ -293,7 +289,7 @@ public final class XxlJobDynamicScheduler {
scheduler.rescheduleJob(triggerKey, oldTrigger);
/*
JobKey jobKey = new JobKey(jobName, jobGroup);
JobKey jobKey = new JobKey(jobName);
// old job detail
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
@ -304,7 +300,7 @@ public final class XxlJobDynamicScheduler {
// cover trigger of job detail
scheduler.scheduleJob(jobDetail, triggerSet, true);*/
logger.info(">>>>>>>>>>> resumeJob success, JobGroup:{}, JobName:{}", jobGroup, jobName);
logger.info(">>>>>>>>>>> resumeJob success, JobName:{}", jobName);
return true;
}
@ -313,13 +309,12 @@ public final class XxlJobDynamicScheduler {
* pause
*
* @param jobName
* @param jobGroup
* @return
* @throws SchedulerException
*/
/*public static boolean pauseJob(String jobName, String jobGroup) throws SchedulerException {
/*public static boolean pauseJob(String jobName) throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
boolean result = false;
if (scheduler.checkExists(triggerKey)) {
@ -336,13 +331,12 @@ public final class XxlJobDynamicScheduler {
* resume
*
* @param jobName
* @param jobGroup
* @return
* @throws SchedulerException
*/
/*public static boolean resumeJob(String jobName, String jobGroup) throws SchedulerException {
/*public static boolean resumeJob(String jobName) throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
boolean result = false;
if (scheduler.checkExists(triggerKey)) {
@ -359,14 +353,13 @@ public final class XxlJobDynamicScheduler {
* run
*
* @param jobName
* @param jobGroup
* @return
* @throws SchedulerException
*/
/*public static boolean triggerJob(String jobName, String jobGroup) throws SchedulerException {
/*public static boolean triggerJob(String jobName) throws SchedulerException {
// TriggerKey : name + group
JobKey jobKey = new JobKey(jobName, jobGroup);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
JobKey jobKey = new JobKey(jobName);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
boolean result = false;
if (scheduler.checkExists(triggerKey)) {

@ -14,7 +14,8 @@ import java.util.Map;
*/
@Mapper
public interface XxlJobLogDao {
// exist jobId not use jobGroup, not exist use jobGroup
public List<XxlJobLog> pageList(@Param("offset") int offset,
@Param("pagesize") int pagesize,
@Param("jobGroup") int jobGroup,

@ -164,13 +164,19 @@ public class XxlJobServiceImpl implements XxlJobService {
jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
}
// group valid
XxlJobGroup jobGroup = xxlJobGroupDao.load(jobInfo.getJobGroup());
if (jobGroup == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_jobgroup")+I18nUtil.getString("system_unvalid")) );
}
// stage job info
XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
if (exists_jobInfo == null) {
return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
}
//String old_cron = exists_jobInfo.getJobCron();
exists_jobInfo.setJobGroup(jobInfo.getJobGroup());
exists_jobInfo.setJobCron(jobInfo.getJobCron());
exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
exists_jobInfo.setAuthor(jobInfo.getAuthor());
@ -186,10 +192,9 @@ public class XxlJobServiceImpl implements XxlJobService {
// update quartz-cron if started
String qz_group = String.valueOf(exists_jobInfo.getJobGroup());
String qz_name = String.valueOf(exists_jobInfo.getId());
try {
XxlJobDynamicScheduler.updateJobCron(qz_group, qz_name, exists_jobInfo.getJobCron());
String qz_name = String.valueOf(exists_jobInfo.getId());
XxlJobDynamicScheduler.updateJobCron(qz_name, exists_jobInfo.getJobCron());
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
return ReturnT.FAIL;
@ -201,12 +206,14 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
public ReturnT<String> remove(int id) {
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
String group = String.valueOf(xxlJobInfo.getJobGroup());
String name = String.valueOf(xxlJobInfo.getId());
if (xxlJobInfo == null) {
return ReturnT.SUCCESS;
}
String name = String.valueOf(xxlJobInfo.getId());
try {
// unbind quartz
XxlJobDynamicScheduler.removeJob(name, group);
XxlJobDynamicScheduler.removeJob(name);
xxlJobInfoDao.delete(id);
xxlJobLogDao.delete(id);
@ -222,12 +229,11 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
public ReturnT<String> start(int id) {
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
String group = String.valueOf(xxlJobInfo.getJobGroup());
String name = String.valueOf(xxlJobInfo.getId());
String cronExpression = xxlJobInfo.getJobCron();
try {
boolean ret = XxlJobDynamicScheduler.addJob(name, group, cronExpression);
boolean ret = XxlJobDynamicScheduler.addJob(name, cronExpression);
return ret?ReturnT.SUCCESS:ReturnT.FAIL;
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);
@ -238,12 +244,11 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
public ReturnT<String> stop(int id) {
XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
String group = String.valueOf(xxlJobInfo.getJobGroup());
String name = String.valueOf(xxlJobInfo.getId());
try {
// bind quartz
boolean ret = XxlJobDynamicScheduler.removeJob(name, group);
boolean ret = XxlJobDynamicScheduler.removeJob(name);
return ret?ReturnT.SUCCESS:ReturnT.FAIL;
} catch (SchedulerException e) {
logger.error(e.getMessage(), e);

@ -142,6 +142,7 @@
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE XXL_JOB_QRTZ_TRIGGER_INFO
SET
job_group = #{jobGroup},
job_cron = #{jobCron},
job_desc = #{jobDesc},
update_time = NOW(),

@ -48,7 +48,7 @@
SELECT <include refid="Base_Column_List" />
FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
@ -82,7 +82,7 @@
SELECT count(1)
FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobGroup gt 0">
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">

@ -301,7 +301,7 @@ exit 0
<div class="form-group">
<label for="firstname" class="col-sm-2 control-label">${I18n.jobinfo_field_jobgroup}<font color="red">*</font></label>
<div class="col-sm-4">
<select class="form-control" name="jobGroup" disabled >
<select class="form-control" name="jobGroup" >
<#list JobGroupList as group>
<option value="${group.id}" >${group.title}</option>
</#list>

Loading…
Cancel
Save