mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-26 20:45:11 +00:00
更新
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* GeneralJobParam.java
|
||||
* Created at 2017-06-04
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler.client.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* 描述 : GeneralJobParam
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
@ApiModel(description = "通用job返回值")
|
||||
public class GeneralJobResult implements Serializable {
|
||||
|
||||
/**
|
||||
* 描述 : ID
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 描述 : 执行ID
|
||||
*/
|
||||
@ApiModelProperty(value = "执行ID", required = true, dataType = "string")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 描述 : 获取id
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置id
|
||||
*
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* IGeneralJobResult.java
|
||||
* Created at 2017-06-11
|
||||
* Created by Administrator
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.scheduler;
|
||||
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobResult;
|
||||
|
||||
/**
|
||||
* 描述 : IGeneralJobResult
|
||||
*
|
||||
* @author Administrator
|
||||
*
|
||||
*/
|
||||
public interface IGeneralJobResult {
|
||||
|
||||
/**
|
||||
* 描述 : save
|
||||
*
|
||||
* @param generalJobResult generalJobResult
|
||||
*/
|
||||
public void save(GeneralJobResult generalJobResult);
|
||||
|
||||
}
|
||||
+19
-4
@@ -16,8 +16,10 @@ import org.springframework.http.ResponseEntity;
|
||||
|
||||
import com.egridcloud.udf.core.RestResponse;
|
||||
import com.egridcloud.udf.rms.Rms;
|
||||
import com.egridcloud.udf.scheduler.IGeneralJobResult;
|
||||
import com.egridcloud.udf.scheduler.SchException;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobParam;
|
||||
import com.egridcloud.udf.scheduler.client.domain.GeneralJobResult;
|
||||
|
||||
/**
|
||||
* 描述 : GeneralJob
|
||||
@@ -51,19 +53,32 @@ public class GeneralJob extends AbstractBaseJob {
|
||||
//请求
|
||||
try {
|
||||
//拿到结果
|
||||
ResponseEntity<RestResponse<String>> result = rms.call(serviceCode, generalJobParam, null,
|
||||
new ParameterizedTypeReference<RestResponse<String>>() {
|
||||
ResponseEntity<RestResponse<GeneralJobResult>> result = rms.call(serviceCode, generalJobParam,
|
||||
null, new ParameterizedTypeReference<RestResponse<GeneralJobResult>>() {
|
||||
}, null);
|
||||
//判断http状态
|
||||
if (result.getStatusCode() != HttpStatus.OK) {
|
||||
throw new SchException(result.getStatusCode().toString());
|
||||
}
|
||||
//设置结果
|
||||
jobExecutionContext.setResult(result.getBody().getResult());
|
||||
//记录结果
|
||||
saveGeneralJobResult(result.getBody().getResult());
|
||||
} catch (Exception e) {
|
||||
//抛出异常
|
||||
throw new JobExecutionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 保存
|
||||
*
|
||||
* @param result result
|
||||
*/
|
||||
private void saveGeneralJobResult(GeneralJobResult result) {
|
||||
IGeneralJobResult generalJobResultService =
|
||||
this.getApplicationContext().getBean(IGeneralJobResult.class);
|
||||
if (generalJobResultService != null) {
|
||||
generalJobResultService.save(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ public class JobDetailMeta implements Serializable {
|
||||
/**
|
||||
* 描述 : 组别
|
||||
*/
|
||||
private String group = "default";;
|
||||
private String group = "default";
|
||||
|
||||
/**
|
||||
* 描述 : 类型
|
||||
|
||||
+16
@@ -151,6 +151,22 @@ public class JobService {
|
||||
this.s.getScheduler().triggerJob(jobKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 触发
|
||||
*
|
||||
* @param jobCode 作业代码
|
||||
* @param jobDataMap 作业数据
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
public void trigger(String jobCode, JobDataMap jobDataMap) throws SchedulerException {
|
||||
//获得作业元数据
|
||||
JobDetailMeta jobDetailMeta = getJobDetailMeta(jobCode);
|
||||
// 设置jobkey
|
||||
JobKey jobKey = getJobKey(jobDetailMeta);
|
||||
// 触发
|
||||
this.s.getScheduler().triggerJob(jobKey, jobDataMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 暂停
|
||||
*
|
||||
|
||||
+41
-200
@@ -90,44 +90,12 @@ public class TriggerListenerService {
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
public void saveTriggerFired(JobExecutionContext context) throws SchedulerException {
|
||||
|
||||
// 状态和异常信息
|
||||
String status = "triggering";
|
||||
String exceptionDetail = null;
|
||||
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
|
||||
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得计划任务实例
|
||||
Scheduler s = context.getScheduler();
|
||||
|
||||
// 删除当前ID已经有的记录
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
}
|
||||
|
||||
// 写入新的记录
|
||||
ScheduledTriggerLog tstl = new ScheduledTriggerLog();
|
||||
tstl.setLogid(context.getFireInstanceId());
|
||||
tstl.setScheduledFireTime(context.getScheduledFireTime());
|
||||
tstl.setFireTime(context.getFireTime());
|
||||
tstl.setEndTime(null);
|
||||
tstl.setJobRunTime(null);
|
||||
tstl.setStatus("triggering");
|
||||
tstl.setResult(null);
|
||||
tstl.setErrorMsg(null);
|
||||
tstl.setTriggerName(context.getTrigger().getKey().getName());
|
||||
tstl.setTriggerGroup(context.getTrigger().getKey().getGroup());
|
||||
tstl.setJobName(context.getJobDetail().getKey().getName());
|
||||
tstl.setJobGroup(context.getJobDetail().getKey().getGroup());
|
||||
tstl.setJobClass(context.getJobDetail().getJobClass().getName());
|
||||
tstl.setThreadGroupName(Thread.currentThread().getThreadGroup().getName());
|
||||
tstl.setThreadId(Long.toString(Thread.currentThread().getId()));
|
||||
tstl.setThreadName(Thread.currentThread().getName());
|
||||
tstl.setThreadPriority(Long.toString(Thread.currentThread().getPriority()));
|
||||
tstl.setScheduledId(s.getSchedulerInstanceId());
|
||||
tstl.setScheduledName(s.getSchedulerName());
|
||||
tstl.setCreateDate(new Date());
|
||||
if (triggerLog != null) {
|
||||
triggerLog.save(tstl);
|
||||
if (this.schedulerConfig.getLogFlag() && this.schedulerConfig.getLogDetailFlag()) {
|
||||
save(context, status, null, exceptionDetail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,47 +109,14 @@ public class TriggerListenerService {
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
public boolean saveVetoJobExecution(JobExecutionContext context) throws SchedulerException {
|
||||
|
||||
// 是否否决
|
||||
boolean vetoed = false;
|
||||
|
||||
// 状态和异常信息
|
||||
String status = "vetoed(" + vetoed + ")";
|
||||
String exceptionDetail = null;
|
||||
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
|
||||
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
|
||||
return vetoed;
|
||||
}
|
||||
|
||||
// 获得计划任务实例
|
||||
Scheduler s = context.getScheduler();
|
||||
|
||||
// 删除当前ID已经有的记录
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
}
|
||||
|
||||
// 写入新的记录
|
||||
ScheduledTriggerLog tstl = new ScheduledTriggerLog();
|
||||
tstl.setLogid(context.getFireInstanceId());
|
||||
tstl.setScheduledFireTime(context.getScheduledFireTime());
|
||||
tstl.setFireTime(context.getFireTime());
|
||||
tstl.setEndTime(null);
|
||||
tstl.setJobRunTime(null);
|
||||
tstl.setStatus("vetoed(" + vetoed + ")");
|
||||
tstl.setResult(null);
|
||||
tstl.setErrorMsg(null);
|
||||
tstl.setTriggerName(context.getTrigger().getKey().getName());
|
||||
tstl.setTriggerGroup(context.getTrigger().getKey().getGroup());
|
||||
tstl.setJobName(context.getJobDetail().getKey().getName());
|
||||
tstl.setJobGroup(context.getJobDetail().getKey().getGroup());
|
||||
tstl.setJobClass(context.getJobDetail().getJobClass().getName());
|
||||
tstl.setThreadGroupName(Thread.currentThread().getThreadGroup().getName());
|
||||
tstl.setThreadId(Long.toString(Thread.currentThread().getId()));
|
||||
tstl.setThreadName(Thread.currentThread().getName());
|
||||
tstl.setThreadPriority(Long.toString(Thread.currentThread().getPriority()));
|
||||
tstl.setScheduledId(s.getSchedulerInstanceId());
|
||||
tstl.setScheduledName(s.getSchedulerName());
|
||||
tstl.setCreateDate(new Date());
|
||||
if (triggerLog != null) {
|
||||
triggerLog.save(tstl);
|
||||
if (this.schedulerConfig.getLogFlag() && this.schedulerConfig.getLogDetailFlag()) {
|
||||
save(context, status, null, exceptionDetail);
|
||||
}
|
||||
return vetoed;
|
||||
}
|
||||
@@ -195,44 +130,12 @@ public class TriggerListenerService {
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
public void saveJobToBeExecuted(JobExecutionContext context) throws SchedulerException {
|
||||
|
||||
// 状态和异常信息
|
||||
String status = "toBeExecuted";
|
||||
String exceptionDetail = null;
|
||||
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
|
||||
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得计划任务实例
|
||||
Scheduler s = context.getScheduler();
|
||||
|
||||
// 删除当前ID已经有的记录
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
}
|
||||
|
||||
// 写入新的记录
|
||||
ScheduledTriggerLog tstl = new ScheduledTriggerLog();
|
||||
tstl.setLogid(context.getFireInstanceId());
|
||||
tstl.setScheduledFireTime(context.getScheduledFireTime());
|
||||
tstl.setFireTime(context.getFireTime());
|
||||
tstl.setEndTime(null);
|
||||
tstl.setJobRunTime(null);
|
||||
tstl.setStatus("toBeExecuted");
|
||||
tstl.setResult(null);
|
||||
tstl.setErrorMsg(null);
|
||||
tstl.setTriggerName(context.getTrigger().getKey().getName());
|
||||
tstl.setTriggerGroup(context.getTrigger().getKey().getGroup());
|
||||
tstl.setJobName(context.getJobDetail().getKey().getName());
|
||||
tstl.setJobGroup(context.getJobDetail().getKey().getGroup());
|
||||
tstl.setJobClass(context.getJobDetail().getJobClass().getName());
|
||||
tstl.setThreadGroupName(Thread.currentThread().getThreadGroup().getName());
|
||||
tstl.setThreadId(Long.toString(Thread.currentThread().getId()));
|
||||
tstl.setThreadName(Thread.currentThread().getName());
|
||||
tstl.setThreadPriority(Long.toString(Thread.currentThread().getPriority()));
|
||||
tstl.setScheduledId(s.getSchedulerInstanceId());
|
||||
tstl.setScheduledName(s.getSchedulerName());
|
||||
tstl.setCreateDate(new Date());
|
||||
if (triggerLog != null) {
|
||||
triggerLog.save(tstl);
|
||||
if (this.schedulerConfig.getLogFlag() && this.schedulerConfig.getLogDetailFlag()) {
|
||||
save(context, status, null, exceptionDetail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,40 +148,11 @@ public class TriggerListenerService {
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
public void saveJobExecutionVetoed(JobExecutionContext context) throws SchedulerException {
|
||||
|
||||
// 获得计划任务实例
|
||||
Scheduler s = context.getScheduler();
|
||||
|
||||
// 删除当前ID已经有的记录
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
}
|
||||
|
||||
// 状态和异常信息
|
||||
String status = "executionVetoed";
|
||||
String exceptionDetail = null;
|
||||
// 写入新的记录
|
||||
ScheduledTriggerLog tstl = new ScheduledTriggerLog();
|
||||
tstl.setLogid(context.getFireInstanceId());
|
||||
tstl.setScheduledFireTime(context.getScheduledFireTime());
|
||||
tstl.setFireTime(context.getFireTime());
|
||||
tstl.setEndTime(null);
|
||||
tstl.setJobRunTime(null);
|
||||
tstl.setStatus("executionVetoed");
|
||||
tstl.setResult(null);
|
||||
tstl.setErrorMsg(null);
|
||||
tstl.setTriggerName(context.getTrigger().getKey().getName());
|
||||
tstl.setTriggerGroup(context.getTrigger().getKey().getGroup());
|
||||
tstl.setJobName(context.getJobDetail().getKey().getName());
|
||||
tstl.setJobGroup(context.getJobDetail().getKey().getGroup());
|
||||
tstl.setJobClass(context.getJobDetail().getJobClass().getName());
|
||||
tstl.setThreadGroupName(Thread.currentThread().getThreadGroup().getName());
|
||||
tstl.setThreadId(Long.toString(Thread.currentThread().getId()));
|
||||
tstl.setThreadName(Thread.currentThread().getName());
|
||||
tstl.setThreadPriority(Long.toString(Thread.currentThread().getPriority()));
|
||||
tstl.setScheduledId(s.getSchedulerInstanceId());
|
||||
tstl.setScheduledName(s.getSchedulerName());
|
||||
tstl.setCreateDate(new Date());
|
||||
if (triggerLog != null) {
|
||||
triggerLog.save(tstl);
|
||||
}
|
||||
save(context, status, null, exceptionDetail);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,58 +166,21 @@ public class TriggerListenerService {
|
||||
*/
|
||||
public void saveJobWasExecuted(JobExecutionContext context, JobExecutionException jobException)
|
||||
throws SchedulerException {
|
||||
|
||||
// 异常信息
|
||||
// 状态和异常信息
|
||||
String status = "executed";
|
||||
String exceptionDetail = null;
|
||||
|
||||
// 如果作业异常,则放入信息到result中
|
||||
if (null != jobException) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("status", "error");
|
||||
result.put("jobException", jobException);
|
||||
context.setResult(result);
|
||||
|
||||
// 获得异常信息
|
||||
exceptionDetail = ExceptionUtils.getStackTrace(jobException);
|
||||
}
|
||||
|
||||
// 是否记录执行历史(true记录,false不记录) , 是否详细记录执行历史(true记录,false不记录)
|
||||
if (!this.schedulerConfig.getLogFlag() || !this.schedulerConfig.getLogDetailFlag()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获得计划任务实例
|
||||
Scheduler s = context.getScheduler();
|
||||
|
||||
// 删除当前ID已经有的记录
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
}
|
||||
|
||||
// 写入新的记录
|
||||
ScheduledTriggerLog tstl = new ScheduledTriggerLog();
|
||||
tstl.setLogid(context.getFireInstanceId());
|
||||
tstl.setScheduledFireTime(context.getScheduledFireTime());
|
||||
tstl.setFireTime(context.getFireTime());
|
||||
tstl.setEndTime(new Date());
|
||||
tstl.setJobRunTime(context.getJobRunTime());
|
||||
tstl.setStatus("executed");
|
||||
tstl.setResult(null);
|
||||
tstl.setErrorMsg(exceptionDetail);
|
||||
tstl.setTriggerName(context.getTrigger().getKey().getName());
|
||||
tstl.setTriggerGroup(context.getTrigger().getKey().getGroup());
|
||||
tstl.setJobName(context.getJobDetail().getKey().getName());
|
||||
tstl.setJobGroup(context.getJobDetail().getKey().getGroup());
|
||||
tstl.setJobClass(context.getJobDetail().getJobClass().getName());
|
||||
tstl.setThreadGroupName(Thread.currentThread().getThreadGroup().getName());
|
||||
tstl.setThreadId(Long.toString(Thread.currentThread().getId()));
|
||||
tstl.setThreadName(Thread.currentThread().getName());
|
||||
tstl.setThreadPriority(Long.toString(Thread.currentThread().getPriority()));
|
||||
tstl.setScheduledId(s.getSchedulerInstanceId());
|
||||
tstl.setScheduledName(s.getSchedulerName());
|
||||
tstl.setCreateDate(new Date());
|
||||
if (triggerLog != null) {
|
||||
triggerLog.save(tstl);
|
||||
if (this.schedulerConfig.getLogFlag() && this.schedulerConfig.getLogDetailFlag()) {
|
||||
save(context, status, null, exceptionDetail);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,36 +197,38 @@ public class TriggerListenerService {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void saveTriggerComplete(JobExecutionContext context,
|
||||
CompletedExecutionInstruction triggerInstructionCode) throws SchedulerException {
|
||||
|
||||
// 状态和异常信息
|
||||
String status = "complete";
|
||||
String exceptionDetail = null;
|
||||
|
||||
// 获得result
|
||||
Object o = context.getResult();
|
||||
if (null != o && o instanceof Map) {
|
||||
Map<String, Object> result = (Map<String, Object>) o;
|
||||
status = result.get("status").toString();
|
||||
JobExecutionException jobException = (JobExecutionException) result.get("jobException");
|
||||
|
||||
// 获得异常信息
|
||||
exceptionDetail = ExceptionUtils.getStackTrace(jobException);
|
||||
}
|
||||
|
||||
// 是否记录执行历史(true记录,false不记录)
|
||||
if (!this.schedulerConfig.getLogFlag()) {
|
||||
return;
|
||||
if (this.schedulerConfig.getLogFlag()) {
|
||||
save(context, status, triggerInstructionCode.toString(), exceptionDetail);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : build
|
||||
*
|
||||
* @param context context
|
||||
* @param status status
|
||||
* @param result result
|
||||
* @param exceptionDetail exceptionDetail
|
||||
* @throws SchedulerException SchedulerException
|
||||
*/
|
||||
private void save(JobExecutionContext context, String status, String result,
|
||||
String exceptionDetail) throws SchedulerException {
|
||||
// 获得计划任务实例
|
||||
Scheduler s = context.getScheduler();
|
||||
|
||||
// 删除当前ID已经有的记录
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
}
|
||||
|
||||
// 写入新的记录
|
||||
//构造
|
||||
ScheduledTriggerLog tstl = new ScheduledTriggerLog();
|
||||
tstl.setLogid(context.getFireInstanceId());
|
||||
tstl.setScheduledFireTime(context.getScheduledFireTime());
|
||||
@@ -397,7 +236,7 @@ public class TriggerListenerService {
|
||||
tstl.setEndTime(new Date());
|
||||
tstl.setJobRunTime(context.getJobRunTime());
|
||||
tstl.setStatus(status);
|
||||
tstl.setResult(triggerInstructionCode.toString());
|
||||
tstl.setResult(result);
|
||||
tstl.setErrorMsg(exceptionDetail);
|
||||
tstl.setTriggerName(context.getTrigger().getKey().getName());
|
||||
tstl.setTriggerGroup(context.getTrigger().getKey().getGroup());
|
||||
@@ -412,7 +251,9 @@ public class TriggerListenerService {
|
||||
tstl.setScheduledName(s.getSchedulerName());
|
||||
tstl.setCreateDate(new Date());
|
||||
if (triggerLog != null) {
|
||||
triggerLog.delete(context.getFireInstanceId());
|
||||
triggerLog.save(tstl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user