Commit 26ce1011 by tiger

instId 调整String

1 parent d53a104d
...@@ -116,12 +116,13 @@ public class SopXxlJobUtil { ...@@ -116,12 +116,13 @@ public class SopXxlJobUtil {
return; return;
} }
int i = 0;
for (SopInstNode node : sop.getInstNodeMap().values()) { for (SopInstNode node : sop.getInstNodeMap().values()) {
initSopNodeJob(sop, node); initSopNodeJob(sop, node, i++);
} }
} }
public static void initSopNodeJob(SopStruct sop, SopInstNode node) { public static void initSopNodeJob(SopStruct sop, SopInstNode node, int i) {
String jobBusId = jobBusId(sop.getInst(), node); String jobBusId = jobBusId(sop.getInst(), node);
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId); XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
...@@ -131,7 +132,7 @@ public class SopXxlJobUtil { ...@@ -131,7 +132,7 @@ public class SopXxlJobUtil {
} }
// 15 2/3 * * * ? // 15 2/3 * * * ?
String cron = DateUtil.format(org.apache.commons.lang.time.DateUtils.addMinutes(new Date(), 1), "s m H d M ?"); String cron = DateUtil.format(org.apache.commons.lang.time.DateUtils.addSeconds(new Date(), 20 + i * 6), "s m H d M ?");
if (StrUtil.isNotBlank(node.getNodeCron())) { if (StrUtil.isNotBlank(node.getNodeCron())) {
cron = node.getNodeCron(); cron = node.getNodeCron();
} }
...@@ -140,7 +141,8 @@ public class SopXxlJobUtil { ...@@ -140,7 +141,8 @@ public class SopXxlJobUtil {
Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId()); Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId());
SopInstNodeParam params = new SopInstNodeParam(); SopInstNodeParam params = new SopInstNodeParam();
params.setInstNodeId(node.getInstNodeId()); params.setInstId(node.getInstId());
params.setNodeId(node.getNodeId());
params.setPreIds(linkPair.getKey()); params.setPreIds(linkPair.getKey());
params.setNextIds(linkPair.getValue()); params.setNextIds(linkPair.getValue());
String paramJson = JSONUtil.toJsonStr(params); String paramJson = JSONUtil.toJsonStr(params);
...@@ -153,6 +155,7 @@ public class SopXxlJobUtil { ...@@ -153,6 +155,7 @@ public class SopXxlJobUtil {
job.setExecutorHandler(SopXxlJobUtil.SOP_NODE_EXECUTE_JOB_ID); job.setExecutorHandler(SopXxlJobUtil.SOP_NODE_EXECUTE_JOB_ID);
job.setBusKey(jobBusId); job.setBusKey(jobBusId);
job.setTriggerStatus(1); job.setTriggerStatus(1);
job.setExecutorRouteStrategy("RANDOM");
if (exists) { if (exists) {
String update = XxlJobUtil.update(job); String update = XxlJobUtil.update(job);
...@@ -169,16 +172,21 @@ public class SopXxlJobUtil { ...@@ -169,16 +172,21 @@ public class SopXxlJobUtil {
Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId()); Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId());
for (Integer nextId : linkPair.getValue()) { for (Integer nextId : linkPair.getValue()) {
String jobBusId = jobBusId(sop.getInst(), sop.getInstNodeMap().get(nextId)); try {
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId); String jobBusId = jobBusId(sop.getInst(), sop.getInstNodeMap().get(nextId));
if (job != null) { XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
SopInstNodeParam params = JSONUtil.toBean(job.getExecutorParam(), SopInstNodeParam.class); if (job != null) {
if (params != null) { SopInstNodeParam params = JSONUtil.toBean(job.getExecutorParam(), SopInstNodeParam.class);
params.getFinishedIds().add(node.getNodeId()); if (params != null) {
params.getFinishedIds().add(node.getNodeId());
String update = XxlJobUtil.update(job);
SopXxlJobUtil.log(log, "【{}】Sop任务节点更新,params:{},result:{}", jobBusId, params, update); String update = XxlJobUtil.update(job);
SopXxlJobUtil.log(log, "【{}】Sop任务节点更新,params:{},result:{}", jobBusId, params, update);
}
} }
} catch (Exception e) {
log.warn("linkPair:{}", linkPair, e);
} }
} }
} }
......
...@@ -68,7 +68,7 @@ public class XxlJobUtil { ...@@ -68,7 +68,7 @@ public class XxlJobUtil {
jobInfo.setJobGroup(groupId); jobInfo.setJobGroup(groupId);
jobInfo.setGlueType("BEAN"); jobInfo.setGlueType("BEAN");
jobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION"); jobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
jobInfo.setExecutorRouteStrategy("FIRST"); jobInfo.setExecutorRouteStrategy("RANDOM");
jobInfo.setMisfireStrategy("DO_NOTHING"); jobInfo.setMisfireStrategy("DO_NOTHING");
jobInfo.setScheduleType(ScheduleTypeEnum.CRON.name()); jobInfo.setScheduleType(ScheduleTypeEnum.CRON.name());
return doPost(adminAddresses + ADD_URL, jobInfo, String.class); return doPost(adminAddresses + ADD_URL, jobInfo, String.class);
......
...@@ -39,10 +39,10 @@ public class SopInstNodeExecuteJobHandler { ...@@ -39,10 +39,10 @@ public class SopInstNodeExecuteJobHandler {
SopXxlJobUtil.log(log, "【执行Sop节点】{}", param); SopXxlJobUtil.log(log, "【执行Sop节点】{}", param);
SopStruct sop = sopService.loadSopByInstNodeId(param.getInstNodeId()); SopStruct sop = sopService.loadSop(param.getInstId());
// 执行sop里面的instNodeId节点。 // 执行sop里面的instNodeId节点。
SopInstNode node = sop.getInstNodeMap().get(param.getInstNodeId()); SopInstNode node = sop.getInstNodeMap().get(param.getNodeId());
boolean avaliable = checkPreIds(sop, node, param); boolean avaliable = checkPreIds(sop, node, param);
if (!avaliable) { if (!avaliable) {
return; return;
...@@ -65,6 +65,8 @@ public class SopInstNodeExecuteJobHandler { ...@@ -65,6 +65,8 @@ public class SopInstNodeExecuteJobHandler {
* @return * @return
*/ */
private boolean checkPreIds(SopStruct sop, SopInstNode node, SopInstNodeParam param) { private boolean checkPreIds(SopStruct sop, SopInstNode node, SopInstNodeParam param) {
log.info("sop:{}", sop);
log.info("node:{}", node);
Pair<Set<Integer>, Set<Integer>> pair = sop.getInstLinkMap().get(node.getNodeId()); Pair<Set<Integer>, Set<Integer>> pair = sop.getInstLinkMap().get(node.getNodeId());
// 前置任务为空,直接执行 // 前置任务为空,直接执行
......
...@@ -9,8 +9,11 @@ import lombok.Data; ...@@ -9,8 +9,11 @@ import lombok.Data;
@Data @Data
public class SopInstNodeParam { public class SopInstNodeParam {
/** 实例id */
private String instId;
/** 实例节点id */ /** 实例节点id */
private Integer instNodeId; private Integer nodeId;
/** 实例节点前置节点id */ /** 实例节点前置节点id */
private Set<Integer> preIds = Sets.newHashSet(); private Set<Integer> preIds = Sets.newHashSet();
......
...@@ -76,7 +76,7 @@ public class SopInstService { ...@@ -76,7 +76,7 @@ public class SopInstService {
* @param instId * @param instId
* @return * @return
*/ */
public boolean delete(Integer instId) { public boolean delete(String instId) {
int i = sopInstMapper.deleteByPrimaryKey(instId); int i = sopInstMapper.deleteByPrimaryKey(instId);
if (i > 0) { if (i > 0) {
return true; return true;
......
...@@ -119,7 +119,7 @@ public class SopService { ...@@ -119,7 +119,7 @@ public class SopService {
List<SopInstNode> instNodes = instNodeMapper List<SopInstNode> instNodes = instNodeMapper
.selectByExample(Example.builder(SopInstNode.class).where(Sqls.custom().andEqualTo("instId", inst.getInstId())).build()); .selectByExample(Example.builder(SopInstNode.class).where(Sqls.custom().andEqualTo("instId", inst.getInstId())).build());
Map<Integer, SopInstNode> instNodeMap = instNodes.stream() Map<Integer, SopInstNode> instNodeMap = instNodes.stream()
.collect(Collectors.toMap(SopInstNode::getInstNodeId, obj -> obj, (key1, key2) -> key1)); .collect(Collectors.toMap(SopInstNode::getNodeId, obj -> obj, (key1, key2) -> key1));
sop.setInstNodeMap(instNodeMap); sop.setInstNodeMap(instNodeMap);
List<SopInstLink> instLinks = instLinkMapper List<SopInstLink> instLinks = instLinkMapper
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
<id column="batch_no" jdbcType="VARCHAR" property="batchNo" /> <id column="batch_no" jdbcType="VARCHAR" property="batchNo" />
<result column="inst_id" jdbcType="INTEGER" property="instId" /> <result column="inst_id" jdbcType="VARCHAR" property="instId" />
<result column="snapshot" jdbcType="VARCHAR" property="snapshot" /> <result column="snapshot" jdbcType="VARCHAR" property="snapshot" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!