mirror of https://github.com/ZhongFuCheng3y/austin
parent
23bd6a235e
commit
428cbfd1cd
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>austin</artifactId>
|
||||||
|
<groupId>com.java3y.austin</groupId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>austin-cron</artifactId>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.java3y.austin</groupId>
|
||||||
|
<artifactId>austin-support</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.xuxueli</groupId>
|
||||||
|
<artifactId>xxl-job-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.java3y.austin.config;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobConfig {
|
||||||
|
|
||||||
|
@Value("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
@Value("${xxl.job.executor.appname}")
|
||||||
|
private String appName;
|
||||||
|
@Value("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
@Value("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
@Value("${xxl.job.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
@Value("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
@Value("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSpringExecutor xxlJobExecutor() {
|
||||||
|
// 创建 XxlJobSpringExecutor 执行器
|
||||||
|
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
|
||||||
|
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
|
||||||
|
xxlJobSpringExecutor.setAppname(appName);
|
||||||
|
xxlJobSpringExecutor.setIp(ip);
|
||||||
|
xxlJobSpringExecutor.setPort(port);
|
||||||
|
xxlJobSpringExecutor.setAccessToken(accessToken);
|
||||||
|
xxlJobSpringExecutor.setLogPath(logPath);
|
||||||
|
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
|
||||||
|
// 返回
|
||||||
|
return xxlJobSpringExecutor;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.java3y.austin.constants;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job常量信息
|
||||||
|
*
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
public class XxlJobConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口路径
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_URL = "/xxl-job-admin/login";
|
||||||
|
public static final String INSERT_URL = "/jobinfo/add";
|
||||||
|
public static final String UPDATE_URL = "/jobinfo/update";
|
||||||
|
public static final String DELETE_URL = "/jobinfo/remove";
|
||||||
|
public static final String RUN_URL = "/jobinfo/start";
|
||||||
|
public static final String STOP_URL = "/jobinfo/stop";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行器名称
|
||||||
|
*/
|
||||||
|
public static final String HANDLER_NAME = "austinJobHandler";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 超时时间
|
||||||
|
*/
|
||||||
|
public static final Integer TIME_OUT = 120;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败重试次数
|
||||||
|
*/
|
||||||
|
public static final Integer RETRY_COUNT = 2;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.java3y.austin.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行阻塞队列
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
public enum ExecutorBlockStrategyEnum {
|
||||||
|
/**
|
||||||
|
* 单机串行
|
||||||
|
*/
|
||||||
|
SERIAL_EXECUTION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 丢弃后续调度
|
||||||
|
*/
|
||||||
|
DISCARD_LATER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 覆盖之前调度
|
||||||
|
*/
|
||||||
|
COVER_EARLY;
|
||||||
|
|
||||||
|
ExecutorBlockStrategyEnum() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.java3y.austin.enums;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路由策略
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
public enum ExecutorRouteStrategyEnum {
|
||||||
|
|
||||||
|
FIRST,
|
||||||
|
LAST,
|
||||||
|
ROUND,
|
||||||
|
RANDOM,
|
||||||
|
CONSISTENT_HASH,
|
||||||
|
LEAST_FREQUENTLY_USED,
|
||||||
|
LEAST_RECENTLY_USED,
|
||||||
|
FAILOVER,
|
||||||
|
BUSYOVER,
|
||||||
|
SHARDING_BROADCAST;
|
||||||
|
|
||||||
|
ExecutorRouteStrategyEnum() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.java3y.austin.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调度过期策略
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
public enum MisfireStrategyEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* do nothing
|
||||||
|
*/
|
||||||
|
DO_NOTHING,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fire once now
|
||||||
|
*/
|
||||||
|
FIRE_ONCE_NOW;
|
||||||
|
|
||||||
|
MisfireStrategyEnum() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.java3y.austin.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调度类型
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
public enum ScheduleTypeEnum {
|
||||||
|
|
||||||
|
NONE,
|
||||||
|
/**
|
||||||
|
* schedule by cron
|
||||||
|
*/
|
||||||
|
CRON,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* schedule by fixed rate (in seconds)
|
||||||
|
*/
|
||||||
|
FIX_RATE;
|
||||||
|
|
||||||
|
ScheduleTypeEnum() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.java3y.austin.handler;
|
||||||
|
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class CronTaskHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 简单任务
|
||||||
|
*/
|
||||||
|
@XxlJob("austinJobHandler")
|
||||||
|
public void execute() {
|
||||||
|
log.info("XXL-JOB, Hello World.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.java3y.austin.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.java3y.austin.constant.AustinConstant;
|
||||||
|
import com.java3y.austin.constants.XxlJobConstant;
|
||||||
|
import com.java3y.austin.domain.MessageTemplate;
|
||||||
|
import com.java3y.austin.entity.XxlJobInfo;
|
||||||
|
import com.java3y.austin.enums.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxlJob工具类
|
||||||
|
*
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
public class XxlJobUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建xxlJobInfo信息
|
||||||
|
*
|
||||||
|
* @param messageTemplate
|
||||||
|
* @param triggerStatus 是否启动定时任务
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static XxlJobInfo buildXxlJobInfo(MessageTemplate messageTemplate) {
|
||||||
|
|
||||||
|
// 判断是否为cron表达式
|
||||||
|
String scheduleConf = StrUtil.EMPTY;
|
||||||
|
String scheduleType = ScheduleTypeEnum.NONE.name();
|
||||||
|
if (!messageTemplate.getExpectPushTime().equals(String.valueOf(AustinConstant.FALSE))) {
|
||||||
|
scheduleType = ScheduleTypeEnum.CRON.name();
|
||||||
|
scheduleConf = messageTemplate.getExpectPushTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
XxlJobInfo xxlJobInfo = XxlJobInfo.builder().jobGroup(1).jobDesc(messageTemplate.getName())
|
||||||
|
.author(messageTemplate.getCreator())
|
||||||
|
.scheduleConf(scheduleConf)
|
||||||
|
.scheduleType(scheduleType)
|
||||||
|
.misfireStrategy(MisfireStrategyEnum.DO_NOTHING.name())
|
||||||
|
.executorBlockStrategy(ExecutorRouteStrategyEnum.CONSISTENT_HASH.name())
|
||||||
|
.executorHandler(XxlJobConstant.HANDLER_NAME)
|
||||||
|
.executorParam(JSON.toJSONString(messageTemplate))
|
||||||
|
.executorBlockStrategy(ExecutorBlockStrategyEnum.SERIAL_EXECUTION.name())
|
||||||
|
.executorTimeout(XxlJobConstant.TIME_OUT)
|
||||||
|
.executorFailRetryCount(XxlJobConstant.RETRY_COUNT)
|
||||||
|
.glueType(GlueTypeEnum.BEAN.name())
|
||||||
|
.triggerStatus(AustinConstant.FALSE)
|
||||||
|
.glueRemark(StrUtil.EMPTY)
|
||||||
|
.glueSource(StrUtil.EMPTY)
|
||||||
|
.alarmEmail(StrUtil.EMPTY)
|
||||||
|
.childJobId(StrUtil.EMPTY).build();
|
||||||
|
|
||||||
|
if (messageTemplate.getCronTaskId() != null) {
|
||||||
|
xxlJobInfo.setId(messageTemplate.getCronTaskId());
|
||||||
|
}
|
||||||
|
return xxlJobInfo;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.java3y.austin.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.java3y.austin.service.CronTaskService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@Api(tags = {"定时任务接口"})
|
||||||
|
@RestController
|
||||||
|
public class XxlJobController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CronTaskService cronTaskService;
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping("/xxl/add/task")
|
||||||
|
public Integer addTask() {
|
||||||
|
|
||||||
|
// return taskService.saveTask();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.java3y.austin.vo;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxlJob任务的参数
|
||||||
|
* @author 3y
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class TaskParam {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板Id
|
||||||
|
*/
|
||||||
|
private String messageTemplateId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cron表达式
|
||||||
|
*/
|
||||||
|
private String cron;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建者
|
||||||
|
*/
|
||||||
|
private String creator;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 额外参数信息
|
||||||
|
*/
|
||||||
|
private Map<String,Object> extra;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue