Commit 1764602d by tiger

updateJob without date

1 parent 3bd38d56
......@@ -55,15 +55,12 @@ public class SopXxlJobUtil {
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();
boolean exists = job != null;
if (job == null) {
job = new XxlJobInfo();
}
job.setExecutorParam("");
job.setJobDesc("加载所有SOP实例任务");
job.setAuthor("admin");
......@@ -71,20 +68,27 @@ public class SopXxlJobUtil {
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);
if (exists) {
String update = XxlJobUtil.update(job);
SopXxlJobUtil.log(log, "【{}】任务更新,cron:{},result:{}", SOP_LOAD_JOB_ID, job.getScheduleConf(), update);
} else {
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);
boolean exists = job != null;
if (job == null) {
job = new XxlJobInfo();
}
// 重建job
job = new XxlJobInfo();
job.setExecutorParam(inst.getInstId());
job.setJobDesc(inst.getInstName());
job.setAuthor("admin");
......@@ -92,9 +96,14 @@ public class SopXxlJobUtil {
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);
if (exists) {
String update = XxlJobUtil.update(job);
SopXxlJobUtil.log(log, "【{}】Sop任务更新,cron:{},result:{}", jobBusId, job.getScheduleConf(), update);
} else {
String add = XxlJobUtil.add(job);
SopXxlJobUtil.log(log, "【{}】Sop任务启动,cron:{},result:{}", jobBusId, job.getScheduleConf(), add);
}
}
public static void initSopNodesJob(SopStruct sop) {
......@@ -115,8 +124,10 @@ public class SopXxlJobUtil {
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);
boolean exists = job != null;
if (job == null) {
job = new XxlJobInfo();
}
// 15 2/3 * * * ?
......@@ -128,7 +139,6 @@ public class SopXxlJobUtil {
// 前置节点,后置节点
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());
......@@ -136,7 +146,6 @@ public class SopXxlJobUtil {
String paramJson = JSONUtil.toJsonStr(params);
// 重建job
job = new XxlJobInfo();
job.setExecutorParam(paramJson);
job.setJobDesc(sop.getInst().getInstName() + "-" + node.getNodeName());
job.setAuthor("admin");
......@@ -144,8 +153,15 @@ public class SopXxlJobUtil {
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);
if (exists) {
String update = XxlJobUtil.update(job);
SopXxlJobUtil.log(log, "【{}】Sop节点任务更新,cron:{},result:{}", jobBusId, job.getScheduleConf(), update);
} else {
String add = XxlJobUtil.add(job);
SopXxlJobUtil.log(log, "【{}】Sop节点任务启动,cron:{},result:{}", jobBusId, job.getScheduleConf(), add);
}
}
public static String jobBusId(SopInst inst) {
......
package cn.com.glsx.process.job.xxljob.core;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class XxlJobInfo {
private int id; // 主键ID
private int jobGroup; // 执行器主键ID
private int id; // 主键ID
private int jobGroup; // 执行器主键ID
private String jobDesc;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+08:00")
private Date addTime;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+08:00")
private Date updateTime;
private String author; // 负责人
private String alarmEmail; // 报警邮件
private String scheduleType; // 调度类型
private String scheduleConf; // 调度配置,值含义取决于调度类型
private String misfireStrategy; // 调度过期策略 MisfireStrategyEnum
private String author; // 负责人
private String alarmEmail; // 报警邮件
private String scheduleType; // 调度类型
private String scheduleConf; // 调度配置,值含义取决于调度类型
private String misfireStrategy; // 调度过期策略 MisfireStrategyEnum
private String executorRouteStrategy; // 执行器路由策略
private String executorHandler; // 执行器,任务Handler名称
private String executorParam; // 执行器,任务参数
private String executorBlockStrategy; // 阻塞处理策略 ExecutorBlockStrategyEnum
private int executorTimeout; // 任务执行超时时间,单位秒
private int executorFailRetryCount; // 失败重试次数
private String glueType; // GLUE类型 #com.xxl.job.core.glue.GlueTypeEnum
private String glueSource; // GLUE源代码
private String glueRemark; // GLUE备注
private String executorRouteStrategy; // 执行器路由策略
private String executorHandler; // 执行器,任务Handler名称
private String executorParam; // 执行器,任务参数
private String executorBlockStrategy; // 阻塞处理策略 ExecutorBlockStrategyEnum
private int executorTimeout; // 任务执行超时时间,单位秒
private int executorFailRetryCount; // 失败重试次数
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+08:00")
private Date glueUpdatetime; // GLUE更新时间
private String glueType; // GLUE类型 #com.xxl.job.core.glue.GlueTypeEnum
private String glueSource; // GLUE源代码
private String glueRemark; // GLUE备注
private String childJobId; // 子任务ID,多个逗号分隔
private Date glueUpdatetime; // GLUE更新时间
private int triggerStatus; // 调度状态:0-停止,1-运行
private long triggerLastTime; // 上次调度时间
private long triggerNextTime; // 下次调度时间
private String childJobId; // 子任务ID,多个逗号分隔
private int triggerStatus; // 调度状态:0-停止,1-运行
private long triggerLastTime; // 上次调度时间
private long triggerNextTime; // 下次调度时间
private String busKey; //业务标识
private String busKey; // 业务标识
public int getId() {
return id;
......
......@@ -9,8 +9,8 @@ import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.util.GsonTool;
import com.xxl.job.core.util.XxlJobRemotingUtil;
import cn.hutool.http.HttpResponse;
......@@ -20,192 +20,197 @@ import lombok.extern.slf4j.Slf4j;
@Component
@Slf4j
public class XxlJobUtil {
public static final int SUCCESS_CODE = 200;
private static String adminAddresses;
private static String appname;
private static Integer groupId;
private static String accessToken;
private static String cookie = "";
@Value("${xxl.job.admin.addresses}")
public void setAdminAddresses(String adminAddresses) {
XxlJobUtil.adminAddresses = adminAddresses;
}
@Value("${xxl.job.accessToken}")
public void setAccessToken(String accessToken) {
XxlJobUtil.accessToken = accessToken;
}
@Value("${xxl.job.executor.appname}")
public void setAppname(String appname) {
XxlJobUtil.appname = appname;
}
@Value("${xxl.job.executor.groupId}")
public void setGroupId(Integer groupId) {
XxlJobUtil.groupId = groupId;
}
private static final String ADD_URL = "/jobinfo/postadd";
private static final String UPDATE_URL = "/jobinfo/postupdate";
private static final String REMOVE_URL = "/jobinfo/remove";
private static final String PAUSE_URL = "/jobinfo/stop";
private static final String START_URL = "/jobinfo/start";
private static final String ADD_AND_START_URL = "/jobinfo/trigger";
private static final String FINDBYBUSKEY = "/jobinfo/findByBusKey";
private static final String GET_GROUP_ID = "/jobgroup/pageList";
private static final String LOGIN = "/login";
/**
* 添加任务
*
* @param jobInfo 任务信息
* @return {@link String} 任务id
**/
public static String add(XxlJobInfo jobInfo) {
jobInfo.setJobGroup(groupId);
jobInfo.setGlueType("BEAN");
jobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
jobInfo.setExecutorRouteStrategy("FIRST");
jobInfo.setMisfireStrategy("DO_NOTHING");
jobInfo.setScheduleType(ScheduleTypeEnum.CRON.name());
return doPost(adminAddresses + ADD_URL, jobInfo, String.class);
}
/**
* 修改执行时间
*
* @return {@link String}
**/
public static String update(XxlJobInfo jobInfo) {
String busKey = jobInfo.getBusKey();
XxlJobInfo byBusKey = findByBusKey(busKey);
if (byBusKey != null) {
jobInfo.setId(byBusKey.getId());
return doPost(adminAddresses + UPDATE_URL, jobInfo, String.class);
}
return null;
}
/**
* 删除任务
*
* @param buskey 业务key
* @return {@link String}
**/
public static String remove(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + REMOVE_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 暂停任务
*
* @param buskey 业务key
* @return {@link String}
**/
public static String pause(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + PAUSE_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 开始任务
*
* @param buskey 业务key
* @return {@link String}
**/
public static String start(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + START_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 添加并启动
*
* @param buskey 业务key
* @return {@link String}
**/
public static String trigger(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + ADD_AND_START_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 根据业务id查询tigger
*
* @param busKey 任务信息
* @return {@link String}
**/
public static XxlJobInfo findByBusKey(String busKey) {
XxlJobInfo xxlJobInfo = doPost(adminAddresses + FINDBYBUSKEY + "?busKey=" + busKey + "&jobGroup=" + groupId, null, XxlJobInfo.class);
return xxlJobInfo;
}
/**
* 根据业务id查询jobGroup
*
* @return {@link String}
**/
@PostConstruct
public void findJobGroup() {
/*
* Map resmap = doPost(adminAddresses + GET_GROUP_ID + "?appname=" + appname, null, Map.class);
* System.out.println(resmap);
* Object data = resmap.get("data");
* if(data!=null){
* String jsonString = JSONObject.toJSONString(data);
* List<Map> maps = JSONObject.parseArray(jsonString, Map.class);
* if(CollectionUtils.isNotEmpty(maps)){
* Map map = maps.get(0);
* groupId= (Integer) map.get("id");
* }
* }
*/
}
public static <T> T doPost(String url, Object json, Class<T> clazz) {
log.info("请求url{},请求参数{} {}:{}", url, JSONObject.toJSONString(json), XxlJobRemotingUtil.XXL_JOB_ACCESS_TOKEN, accessToken);
ReturnT<T> returnT = XxlJobRemotingUtil.postBody(url, accessToken, 30, json, clazz);
if (returnT.getCode() != SUCCESS_CODE) {
log.info(String.format("【xxl-job】接口调用失败,错误码:%s,原因:%s", returnT.getCode(), returnT.getMsg()));
}
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;
}
public static final int SUCCESS_CODE = 200;
private static String adminAddresses;
private static String appname;
private static Integer groupId;
private static String accessToken;
private static String cookie = "";
@Value("${xxl.job.admin.addresses}")
public void setAdminAddresses(String adminAddresses) {
XxlJobUtil.adminAddresses = adminAddresses;
}
@Value("${xxl.job.accessToken}")
public void setAccessToken(String accessToken) {
XxlJobUtil.accessToken = accessToken;
}
@Value("${xxl.job.executor.appname}")
public void setAppname(String appname) {
XxlJobUtil.appname = appname;
}
@Value("${xxl.job.executor.groupId}")
public void setGroupId(Integer groupId) {
XxlJobUtil.groupId = groupId;
}
private static final String ADD_URL = "/jobinfo/postadd";
private static final String UPDATE_URL = "/jobinfo/postupdate";
private static final String REMOVE_URL = "/jobinfo/remove";
private static final String PAUSE_URL = "/jobinfo/stop";
private static final String START_URL = "/jobinfo/start";
private static final String ADD_AND_START_URL = "/jobinfo/trigger";
private static final String FINDBYBUSKEY = "/jobinfo/findByBusKey";
private static final String GET_GROUP_ID = "/jobgroup/pageList";
private static final String LOGIN = "/login";
/**
* 添加任务
*
* @param jobInfo 任务信息
* @return {@link String} 任务id
**/
public static String add(XxlJobInfo jobInfo) {
jobInfo.setJobGroup(groupId);
jobInfo.setGlueType("BEAN");
jobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
jobInfo.setExecutorRouteStrategy("FIRST");
jobInfo.setMisfireStrategy("DO_NOTHING");
jobInfo.setScheduleType(ScheduleTypeEnum.CRON.name());
return doPost(adminAddresses + ADD_URL, jobInfo, String.class);
}
/**
* 修改执行时间
*
* @return {@link String}
**/
public static String update(XxlJobInfo jobInfo) {
String busKey = jobInfo.getBusKey();
XxlJobInfo byBusKey = findByBusKey(busKey);
if (byBusKey != null) {
jobInfo.setId(byBusKey.getId());
jobInfo.setAddTime(null);
jobInfo.setUpdateTime(null);
jobInfo.setGlueUpdatetime(null);
return doPost(adminAddresses + UPDATE_URL, jobInfo, String.class);
}
return null;
}
/**
* 删除任务
*
* @param buskey 业务key
* @return {@link String}
**/
public static String remove(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + REMOVE_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 暂停任务
*
* @param buskey 业务key
* @return {@link String}
**/
public static String pause(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + PAUSE_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 开始任务
*
* @param buskey 业务key
* @return {@link String}
**/
public static String start(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + START_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 添加并启动
*
* @param buskey 业务key
* @return {@link String}
**/
public static String trigger(String buskey) {
XxlJobInfo byBusKey = findByBusKey(buskey);
if (byBusKey != null) {
return doPost(adminAddresses + ADD_AND_START_URL + "?id=" + byBusKey.getId(), null, String.class);
}
return null;
}
/**
* 根据业务id查询tigger
*
* @param busKey 任务信息
* @return {@link String}
**/
public static XxlJobInfo findByBusKey(String busKey) {
XxlJobInfo xxlJobInfo = doPost(adminAddresses + FINDBYBUSKEY + "?busKey=" + busKey + "&jobGroup=" + groupId, null, XxlJobInfo.class);
return xxlJobInfo;
}
/**
* 根据业务id查询jobGroup
*
* @return {@link String}
**/
@PostConstruct
public void findJobGroup() {
/*
* Map resmap = doPost(adminAddresses + GET_GROUP_ID + "?appname=" + appname, null, Map.class);
* System.out.println(resmap);
* Object data = resmap.get("data");
* if(data!=null){
* String jsonString = JSONObject.toJSONString(data);
* List<Map> maps = JSONObject.parseArray(jsonString, Map.class);
* if(CollectionUtils.isNotEmpty(maps)){
* Map map = maps.get(0);
* groupId= (Integer) map.get("id");
* }
* }
*/
}
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);
ReturnT<T> returnT = XxlJobRemotingUtil.postBody(url, accessToken, 30, json, clazz);
if (returnT.getCode() != SUCCESS_CODE) {
log.info(String.format("【xxl-job】接口调用失败,错误码:%s,原因:%s", returnT.getCode(), returnT.getMsg()));
}
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;
}
}
......@@ -9,6 +9,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
import cn.com.glsx.process.job.xxljob.param.SopInstNodeParam;
import cn.com.glsx.process.modules.entity.SopInstNode;
import cn.com.glsx.process.modules.model.SopStruct;
import cn.com.glsx.process.modules.service.SopService;
import cn.hutool.json.JSONUtil;
......@@ -18,7 +19,6 @@ import lombok.extern.slf4j.Slf4j;
@Component
public class SopInstNodeExecuteJobHandler {
@Resource
private SopService sopService;
......@@ -30,8 +30,16 @@ public class SopInstNodeExecuteJobHandler {
SopXxlJobUtil.log(log, "【执行Sop节点】{}", param);
SopStruct sop = sopService.loadSopByInstNodeId(param.getInstNodeId());
// TODO 执行sop里面的instNodeId节点。
SopInstNode node = sop.getInstNodeMap().get(param.getInstNodeId());
{
// 节点执行
}
// TODO 处理节点流程
// 创建所有节点任务
// SopXxlJobUtil.initSopNodeJob(sop);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!