Commit 26ce1011 by tiger

instId 调整String

1 parent d53a104d
......@@ -116,12 +116,13 @@ public class SopXxlJobUtil {
return;
}
int i = 0;
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);
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
......@@ -131,7 +132,7 @@ public class SopXxlJobUtil {
}
// 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())) {
cron = node.getNodeCron();
}
......@@ -140,7 +141,8 @@ public class SopXxlJobUtil {
Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId());
SopInstNodeParam params = new SopInstNodeParam();
params.setInstNodeId(node.getInstNodeId());
params.setInstId(node.getInstId());
params.setNodeId(node.getNodeId());
params.setPreIds(linkPair.getKey());
params.setNextIds(linkPair.getValue());
String paramJson = JSONUtil.toJsonStr(params);
......@@ -153,6 +155,7 @@ public class SopXxlJobUtil {
job.setExecutorHandler(SopXxlJobUtil.SOP_NODE_EXECUTE_JOB_ID);
job.setBusKey(jobBusId);
job.setTriggerStatus(1);
job.setExecutorRouteStrategy("RANDOM");
if (exists) {
String update = XxlJobUtil.update(job);
......@@ -169,16 +172,21 @@ public class SopXxlJobUtil {
Pair<Set<Integer>, Set<Integer>> linkPair = sop.getInstLinkMap().get(node.getNodeId());
for (Integer nextId : linkPair.getValue()) {
String jobBusId = jobBusId(sop.getInst(), sop.getInstNodeMap().get(nextId));
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
if (job != null) {
SopInstNodeParam params = JSONUtil.toBean(job.getExecutorParam(), SopInstNodeParam.class);
if (params != null) {
params.getFinishedIds().add(node.getNodeId());
String update = XxlJobUtil.update(job);
SopXxlJobUtil.log(log, "【{}】Sop任务节点更新,params:{},result:{}", jobBusId, params, update);
try {
String jobBusId = jobBusId(sop.getInst(), sop.getInstNodeMap().get(nextId));
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
if (job != null) {
SopInstNodeParam params = JSONUtil.toBean(job.getExecutorParam(), SopInstNodeParam.class);
if (params != null) {
params.getFinishedIds().add(node.getNodeId());
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 {
jobInfo.setJobGroup(groupId);
jobInfo.setGlueType("BEAN");
jobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
jobInfo.setExecutorRouteStrategy("FIRST");
jobInfo.setExecutorRouteStrategy("RANDOM");
jobInfo.setMisfireStrategy("DO_NOTHING");
jobInfo.setScheduleType(ScheduleTypeEnum.CRON.name());
return doPost(adminAddresses + ADD_URL, jobInfo, String.class);
......
......@@ -39,10 +39,10 @@ public class SopInstNodeExecuteJobHandler {
SopXxlJobUtil.log(log, "【执行Sop节点】{}", param);
SopStruct sop = sopService.loadSopByInstNodeId(param.getInstNodeId());
SopStruct sop = sopService.loadSop(param.getInstId());
// 执行sop里面的instNodeId节点。
SopInstNode node = sop.getInstNodeMap().get(param.getInstNodeId());
SopInstNode node = sop.getInstNodeMap().get(param.getNodeId());
boolean avaliable = checkPreIds(sop, node, param);
if (!avaliable) {
return;
......@@ -65,6 +65,8 @@ public class SopInstNodeExecuteJobHandler {
* @return
*/
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());
// 前置任务为空,直接执行
......
......@@ -9,8 +9,11 @@ import lombok.Data;
@Data
public class SopInstNodeParam {
/** 实例id */
private String instId;
/** 实例节点id */
private Integer instNodeId;
private Integer nodeId;
/** 实例节点前置节点id */
private Set<Integer> preIds = Sets.newHashSet();
......
......@@ -76,7 +76,7 @@ public class SopInstService {
* @param instId
* @return
*/
public boolean delete(Integer instId) {
public boolean delete(String instId) {
int i = sopInstMapper.deleteByPrimaryKey(instId);
if (i > 0) {
return true;
......
......@@ -119,7 +119,7 @@ public class SopService {
List<SopInstNode> instNodes = instNodeMapper
.selectByExample(Example.builder(SopInstNode.class).where(Sqls.custom().andEqualTo("instId", inst.getInstId())).build());
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);
List<SopInstLink> instLinks = instLinkMapper
......
......@@ -6,7 +6,7 @@
WARNING - @mbg.generated
-->
<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="create_time" jdbcType="TIMESTAMP" property="createTime" />
<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!