Commit b40620a7 by tiger

触发实例刷新

1 parent 6b818608
package cn.com.glsx.process.job.xxljob.core; package cn.com.glsx.process.job.xxljob.core;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import com.google.common.collect.Lists;
import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.context.XxlJobHelper;
import cn.com.glsx.process.job.xxljob.param.SopInstNodeParam; import cn.com.glsx.process.job.xxljob.param.SopInstNodeParam;
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.model.SopStruct; import cn.com.glsx.process.modules.model.SopStruct;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
...@@ -34,11 +37,13 @@ public class SopXxlJobUtil { ...@@ -34,11 +37,13 @@ public class SopXxlJobUtil {
String jobBusId = jobBusId(sop.getInst()); String jobBusId = jobBusId(sop.getInst());
XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId); XxlJobInfo job = XxlJobUtil.findByBusKey(jobBusId);
if (job != null && job.getTriggerStatus() == 1) { if (job == null) {
String pause = XxlJobUtil.pause(jobBusId); SopXxlJobUtil.log(log, "【{}】Sop任务不存在:{}", jobBusId, sop.getInst().getInstName());
SopXxlJobUtil.log(log, "【{}】Sop任务停止:{}", jobBusId, pause); } else if (job.getTriggerStatus() != 1) {
SopXxlJobUtil.log(log, "【{}】Sop任务已停止:{}", jobBusId, sop.getInst().getInstName());
} else { } else {
SopXxlJobUtil.log(log, "【{}】Sop任务已停止:{}", jobBusId, job == null ? "null" : job.getTriggerStatus()); String pause = XxlJobUtil.pause(jobBusId);
SopXxlJobUtil.log(log, "【{}】Sop任务停止:{} - {}", jobBusId, pause, sop.getInst().getInstName());
} }
// 遍历node,停止任务 // 遍历node,停止任务
...@@ -163,7 +168,6 @@ public class SopXxlJobUtil { ...@@ -163,7 +168,6 @@ public class SopXxlJobUtil {
String add = XxlJobUtil.add(job); String add = XxlJobUtil.add(job);
SopXxlJobUtil.log(log, "【{}】Sop任务节点启动,cron:{},result:{}", jobBusId, job.getScheduleConf(), add); SopXxlJobUtil.log(log, "【{}】Sop任务节点启动,cron:{},result:{}", jobBusId, job.getScheduleConf(), add);
} }
} }
public static void finishSopNodeJob(SopStruct sop, SopInstNode node) { public static void finishSopNodeJob(SopStruct sop, SopInstNode node) {
...@@ -191,6 +195,30 @@ public class SopXxlJobUtil { ...@@ -191,6 +195,30 @@ public class SopXxlJobUtil {
} }
} }
public static String triggerHidden(SopStruct sop) {
if (sop == null) {
return null;
}
List<String> list = Lists.newArrayList();
for (int nodeId : sop.getNodeSort()) {
SopInstNode node = sop.getInstNodeMap().get(nodeId);
if (node.getNodeVisible() == 1) {
continue;
}
// 隐藏任务执行:
String jobBusId = jobBusId(sop.getInst(), node);
XxlJobUtil.trigger(jobBusId);
log.info("【{}】手动触发隐藏任务:{} - {}", jobBusId, node.getNodeName(), node.getNodeCron());
list.add(node.getNodeName());
}
try {
Thread.sleep(2000); // 执行完任务后,稍等才去执行后续操作。
} catch (Exception e) {
}
return CollectionUtil.join(list, ",");
}
public static String jobBusId(SopInst inst) { public static String jobBusId(SopInst inst) {
return inst.getInstId(); return inst.getInstId();
} }
......
...@@ -188,7 +188,7 @@ public class XxlJobUtil { ...@@ -188,7 +188,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{},请求参数{} {}:{}", url, GsonTool.toJson(json), XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN, accessToken); log.info("请求url: {}, 请求参数: {} {} : {}", url, GsonTool.toJson(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()));
......
package cn.com.glsx.process.modules.api; package cn.com.glsx.process.modules.controller;
import javax.annotation.Resource; import javax.annotation.Resource;
...@@ -8,7 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -8,7 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.glsx.plat.core.annotation.ResponseResultBody; import com.glsx.plat.core.annotation.ResponseResultBody;
import com.glsx.plat.core.web.Result;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.modules.model.SopStruct; 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 io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
...@@ -23,7 +25,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -23,7 +25,7 @@ import lombok.extern.slf4j.Slf4j;
@RestController @RestController
@RequestMapping(value = "/sop") @RequestMapping(value = "/sop")
@ResponseResultBody @ResponseResultBody
public class SopApiController { public class SopController {
@Resource @Resource
private SopService sopService; private SopService sopService;
...@@ -35,4 +37,12 @@ public class SopApiController { ...@@ -35,4 +37,12 @@ public class SopApiController {
return sop; return sop;
} }
@Operation(summary = "刷新实例状态", description = "找出实例中所有隐藏且频繁执行的节点,手动执行一次")
@GetMapping(value = "/inst/refresh/{instId}")
public Result<String> stageTrigger(@PathVariable("instId") String instId) {
SopStruct sop = sopService.loadSop(instId);
String rs = SopXxlJobUtil.triggerHidden(sop);
return Result.success("已刷新:" + rs);
}
} }
package cn.com.glsx.process.modules.sop.java.example; package cn.com.glsx.process.modules.sop.java.example;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.sop.CustomerInfo; import cn.com.glsx.process.modules.sop.CustomerInfo;
import cn.com.glsx.process.modules.sop.SopExecutorResult; import cn.com.glsx.process.modules.sop.SopExecutorResult;
import cn.com.glsx.process.modules.sop.SopHelper; import cn.com.glsx.process.modules.sop.SopHelper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.util.List;
import java.util.Map;
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!