Skip to content

Commit

Permalink
1.xxl-job创建执行器(不再硬编码)
Browse files Browse the repository at this point in the history
2.修改表结构支持定时任务
  • Loading branch information
ZhongFuCheng3y committed Jan 29, 2022
1 parent ac6f1f1 commit 0d246e3
Show file tree
Hide file tree
Showing 13 changed files with 320 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class AustinConstant {
*/
public final static String YYYY_MM_DD = "yyyyMMdd";

/**
* cron时间格式
*/
public final static String CRON_FORMAT = "ss mm HH dd MM ? yyyy";


/**
* apollo默认的值
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class XxlJobConstant {

/**
* 接口路径
* 任务信息接口路径
*/
public static final String LOGIN_URL = "/login";
public static final String INSERT_URL = "/jobinfo/add";
Expand All @@ -19,9 +19,16 @@ public class XxlJobConstant {
public static final String STOP_URL = "/jobinfo/stop";

/**
* 执行器名称
* 执行器组接口路径
*/
public static final String HANDLER_NAME = "austinJobHandler";
public static final String JOB_GROUP_PAGE_LIST = "/jobgroup/pageList";
public static final String JOB_GROUP_INSERT_URL = "/jobgroup/save";


/**
* 执行任务名称
*/
public static final String JOB_HANDLER_NAME = "austinJob";

/**
* 超时时间
Expand All @@ -33,4 +40,9 @@ public class XxlJobConstant {
*/
public static final Integer RETRY_COUNT = 2;

/**
* 立即执行的任务 延迟时间(秒数)
*/
public static final Integer DELAY_TIME = 5;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.java3y.austin.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
* 执行器组信息
*
* @author 3y
*/
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class XxlJobGroup {

private int id;
private String appname;

private String title;
/**
* 执行器地址类型:0=自动注册、1=手动录入
*/
private int addressType;

/**
* 执行器地址列表,多地址逗号分隔(手动录入)
*/
private String addressList;
private Date updateTime;

/**
* registry list 执行器地址列表(系统注册)
*/
private List<String> registryList;

public List<String> getRegistryList() {
if (addressList != null && addressList.trim().length() > 0) {
registryList = new ArrayList<String>(Arrays.asList(addressList.split(",")));
}
return registryList;
}


}
108 changes: 87 additions & 21 deletions austin-cron/src/main/java/com/java3y/austin/entity/XxlJobInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,104 @@
@Builder
public class XxlJobInfo implements Serializable {

private Integer id; // 主键ID
/**
* 主键ID
*/
private Integer id;

private int jobGroup; // 执行器主键ID
/**
* 执行器主键ID
*/
private int jobGroup;
private String jobDesc;

private Date addTime;
private Date updateTime;

private String author; // 负责人
private String alarmEmail; // 报警邮件
/**
* 负责人
*/
private String author;

private String scheduleType; // 调度类型
private String scheduleConf; // 调度配置,值含义取决于调度类型
/**
* 报警邮件
*/
private String alarmEmail;

private String misfireStrategy; // 调度过期策略
/**
* 调度类型
*/
private String scheduleType;
/**
* 调度配置,值含义取决于调度类型
*/
private String scheduleConf;

private String executorRouteStrategy; // 执行器路由策略
private String executorHandler; // 执行器,任务Handler名称
private String executorParam; // 执行器,任务参数
private String executorBlockStrategy; // 阻塞处理策略
private int executorTimeout; // 任务执行超时时间,单位秒
private int executorFailRetryCount; // 失败重试次数
/**
* 调度过期策略
*/
private String misfireStrategy;

private String glueType; // GLUE类型 #com.xxl.job.core.glue.GlueTypeEnum
private String glueSource; // GLUE源代码
private String glueRemark; // GLUE备注
private Date glueUpdatetime; // GLUE更新时间
/**
* 执行器路由策略
*/
private String executorRouteStrategy;

private String childJobId; // 子任务ID,多个逗号分隔
/**
* 执行器,任务Handler名称
*/
private String executorHandler;
/**
* 执行器,任务参数
*/
private String executorParam;

private int triggerStatus; // 调度状态:0-停止,1-运行
private long triggerLastTime; // 上次调度时间
private long triggerNextTime; // 下次调度时间
/**
* 阻塞处理策略
*/
private String executorBlockStrategy;
/**
* 任务执行超时时间,单位秒
*/
private int executorTimeout;
/**
* 失败重试次数
*/
private int executorFailRetryCount;

/**
* GLUE类型 #com.xxl.job.core.glue.GlueTypeEnum
*/
private String glueType;
/**
* GLUE源代码
*/
private String glueSource;
/**
* GLUE备注
*/
private String glueRemark;
/**
* GLUE更新时间
*/
private Date glueUpdatetime;

/**
* 子任务ID,多个逗号分隔
*/
private String childJobId;

/**
* 调度状态:0-停止,1-运行
*/
private int triggerStatus;
/**
* 上次调度时间
*/
private long triggerLastTime;
/**
* 下次调度时间
*/
private long triggerNextTime;

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
package com.java3y.austin.handler;

import com.alibaba.fastjson.JSON;
import com.java3y.austin.domain.MessageTemplate;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
* 定时任务处理类
* @author 3y
*/
@Service
@Slf4j
public class CronTaskHandler {

/**
* 简单任务
* 处理所有的 austin 定时任务消息
*/
@XxlJob("austinJobHandler")
@XxlJob("austinJob")
public void execute() {
log.info("XXL-JOB, Hello World.");
MessageTemplate messageTemplate = JSON.parseObject(XxlJobHelper.getJobParam(), MessageTemplate.class);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.java3y.austin.service;

import com.java3y.austin.entity.XxlJobGroup;
import com.java3y.austin.entity.XxlJobInfo;
import com.java3y.austin.vo.BasicResultVO;

Expand Down Expand Up @@ -39,4 +40,16 @@ public interface CronTaskService {
BasicResultVO stopCronTask(Integer taskId);


/**
* 得到执行器Id
*
* @return
*/
BasicResultVO getGroupId(String appName, String title);

/**
* 创建执行器
*/
BasicResultVO createGroup(XxlJobGroup xxlJobGroup);

}
Loading

0 comments on commit 0d246e3

Please sign in to comment.