Commit 733e47f0 by zhouhaibao

Merge remote-tracking branch 'origin/v1.0.1' into v1.0.1

2 parents 53041221 8a7da356
...@@ -23,6 +23,14 @@ ...@@ -23,6 +23,14 @@
<groupId>com.glsx</groupId> <groupId>com.glsx</groupId>
<artifactId>rest-admin-feign</artifactId> <artifactId>rest-admin-feign</artifactId>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package cn.com.glsx.process.modules.model; package cn.com.glsx.process.modules.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import com.google.common.collect.Sets;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstBatch; import cn.com.glsx.process.modules.entity.SopInstBatch;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
...@@ -38,4 +42,40 @@ public class SopStruct { ...@@ -38,4 +42,40 @@ public class SopStruct {
/** 实例当前批次 */ /** 实例当前批次 */
private SopInstBatch batch; private SopInstBatch batch;
/** 所有节点执行顺序 */
public List<Integer> getNodeSort() {
List<Integer> sort = new ArrayList<>();
Set<Integer> keys = Sets.newHashSet();
int i = 0;
while (keys.size() < instLinkMap.keySet().size()) {
Set<Integer> sets = instLinkMap.keySet();
for (Integer key : sets) {
i++;
Pair<Set<Integer>, Set<Integer>> pair = instLinkMap.get(key);
if (!keys.contains(key)) {
// 第一个节点:直接执行
if (pair.getKey().isEmpty()) {
keys.add(key);
sort.add(key);
continue;
}
// 非第一个节点:判断前置节点
if (keys.containsAll(pair.getKey())) {
keys.add(key);
sort.add(key);
continue;
}
} else {
// 进入后置节点
sets = pair.getValue();
continue;
}
}
if (i++ > 1000) {
throw new RuntimeException("Sop实例:【" + inst.getInstId() + "-" + inst.getInstName() + "】节点不闭环,请检查!");
}
}
return sort;
}
} }
...@@ -8,17 +8,16 @@ import java.util.TimeZone; ...@@ -8,17 +8,16 @@ import java.util.TimeZone;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import com.glsx.plat.context.EnableRestAdmin; import com.glsx.plat.context.EnableRestAdmin;
import cn.com.glsx.process.job.DynamicTaskService; import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/** /**
* @author payu * @author payu
...@@ -26,14 +25,11 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy; ...@@ -26,14 +25,11 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
@EnableDubbo @EnableDubbo
@EnableRestAdmin @EnableRestAdmin
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients(basePackages = {"cn.com.glsx.*.api"}) @EnableFeignClients(basePackages = { "cn.com.glsx.*.api" })
@SpringBootApplication @SpringBootApplication
@EnableAspectJAutoProxy @EnableAspectJAutoProxy
public class Application implements CommandLineRunner { public class Application implements CommandLineRunner {
@Autowired
private DynamicTaskService dynamicTaskAdd;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
...@@ -45,6 +41,6 @@ public class Application implements CommandLineRunner { ...@@ -45,6 +41,6 @@ public class Application implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
/* dynamicTaskAdd.scanAddJob();*/ SopXxlJobUtil.initLoadJob();
} }
} }
...@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext; ...@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob; import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.glsx.plat.context.utils.SpringUtils; import com.glsx.plat.context.utils.SpringUtils;
import cn.com.glsx.process.job.elastic.core.DynamicTaskService; import cn.com.glsx.process.job.DynamicTaskService;
import cn.com.glsx.process.job.elastic.param.SopInstNodeParam; import cn.com.glsx.process.job.elastic.param.SopInstNodeParam;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
...@@ -55,14 +55,14 @@ public class SopInstExecuteJob implements SimpleJob { ...@@ -55,14 +55,14 @@ public class SopInstExecuteJob implements SimpleJob {
if (StrUtil.isNotBlank(node.getNodeCron())) { if (StrUtil.isNotBlank(node.getNodeCron())) {
// 按cron表达式执行 // 按cron表达式执行
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), new SopInstNodeJob(), // taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), new SopInstNodeJob(),
sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled); // sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled);
} else { } else {
// //
// 立即执行: 1分钟后执行: 11 12 8 2 3 ? 2024 // 立即执行: 1分钟后执行: 11 12 8 2 3 ? 2024
String cron = DateUtil.format(org.apache.commons.lang.time.DateUtils.addMinutes(new Date(), 1), "s m H d M ? yyyy"); String cron = DateUtil.format(org.apache.commons.lang.time.DateUtils.addMinutes(new Date(), 1), "s m H d M ? yyyy");
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), cron, new SopInstNodeJob(), // taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), cron, new SopInstNodeJob(),
sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled); // sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled);
} }
} }
......
...@@ -6,7 +6,6 @@ import com.dangdang.ddframe.job.api.ShardingContext; ...@@ -6,7 +6,6 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob; import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.glsx.plat.context.utils.SpringUtils; import com.glsx.plat.context.utils.SpringUtils;
import cn.com.glsx.process.job.elastic.core.DynamicTaskService;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.service.SopService; import cn.com.glsx.process.modules.service.SopService;
...@@ -28,15 +27,15 @@ public class SopInstLoadJob implements SimpleJob { ...@@ -28,15 +27,15 @@ public class SopInstLoadJob implements SimpleJob {
log.info("---------SopInstLoadJob-------------:" + JobParameter); log.info("---------SopInstLoadJob-------------:" + JobParameter);
SopService sopService = SpringUtils.getBean(SopService.class); SopService sopService = SpringUtils.getBean(SopService.class);
DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class); // DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class);
List<SopInst> all = sopService.loadAllInst(); List<SopInst> all = sopService.loadAllInst();
for (SopInst inst : all) { for (SopInst inst : all) {
if (inst.getInstStatus() == 1) { if (inst.getInstStatus() == 1) {
taskService.create(jobName(inst), inst.getInstCron(), 1, new SopInstExecuteJob(), inst.getInstName(), inst.getInstId()); // taskService.create(jobName(inst), inst.getInstCron(), 1, new SopInstExecuteJob(), inst.getInstName(), inst.getInstId());
} else { } else {
taskService.stopJob(inst.getInstName()); // taskService.stopJob(inst.getInstName());
} }
} }
......
...@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext; ...@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob; import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.glsx.plat.context.utils.SpringUtils; import com.glsx.plat.context.utils.SpringUtils;
import cn.com.glsx.process.job.elastic.core.DynamicTaskService; import cn.com.glsx.process.job.DynamicTaskService;
import cn.com.glsx.process.job.elastic.param.SopInstNodeParam; import cn.com.glsx.process.job.elastic.param.SopInstNodeParam;
import cn.com.glsx.process.modules.entity.SopInstNode; import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
...@@ -67,8 +67,8 @@ public class SopInstNodeJob implements SimpleJob { ...@@ -67,8 +67,8 @@ public class SopInstNodeJob implements SimpleJob {
DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class); DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class);
// 按cron表达式执行 // 按cron表达式执行
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), new SopInstNodeJob(), // taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), new SopInstNodeJob(),
sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled); // sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled);
} }
......
package cn.com.glsx.process.job.xxljob.core;
import java.util.Date;
import java.util.Set;
import org.slf4j.Logger;
import com.xxl.job.core.context.XxlJobHelper;
import cn.com.glsx.process.job.elastic.param.SopInstNodeParam;
import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SopXxlJobUtil {
public static final String SOP_LOAD_JOB_ID = "sopInstLoadJobHandler";
public static final String SOP_EXECUTE_JOB_ID = "sopInstExecuteJobHandler";
public static final String SOP_NODE_EXECUTE_JOB_ID = "sopNodeExecuteJobHandler";
public static void pauseSop(SopStruct sop) {
String jobBusId = jobBusId(sop.getInst());
String pause = XxlJobUtil.pause(jobBusId);
SopXxlJobUtil.log(log, "【{}】Sop任务停止:{}", jobBusId, pause);
if (sop != null) {
// 遍历node,停止任务
for (SopInstNode node : sop.getInstNodeMap().values()) {
jobBusId = jobBusId(sop.getInst(), node);
pause = XxlJobUtil.pause(jobBusId);
SopXxlJobUtil.log(log, "【{}】Sop节点任务停止:{}", jobBusId, pause);
}
}
}
public static void initLoadJob() {
XxlJobInfo job = XxlJobUtil.findByBusKey(SOP_LOAD_JOB_ID);
if (job != null) {
if (job.getTriggerStatus() == 1) {
return;
} else {
XxlJobUtil.remove(SOP_LOAD_JOB_ID);
}
}
job = new XxlJobInfo();
job.setExecutorParam("");
job.setJobDesc("加载所有SOP实例任务");
job.setAuthor("admin");
job.setScheduleConf("10 */5 * * * ?");
job.setExecutorHandler(SOP_LOAD_JOB_ID);
job.setBusKey(SOP_LOAD_JOB_ID);
job.setTriggerStatus(1);
String add = XxlJobUtil.add(job);
SopXxlJobUtil.log(log, "【{}】任务启动,cron:{},result:{}", SOP_LOAD_JOB_ID, job.getScheduleConf(), add);
}
public static void initSopJob(SopInst inst) {
String jobBusId = jobBusId(inst);
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
if (job != null) {
XxlJobUtil.remove(jobBusId);
}
// 重建job
job = new XxlJobInfo();
job.setExecutorParam(inst.getInstId());
job.setJobDesc(inst.getInstName());
job.setAuthor("admin");
job.setScheduleConf(inst.getInstCron());
job.setExecutorHandler(SopXxlJobUtil.SOP_EXECUTE_JOB_ID);
job.setBusKey(jobBusId);
job.setTriggerStatus(1);
String add = XxlJobUtil.add(job);
SopXxlJobUtil.log(log, "【{}】Sop任务启动,cron:{},result:{}", inst.getInstId(), job.getScheduleConf(), add);
}
public static void initSopNodesJob(SopStruct sop) {
if (sop == null) {
return;
}
if (sop.getInst().getInstStatus() == 0) {
pauseSop(sop);
return;
}
for (SopInstNode node : sop.getInstNodeMap().values()) {
initSopNodeJob(sop, node);
}
}
public static void initSopNodeJob(SopStruct sop, SopInstNode node) {
String jobBusId = jobBusId(sop.getInst(), node);
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
if (job != null) {
XxlJobUtil.remove(jobBusId);
}
// 15 2/3 * * * ?
String cron = DateUtil.format(org.apache.commons.lang.time.DateUtils.addMinutes(new Date(), 1), "s m H d M ?");
if (StrUtil.isNotBlank(node.getNodeCron())) {
cron = node.getNodeCron();
}
// 前置节点,后置节点
Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId());
boolean enabled = linkPair == null || linkPair.getKey().isEmpty();
SopInstNodeParam params = new SopInstNodeParam();
params.setInstNodeId(node.getInstNodeId());
params.setPreIds(linkPair.getKey());
String paramJson = JSONUtil.toJsonStr(params);
// 重建job
job = new XxlJobInfo();
job.setExecutorParam(sop.getInst().getInstId()); // TODO
job.setJobDesc(sop.getInst().getInstName() + "-" + node.getNodeName());
job.setAuthor("admin");
job.setScheduleConf(cron);
job.setExecutorHandler(SopXxlJobUtil.SOP_NODE_EXECUTE_JOB_ID);
job.setBusKey(jobBusId);
job.setTriggerStatus(1);
String add = XxlJobUtil.add(job);
SopXxlJobUtil.log(log, "【{}】Sop节点任务启动,cron:{},result:{}", jobBusId, job.getScheduleConf(), add);
}
public static String jobBusId(SopInst inst) {
return inst.getInstId();
}
public static String jobBusId(SopInst inst, SopInstNode node) {
return inst.getInstId() + "-" + node.getNodeId();
}
// 日志相关
public static boolean log(Logger logger, String appendLogPattern, Object... appendLogArguments) {
logger.info(appendLogPattern, appendLogArguments);
return XxlJobHelper.log(appendLogPattern, appendLogArguments);
}
}
package cn.com.glsx.process.job.xxljob.core; package cn.com.glsx.process.job.xxljob.core;
import java.io.IOException;
import java.net.HttpCookie;
import java.util.List;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -9,6 +13,8 @@ import com.alibaba.fastjson.JSONObject; ...@@ -9,6 +13,8 @@ import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.util.XxlJobRemotingUtil; import com.xxl.job.core.util.XxlJobRemotingUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Component @Component
...@@ -19,6 +25,7 @@ public class XxlJobUtil { ...@@ -19,6 +25,7 @@ public class XxlJobUtil {
private static String appname; private static String appname;
private static Integer groupId; private static Integer groupId;
private static String accessToken; private static String accessToken;
private static String cookie = "";
@Value("${xxl.job.admin.addresses}") @Value("${xxl.job.admin.addresses}")
public void setAdminAddresses(String adminAddresses) { public void setAdminAddresses(String adminAddresses) {
...@@ -166,7 +173,7 @@ public class XxlJobUtil { ...@@ -166,7 +173,7 @@ public class XxlJobUtil {
} }
public static <T> T doPost(String url, Object json, Class<T> clazz) { public static <T> T doPost(String url, Object json, Class<T> clazz) {
log.info("请求url{},请求参数{} accessToken:{}", url, JSONObject.toJSONString(json), accessToken); log.info("请求url{},请求参数{} {}:{}", url, JSONObject.toJSONString(json), XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN, accessToken);
ReturnT<T> returnT = XxlJobRemotingUtil.postBody(url, accessToken, 30, json, clazz); ReturnT<T> returnT = XxlJobRemotingUtil.postBody(url, accessToken, 30, json, clazz);
if (returnT.getCode() != SUCCESS_CODE) { if (returnT.getCode() != SUCCESS_CODE) {
log.info(String.format("【xxl-job】接口调用失败,错误码:%s,原因:%s", returnT.getCode(), returnT.getMsg())); log.info(String.format("【xxl-job】接口调用失败,错误码:%s,原因:%s", returnT.getCode(), returnT.getMsg()));
...@@ -174,4 +181,25 @@ public class XxlJobUtil { ...@@ -174,4 +181,25 @@ public class XxlJobUtil {
return returnT.getContent(); return returnT.getContent();
} }
/**
* 登录
*
* @param url
* @param userName
* @param password
* @return
* @throws HttpException
* @throws IOException
*/
public static String login(String userName, String password) {
HttpResponse rsp = HttpUtil.createGet(adminAddresses + "/api/jobinfo/login?userName=" + userName + "&password=" + password).execute();
List<HttpCookie> cookies = rsp.getCookies();
StringBuffer tmpcookies = new StringBuffer();
for (HttpCookie c : cookies) {
tmpcookies.append(c.toString() + ";");
}
cookie = tmpcookies.toString();
return cookie;
}
} }
package cn.com.glsx.process.job.xxljob.impl;
import org.springframework.stereotype.Component;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
public class HelloJobHandler {
@XxlJob("demoJobHandler")
public void demoJobHandler(String param) throws Exception {
log.info("XXL-JOB, Hello World.");
}
}
package cn.com.glsx.process.job.xxljob.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class SopInstExecuteJobHandler {
static final String JOB_ID = "sopInstExecuteJobHandler";
@Resource
private SopService sopService;
@XxlJob(SopXxlJobUtil.SOP_EXECUTE_JOB_ID)
public void handler(String param) throws Exception {
param = XxlJobHelper.getJobParam();
log.info("【执行Sop实例】{}", param);
String instId = param;
SopStruct sop = sopService.loadSop(instId);
// 创建所有节点任务
SopXxlJobUtil.initSopNodesJob(sop);
}
}
package cn.com.glsx.process.job.xxljob.impl; package cn.com.glsx.process.job.xxljob.impl;
import java.util.Date;
import java.util.List; import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
import com.xxl.job.core.glue.GlueTypeEnum;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import cn.com.glsx.process.job.xxljob.core.XxlJobInfo; import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.job.xxljob.core.XxlJobUtil;
import cn.com.glsx.process.modules.entity.SopInst; import cn.com.glsx.process.modules.entity.SopInst;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopService; import cn.com.glsx.process.modules.service.SopService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -21,80 +18,27 @@ import lombok.extern.slf4j.Slf4j; ...@@ -21,80 +18,27 @@ import lombok.extern.slf4j.Slf4j;
@Component @Component
public class SopInstLoadJobHandler { public class SopInstLoadJobHandler {
static final String JOB_ID = "sopInstLoadJobHandler";
@Resource @Resource
private SopService sopService; private SopService sopService;
@XxlJob(JOB_ID) @XxlJob(SopXxlJobUtil.SOP_LOAD_JOB_ID)
public void handler(String param) throws Exception { public void handler(String param) throws Exception {
log.info("【加载Sop实例列表】{}", param); SopXxlJobUtil.log(log, "【加载Sop实例列表】{}", param);
List<SopInst> all = sopService.loadAllInst(); List<SopInst> all = sopService.loadAllInst();
for (SopInst inst : all) { for (SopInst inst : all) {
if (inst.getInstStatus() == 0) { if (inst.getInstStatus() == 0) {
String pause = XxlJobUtil.pause(inst.getInstId()); // 停止实例任务以及所有子任务
log.info("【{}】任务停止:{}", inst.getInstId(), pause);
SopStruct sop = sopService.loadSop(inst.getInstId());
SopXxlJobUtil.pauseSop(sop);
continue; continue;
} }
// 检查实例是否已加载到任务列表 // 启动sop任务
XxlJobInfo job = XxlJobUtil.findByBusKey(inst.getInstId()); SopXxlJobUtil.initSopJob(inst);
if (job == null || job.getTriggerStatus() == 0) {
job = new XxlJobInfo();
job.setAuthor("admin");
job.setAddTime(new Date());
job.setBusKey(inst.getInstId());
job.setExecutorBlockStrategy(param);
job.setExecutorFailRetryCount(1);
job.setExecutorHandler("");
job.setExecutorParam("");
job.setExecutorRouteStrategy(param);
job.setExecutorTimeout(0);
job.setGlueRemark(param);
job.setGlueSource(param);
job.setGlueType(GlueTypeEnum.BEAN.getCmd());
job.setGlueUpdatetime(new Date());
job.setJobDesc(param);
job.setJobGroup(0);
job.setMisfireStrategy(param);
job.setScheduleConf(param);
job.setScheduleType(param);
job.setTriggerStatus(0);
job.setUpdateTime(null);
String add = XxlJobUtil.add(job);
log.info("【{}】任务启动:{}", inst.getInstId(), add);
}
} }
} }
public static void initJob() {
XxlJobInfo job = new XxlJobInfo();
job.setAddTime(new Date());
job.setAuthor("admin");
job.setBusKey(JOB_ID);
job.setExecutorBlockStrategy(ExecutorBlockStrategyEnum.COVER_EARLY.name());
job.setExecutorFailRetryCount(1);
job.setExecutorHandler(JOB_ID);
job.setExecutorParam("");
job.setExecutorRouteStrategy("FIRST");
job.setExecutorTimeout(0);
job.setGlueRemark("java");
job.setGlueSource("");
job.setGlueType(GlueTypeEnum.BEAN.getCmd());
job.setGlueUpdatetime(new Date());
job.setJobDesc("加载所有SOP实例任务");
job.setJobGroup(1);
job.setMisfireStrategy("DO_NOTHING");
job.setScheduleConf("10 */5 * * * ?"); // 每5分钟加载一次
job.setScheduleType("CRON");
job.setTriggerStatus(1);
job.setUpdateTime(new Date());
String add = XxlJobUtil.add(job);
log.info("【{}】任务启动:{}", JOB_ID, add);
}
} }
package cn.com.glsx.process.job.xxljob.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Component
public class SopInstNodeExecuteJobHandler {
@Resource
private SopService sopService;
@XxlJob(SopXxlJobUtil.SOP_NODE_EXECUTE_JOB_ID)
public void handler(String param) throws Exception {
param = XxlJobHelper.getJobParam();
SopXxlJobUtil.log(log, "【执行Sop节点】{}", param);
String instId = param;
SopStruct sop = sopService.loadSop(instId);
// 创建所有节点任务
// SopXxlJobUtil.initSopNodeJob(sop);
}
}
...@@ -12,7 +12,6 @@ import com.glsx.plat.core.web.R; ...@@ -12,7 +12,6 @@ import com.glsx.plat.core.web.R;
import cn.com.glsx.process.job.xxljob.core.XxlJobInfo; import cn.com.glsx.process.job.xxljob.core.XxlJobInfo;
import cn.com.glsx.process.job.xxljob.core.XxlJobUtil; import cn.com.glsx.process.job.xxljob.core.XxlJobUtil;
import cn.com.glsx.process.job.xxljob.impl.SopInstLoadJobHandler;
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 lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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"> <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> <parent>
<groupId>com.glsx</groupId> <groupId>com.glsx</groupId>
<artifactId>rest-admin-framework</artifactId> <artifactId>rest-admin-framework</artifactId>
...@@ -48,8 +50,10 @@ ...@@ -48,8 +50,10 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<modules>
<modules>
<module>platform-process</module> <module>platform-process</module>
<module>platform-process-api</module> <module>platform-process-api</module>
</modules> </modules>
</project> </project>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!