1、任务日志表"调度状态"和"执行状态"统一为int值,修改对应表结构;

2、分布式调度器更名;
pull/1/head
xueli.xue 8 years ago
parent b590a65c4a
commit 725d1f4fe5

@ -2,7 +2,7 @@ package com.xxl.job.admin.core.biz;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil;
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
import com.xxl.job.core.biz.AdminBiz;
import com.xxl.job.core.biz.model.HandleCallbackParam;
import com.xxl.job.core.biz.model.ReturnT;
@ -24,7 +24,7 @@ public class AdminBizImpl implements AdminBiz {
public ReturnT<String> callback(HandleCallbackParam handleCallbackParam) {
// valid log item
XxlJobLog log = DynamicSchedulerUtil.xxlJobLogDao.load(handleCallbackParam.getLogId());
XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(handleCallbackParam.getLogId());
if (log == null) {
return new ReturnT(ReturnT.FAIL_CODE, "log item not found.");
}
@ -32,17 +32,17 @@ public class AdminBizImpl implements AdminBiz {
// trigger success, to trigger child job, and avoid repeat trigger child job
String childTriggerMsg = null;
if (ReturnT.SUCCESS_CODE==handleCallbackParam.getCode() && ReturnT.SUCCESS_CODE!=log.getHandleCode()) {
XxlJobInfo xxlJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
XxlJobInfo xxlJobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
if (xxlJobInfo!=null && StringUtils.isNotBlank(xxlJobInfo.getChildJobKey())) {
childTriggerMsg = "<hr>";
String[] childJobKeys = xxlJobInfo.getChildJobKey().split(",");
for (int i = 0; i < childJobKeys.length; i++) {
String[] jobKeyArr = childJobKeys[i].split("_");
if (jobKeyArr!=null && jobKeyArr.length==2) {
XxlJobInfo childJobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(Integer.valueOf(jobKeyArr[0]), jobKeyArr[1]);
XxlJobInfo childJobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.load(Integer.valueOf(jobKeyArr[0]), jobKeyArr[1]);
if (childJobInfo!=null) {
try {
boolean ret = DynamicSchedulerUtil.triggerJob(childJobInfo.getJobName(), String.valueOf(childJobInfo.getJobGroup()));
boolean ret = XxlJobDynamicScheduler.triggerJob(childJobInfo.getJobName(), String.valueOf(childJobInfo.getJobGroup()));
// add msg
childTriggerMsg += MessageFormat.format("<br> {0}/{1} 触发子任务成功, 子任务Key: {2}, status: {3}, 子任务描述: {4}",
@ -79,7 +79,7 @@ public class AdminBizImpl implements AdminBiz {
log.setHandleTime(new Date());
log.setHandleCode(handleCallbackParam.getCode());
log.setHandleMsg(handleMsg.toString());
DynamicSchedulerUtil.xxlJobLogDao.updateHandleInfo(log);
XxlJobDynamicScheduler.xxlJobLogDao.updateHandleInfo(log);
return new ReturnT(ReturnT.SUCCESS_CODE, null);
}

@ -3,9 +3,9 @@ package com.xxl.job.admin.core.jobbean;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
import com.xxl.job.admin.core.thread.JobMonitorHelper;
import com.xxl.job.admin.core.thread.JobRegistryHelper;
import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil;
import com.xxl.job.core.biz.ExecutorBiz;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.biz.model.TriggerParam;
@ -36,12 +36,12 @@ public class RemoteHttpJobBean extends QuartzJobBean {
throws JobExecutionException {
JobKey jobKey = context.getTrigger().getJobKey();
XxlJobInfo jobInfo = DynamicSchedulerUtil.xxlJobInfoDao.load(Integer.valueOf(jobKey.getGroup()), jobKey.getName());
XxlJobInfo jobInfo = XxlJobDynamicScheduler.xxlJobInfoDao.load(Integer.valueOf(jobKey.getGroup()), jobKey.getName());
// save log
XxlJobLog jobLog = new XxlJobLog();
jobLog.setJobGroup(jobInfo.getJobGroup());
jobLog.setJobName(jobInfo.getJobName());
DynamicSchedulerUtil.xxlJobLogDao.save(jobLog);
XxlJobDynamicScheduler.xxlJobLogDao.save(jobLog);
logger.debug(">>>>>>>>>>> xxl-job trigger start, jobId:{}", jobLog.getId());
// admin address
@ -50,7 +50,7 @@ public class RemoteHttpJobBean extends QuartzJobBean {
if (adminAddressList!=null) {
adminAddressSet.addAll(adminAddressList);
}
adminAddressSet.add(DynamicSchedulerUtil.getCallbackAddress());
adminAddressSet.add(XxlJobDynamicScheduler.getCallbackAddress());
// update trigger info 1/2
jobLog.setTriggerTime(new Date());
@ -68,7 +68,7 @@ public class RemoteHttpJobBean extends QuartzJobBean {
// parse address
List<String> addressList = new ArrayList<String>();
XxlJobGroup group = DynamicSchedulerUtil.xxlJobGroupDao.load(Integer.valueOf(jobInfo.getJobGroup()));
XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(Integer.valueOf(jobInfo.getJobGroup()));
if (group!=null) {
addressList = JobRegistryHelper.discover(RegistHelper.RegistType.EXECUTOR.name(), group.getAppName());
}
@ -82,7 +82,7 @@ public class RemoteHttpJobBean extends QuartzJobBean {
// update trigger info 2/2
jobLog.setTriggerCode(responseModel.getCode());
jobLog.setTriggerMsg(responseModel.getMsg());
DynamicSchedulerUtil.xxlJobLogDao.updateTriggerInfo(jobLog);
XxlJobDynamicScheduler.xxlJobLogDao.updateTriggerInfo(jobLog);
// monitor triger
JobMonitorHelper.monitor(jobLog.getId());

@ -29,13 +29,13 @@ import java.util.*;
* base quartz scheduler util
* @author xuxueli 2015-12-19 16:13:53
*/
public final class DynamicSchedulerUtil implements ApplicationContextAware, InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class);
public final class XxlJobDynamicScheduler implements ApplicationContextAware, InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(XxlJobDynamicScheduler.class);
// Scheduler
private static Scheduler scheduler;
public static void setScheduler(Scheduler scheduler) {
DynamicSchedulerUtil.scheduler = scheduler;
XxlJobDynamicScheduler.scheduler = scheduler;
}
// trigger callback address
@ -84,10 +84,10 @@ public final class DynamicSchedulerUtil implements ApplicationContextAware, Init
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
DynamicSchedulerUtil.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class);
DynamicSchedulerUtil.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class);
DynamicSchedulerUtil.xxlJobRegistryDao = applicationContext.getBean(IXxlJobRegistryDao.class);
DynamicSchedulerUtil.xxlJobGroupDao = applicationContext.getBean(IXxlJobGroupDao.class);
XxlJobDynamicScheduler.xxlJobLogDao = applicationContext.getBean(IXxlJobLogDao.class);
XxlJobDynamicScheduler.xxlJobInfoDao = applicationContext.getBean(IXxlJobInfoDao.class);
XxlJobDynamicScheduler.xxlJobRegistryDao = applicationContext.getBean(IXxlJobRegistryDao.class);
XxlJobDynamicScheduler.xxlJobGroupDao = applicationContext.getBean(IXxlJobGroupDao.class);
}
@Override

@ -3,7 +3,7 @@ package com.xxl.job.admin.core.thread;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.model.XxlJobLog;
import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil;
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
import com.xxl.job.admin.core.util.MailUtil;
import com.xxl.job.core.biz.model.ReturnT;
import org.slf4j.Logger;
@ -38,7 +38,7 @@ public class JobMonitorHelper {
Integer jobLogId = JobMonitorHelper.helper.queue.take();
if (jobLogId != null && jobLogId > 0) {
logger.info(">>>>>>>>>>> job monitor heat success, JobLogId:{}", jobLogId);
XxlJobLog log = DynamicSchedulerUtil.xxlJobLogDao.load(jobLogId);
XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(jobLogId);
if (log!=null) {
if (ReturnT.SUCCESS_CODE==log.getTriggerCode() && log.getHandleCode()==0) {
// running
@ -53,13 +53,13 @@ public class JobMonitorHelper {
// pass
}
if (ReturnT.FAIL_CODE == log.getTriggerCode()|| ReturnT.FAIL_CODE==log.getHandleCode()) {
XxlJobInfo info = DynamicSchedulerUtil.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
XxlJobInfo info = XxlJobDynamicScheduler.xxlJobInfoDao.load(log.getJobGroup(), log.getJobName());
if (info!=null && info.getAlarmEmail()!=null && info.getAlarmEmail().trim().length()>0) {
Set<String> emailSet = new HashSet<String>(Arrays.asList(info.getAlarmEmail().split(",")));
for (String email: emailSet) {
String title = "《调度监控报警》(任务调度中心XXL-JOB)";
XxlJobGroup group = DynamicSchedulerUtil.xxlJobGroupDao.load(Integer.valueOf(info.getJobGroup()));
XxlJobGroup group = XxlJobDynamicScheduler.xxlJobGroupDao.load(Integer.valueOf(info.getJobGroup()));
String content = MessageFormat.format("任务调度失败, 执行器名称:{0}, 任务描述:{1}.", group!=null?group.getTitle():"null", info.getJobDesc());
MailUtil.sendMail(email, title, content, false, null);
}

@ -1,7 +1,7 @@
package com.xxl.job.admin.core.thread;
import com.xxl.job.admin.core.model.XxlJobRegistry;
import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil;
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
import com.xxl.job.core.registry.RegistHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -28,15 +28,15 @@ public class JobRegistryHelper {
while (true) {
try {
// registry admin
int ret = DynamicSchedulerUtil.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), DynamicSchedulerUtil.getCallbackAddress());
int ret = XxlJobDynamicScheduler.xxlJobRegistryDao.registryUpdate(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobDynamicScheduler.getCallbackAddress());
if (ret < 1) {
DynamicSchedulerUtil.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), DynamicSchedulerUtil.getCallbackAddress());
XxlJobDynamicScheduler.xxlJobRegistryDao.registrySave(RegistHelper.RegistType.ADMIN.name(), RegistHelper.RegistType.ADMIN.name(), XxlJobDynamicScheduler.getCallbackAddress());
}
// fresh registry map
ConcurrentHashMap<String, List<String>> temp = new ConcurrentHashMap<String, List<String>>();
DynamicSchedulerUtil.xxlJobRegistryDao.removeDead(RegistHelper.TIMEOUT*2);
List<XxlJobRegistry> list = DynamicSchedulerUtil.xxlJobRegistryDao.findAll(RegistHelper.TIMEOUT*2);
XxlJobDynamicScheduler.xxlJobRegistryDao.removeDead(RegistHelper.TIMEOUT*2);
List<XxlJobRegistry> list = XxlJobDynamicScheduler.xxlJobRegistryDao.findAll(RegistHelper.TIMEOUT*2);
if (list != null) {
for (XxlJobRegistry item: list) {
String groupKey = makeGroupKey(item.getRegistryGroup(), item.getRegistryKey());

@ -2,7 +2,7 @@ package com.xxl.job.admin.service.impl;
import com.xxl.job.admin.core.model.XxlJobGroup;
import com.xxl.job.admin.core.model.XxlJobInfo;
import com.xxl.job.admin.core.schedule.DynamicSchedulerUtil;
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
import com.xxl.job.admin.dao.IXxlJobGroupDao;
import com.xxl.job.admin.dao.IXxlJobInfoDao;
import com.xxl.job.admin.dao.IXxlJobLogDao;
@ -51,7 +51,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
// fill job info
if (list!=null && list.size()>0) {
for (XxlJobInfo jobInfo : list) {
DynamicSchedulerUtil.fillJobInfo(jobInfo);
XxlJobDynamicScheduler.fillJobInfo(jobInfo);
}
}
@ -106,7 +106,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
// generate jobName
String jobName = FastDateFormat.getInstance("yyyyMMddHHmmssSSSS").format(new Date());
try {
if (DynamicSchedulerUtil.checkExists(jobName, String.valueOf(jobGroup))) {
if (XxlJobDynamicScheduler.checkExists(jobName, String.valueOf(jobGroup))) {
return new ReturnT<String>(500, "系统繁忙,请稍后重试");
}
} catch (SchedulerException e1) {
@ -131,7 +131,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
try {
// add job 2 quartz
boolean result = DynamicSchedulerUtil.addJob(String.valueOf(jobGroup), jobName, jobCron);
boolean result = XxlJobDynamicScheduler.addJob(String.valueOf(jobGroup), jobName, jobCron);
if (result) {
xxlJobInfoDao.save(jobInfo);
return ReturnT.SUCCESS;
@ -200,7 +200,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
try {
// fresh quartz
boolean ret = DynamicSchedulerUtil.rescheduleJob(String.valueOf(jobGroup), jobName, jobCron);
boolean ret = XxlJobDynamicScheduler.rescheduleJob(String.valueOf(jobGroup), jobName, jobCron);
if (ret) {
xxlJobInfoDao.update(jobInfo);
return ReturnT.SUCCESS;
@ -216,7 +216,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
@Override
public ReturnT<String> remove(int jobGroup, String jobName) {
try {
DynamicSchedulerUtil.removeJob(jobName, String.valueOf(jobGroup));
XxlJobDynamicScheduler.removeJob(jobName, String.valueOf(jobGroup));
xxlJobInfoDao.delete(jobGroup, jobName);
xxlJobLogDao.delete(jobGroup, jobName);
xxlJobLogGlueDao.delete(jobGroup, jobName);
@ -230,7 +230,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
@Override
public ReturnT<String> pause(int jobGroup, String jobName) {
try {
DynamicSchedulerUtil.pauseJob(jobName, String.valueOf(jobGroup)); // jobStatus do not store
XxlJobDynamicScheduler.pauseJob(jobName, String.valueOf(jobGroup)); // jobStatus do not store
return ReturnT.SUCCESS;
} catch (SchedulerException e) {
e.printStackTrace();
@ -241,7 +241,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
@Override
public ReturnT<String> resume(int jobGroup, String jobName) {
try {
DynamicSchedulerUtil.resumeJob(jobName, String.valueOf(jobGroup));
XxlJobDynamicScheduler.resumeJob(jobName, String.valueOf(jobGroup));
return ReturnT.SUCCESS;
} catch (SchedulerException e) {
e.printStackTrace();
@ -252,7 +252,7 @@ public class XxlJobServiceImpl implements IXxlJobService {
@Override
public ReturnT<String> triggerJob(int jobGroup, String jobName) {
try {
DynamicSchedulerUtil.triggerJob(jobName, String.valueOf(jobGroup));
XxlJobDynamicScheduler.triggerJob(jobName, String.valueOf(jobGroup));
return ReturnT.SUCCESS;
} catch (SchedulerException e) {
e.printStackTrace();

@ -14,7 +14,7 @@
</bean>
<!-- 协同-调度器 -->
<bean id="dynamicSchedulerUtil" class="com.xxl.job.admin.core.schedule.DynamicSchedulerUtil" init-method="init" destroy-method="destroy" >
<bean id="dynamicSchedulerUtil" class="com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler" init-method="init" destroy-method="destroy" >
<!-- (轻易不要变更“调度器名称”, 任务创建时会绑定该“调度器名称”) -->
<property name="scheduler" ref="quartzScheduler"/>
<!-- 调度中心回调IP[选填],为空则自动获取 -->

Loading…
Cancel
Save