mirror of
https://gitee.com/wangkang/udf.git
synced 2026-11-06 02:25:30 +00:00
添加手动触发方法
This commit is contained in:
+1
-1
@@ -63,7 +63,7 @@ public class SchClientHandle implements ApplicationContextAware {
|
||||
RmsJobResult result = new RmsJobResult();
|
||||
result.setParam(param);
|
||||
result.setClientReceiveTime(receiveTime);
|
||||
result.setFireInstanceId(param.getFireInstanceId());
|
||||
result.setId(param.getId());
|
||||
//执行(并且记录开始和结束时间)
|
||||
result.setClientStartExecuteTime(new Date());
|
||||
try {
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* TriggerType.java
|
||||
* Created at 2016-09-27
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.client;
|
||||
|
||||
/**
|
||||
* 描述 : TriggerType
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
public enum TriggerType {
|
||||
/**
|
||||
* 描述 : 手动触发
|
||||
*/
|
||||
MANUAL("manual"),
|
||||
/**
|
||||
* 描述 : 触发器触发
|
||||
*/
|
||||
TRIGGER("trigger");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Field value: 参数值
|
||||
* </p>
|
||||
*/
|
||||
private String value = null;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Description: 构造函数
|
||||
* </p>
|
||||
*
|
||||
* @param value 构造函数
|
||||
*/
|
||||
private TriggerType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Description: 放回int值
|
||||
* </p>
|
||||
*
|
||||
* @return value 放回int值
|
||||
*/
|
||||
public String value() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
+48
@@ -26,12 +26,24 @@ public class RmsJobParam implements Serializable {
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 描述 : 主键ID
|
||||
*/
|
||||
@ApiModelProperty(value = "主键ID", required = true, dataType = "string")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 描述 : 触发实例ID
|
||||
*/
|
||||
@ApiModelProperty(value = "触发实例ID", required = true, dataType = "string")
|
||||
private String fireInstanceId;
|
||||
|
||||
/**
|
||||
* 描述 : 触发方式
|
||||
*/
|
||||
@ApiModelProperty(value = "触发实例ID", required = true, dataType = "string")
|
||||
private String triggerType;
|
||||
|
||||
/**
|
||||
* 描述 : bean名称
|
||||
*/
|
||||
@@ -50,6 +62,42 @@ public class RmsJobParam implements Serializable {
|
||||
@ApiModelProperty(value = "作业参数", required = true, dataType = "object")
|
||||
private Map<String, Object> jobDataMap; //NOSONAR
|
||||
|
||||
/**
|
||||
* 描述 : 获取triggerType
|
||||
*
|
||||
* @return the triggerType
|
||||
*/
|
||||
public String getTriggerType() {
|
||||
return triggerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置triggerType
|
||||
*
|
||||
* @param triggerType the triggerType to set
|
||||
*/
|
||||
public void setTriggerType(String triggerType) {
|
||||
this.triggerType = triggerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取id
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置id
|
||||
*
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取async
|
||||
*
|
||||
|
||||
+11
-11
@@ -27,10 +27,10 @@ public class RmsJobResult implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 描述 : 执行ID
|
||||
* 描述 : 主键ID
|
||||
*/
|
||||
@ApiModelProperty(value = "执行ID", required = true, dataType = "string")
|
||||
private String fireInstanceId;
|
||||
@ApiModelProperty(value = "主键ID", required = true, dataType = "string")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 描述 : 参数
|
||||
@@ -177,21 +177,21 @@ public class RmsJobResult implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取fireInstanceId
|
||||
* 描述 : 获取id
|
||||
*
|
||||
* @return the fireInstanceId
|
||||
* @return the id
|
||||
*/
|
||||
public String getFireInstanceId() {
|
||||
return fireInstanceId;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置fireInstanceId
|
||||
* 描述 : 设置id
|
||||
*
|
||||
* @param fireInstanceId the fireInstanceId to set
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setFireInstanceId(String fireInstanceId) {
|
||||
this.fireInstanceId = fireInstanceId;
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class SchClientController implements ISchClientController {
|
||||
RmsJobResult result = new RmsJobResult();
|
||||
result.setParam(param);
|
||||
result.setClientReceiveTime(receiveTime);
|
||||
result.setFireInstanceId(param.getFireInstanceId());
|
||||
result.setId(param.getId());
|
||||
//执行(区分同步跟异步)
|
||||
if (param.getAsync()) {
|
||||
schClientHandle.asyncHandle(receiveTime, param);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.job;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
@@ -23,6 +25,7 @@ import com.egridcloud.udf.rms.Rms;
|
||||
import com.egridcloud.udf.scheduler.IRmsJobLog;
|
||||
import com.egridcloud.udf.scheduler.client.RmsJobStats;
|
||||
import com.egridcloud.udf.scheduler.client.SchException;
|
||||
import com.egridcloud.udf.scheduler.client.TriggerType;
|
||||
import com.egridcloud.udf.scheduler.client.domain.RmsJobParam;
|
||||
import com.egridcloud.udf.scheduler.client.domain.RmsJobResult;
|
||||
|
||||
@@ -45,26 +48,32 @@ public class RmsJob extends AbstractBaseJob {
|
||||
//从trigger中获得jobDataMap
|
||||
JobDataMap jobDataMap = jobExecutionContext.getTrigger().getJobDataMap();
|
||||
//获得必要字段
|
||||
String triggerId = jobDataMap.getString("triggerId");
|
||||
triggerId = StringUtils.isBlank(triggerId) ? UUID.randomUUID().toString() : triggerId;
|
||||
String triggerType = jobDataMap.getString("triggerType");
|
||||
triggerType = StringUtils.isBlank(triggerType) ? TriggerType.TRIGGER.value() : triggerType;
|
||||
String serviceCode = jobDataMap.getString("serviceCode");
|
||||
String beanName = jobDataMap.getString("beanName");
|
||||
Boolean async = jobDataMap.getBoolean("async");
|
||||
//校验
|
||||
if (StringUtils.isBlank(serviceCode)) {
|
||||
throw new SchException("serviceCode can not be empty");
|
||||
}
|
||||
if (StringUtils.isBlank(beanName)) {
|
||||
throw new SchException("beanName can not be empty");
|
||||
}
|
||||
//获得RMS
|
||||
Rms rms = this.getApplicationContext().getBean(Rms.class);
|
||||
//封装请求参数
|
||||
RmsJobParam rmsJobParam = new RmsJobParam();
|
||||
rmsJobParam.setId(triggerId);
|
||||
rmsJobParam.setTriggerType(triggerType);
|
||||
rmsJobParam.setFireInstanceId(jobExecutionContext.getFireInstanceId());
|
||||
rmsJobParam.setBeanName(beanName);
|
||||
rmsJobParam.setAsync(async);
|
||||
rmsJobParam.setJobDataMap(jobDataMap.getWrappedMap());
|
||||
//请求
|
||||
try {
|
||||
//校验
|
||||
if (StringUtils.isBlank(serviceCode)) {
|
||||
throw new SchException("serviceCode can not be empty");
|
||||
}
|
||||
if (StringUtils.isBlank(rmsJobParam.getBeanName())) {
|
||||
throw new SchException("beanName can not be empty");
|
||||
}
|
||||
//获得RMS
|
||||
Rms rms = this.getApplicationContext().getBean(Rms.class);
|
||||
//请求
|
||||
ResponseEntity<RestResponse<RmsJobResult>> result = rms.call(serviceCode, rmsJobParam, null,
|
||||
new ParameterizedTypeReference<RestResponse<RmsJobResult>>() {
|
||||
}, null);
|
||||
@@ -79,7 +88,7 @@ public class RmsJob extends AbstractBaseJob {
|
||||
//定义返回值
|
||||
RmsJobResult result = new RmsJobResult();
|
||||
result.setParam(rmsJobParam);
|
||||
result.setFireInstanceId(rmsJobParam.getFireInstanceId());
|
||||
result.setId(rmsJobParam.getId());
|
||||
result.setStats(RmsJobStats.ERROR.value());
|
||||
result.setErrorMsg(ExceptionUtils.getStackTrace(e));
|
||||
//记录
|
||||
|
||||
-15
@@ -136,21 +136,6 @@ public class JobService {
|
||||
this.s.getScheduler().deleteJob(jobKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 触发
|
||||
*
|
||||
* @param jobCode 作业代码
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
public void trigger(String jobCode) throws SchedulerException {
|
||||
//获得作业元数据
|
||||
JobDetailMeta jobDetailMeta = getJobDetailMeta(jobCode);
|
||||
// 设置jobkey
|
||||
JobKey jobKey = getJobKey(jobDetailMeta);
|
||||
// 触发
|
||||
this.s.getScheduler().triggerJob(jobKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 触发
|
||||
*
|
||||
|
||||
+25
@@ -6,8 +6,11 @@
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.web;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
@@ -94,4 +97,26 @@ public interface IJobController {
|
||||
public RestResponse<String> remove(@PathVariable String jobCode) //NOSONAR
|
||||
throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 描述 : 触发作业
|
||||
*
|
||||
* @param jobCode 作业代码
|
||||
* @param jobDataMap jobDataMap
|
||||
* @return 操作结果
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
@ApiOperation(value = "SCHEDULER_JOB_4", notes = "触发作业")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsApplicationName", value = "rms应用名称",
|
||||
required = true, dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsSign", value = "rms认证秘钥", required = true,
|
||||
dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "header", name = "rmsServiceCode", value = "rms接口编号",
|
||||
required = true, dataType = "string"),
|
||||
@ApiImplicitParam(paramType = "path", name = "jobCode", value = "作业代码", required = true,
|
||||
dataType = "string") })
|
||||
@RequestMapping(value = "trigger/{jobCode}", method = RequestMethod.POST)
|
||||
public RestResponse<String> trigger(@PathVariable String jobCode,
|
||||
@RequestBody Map<String, Object> jobDataMap) throws SchedulerException;
|
||||
|
||||
}
|
||||
|
||||
+29
@@ -6,12 +6,19 @@
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.web;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.egridcloud.udf.core.RestResponse;
|
||||
import com.egridcloud.udf.scheduler.client.TriggerType;
|
||||
import com.egridcloud.udf.scheduler.service.JobService;
|
||||
|
||||
/**
|
||||
@@ -49,4 +56,26 @@ public class JobController implements IJobController {
|
||||
return new RestResponse<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestResponse<String> trigger(@PathVariable String jobCode,
|
||||
@RequestBody Map<String, Object> jobDataMap) throws SchedulerException {
|
||||
//生成id
|
||||
String triggerId = UUID.randomUUID().toString();
|
||||
//生成jobDataMap
|
||||
JobDataMap jdm = null;
|
||||
//判断是否有jobDataMap
|
||||
if (MapUtils.isEmpty(jobDataMap)) {
|
||||
jdm = new JobDataMap();
|
||||
} else {
|
||||
jdm = new JobDataMap(jobDataMap);
|
||||
}
|
||||
//添加参数
|
||||
jdm.put("triggerId", triggerId);
|
||||
jdm.put("triggerType", TriggerType.MANUAL.value());
|
||||
//触发
|
||||
jobService.trigger(jobCode, jdm);
|
||||
//返回
|
||||
return new RestResponse<>(triggerId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user