|
|
@ -6,6 +6,7 @@ import com.xxl.job.admin.core.model.XxlJobLog;
|
|
|
|
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
|
|
import com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler;
|
|
|
|
import com.xxl.job.admin.core.util.MailUtil;
|
|
|
|
import com.xxl.job.admin.core.util.MailUtil;
|
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
@ -35,33 +36,38 @@ public class JobFailMonitorHelper {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
|
|
// monitor
|
|
|
|
// monitor
|
|
|
|
while (!toStop) {
|
|
|
|
while (!toStop) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Integer jobLogId = JobFailMonitorHelper.instance.queue.take();
|
|
|
|
List<Integer> jobLogIdList = new ArrayList<Integer>();
|
|
|
|
if (jobLogId != null && jobLogId > 0) {
|
|
|
|
int drainToNum = JobFailMonitorHelper.instance.queue.drainTo(jobLogIdList);
|
|
|
|
XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(jobLogId);
|
|
|
|
|
|
|
|
if (log!=null) {
|
|
|
|
|
|
|
|
if (ReturnT.SUCCESS_CODE==log.getTriggerCode() && log.getHandleCode()==0) {
|
|
|
|
|
|
|
|
// job running, wait + again monitor
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(jobLogIdList)) {
|
|
|
|
|
|
|
|
for (Integer jobLogId : jobLogIdList) {
|
|
|
|
|
|
|
|
if (jobLogId==null || jobLogId==0) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
XxlJobLog log = XxlJobDynamicScheduler.xxlJobLogDao.load(jobLogId);
|
|
|
|
|
|
|
|
if (log == null) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReturnT.SUCCESS_CODE == log.getTriggerCode() && log.getHandleCode() == 0) {
|
|
|
|
JobFailMonitorHelper.monitor(jobLogId);
|
|
|
|
JobFailMonitorHelper.monitor(jobLogId);
|
|
|
|
logger.info(">>>>>>>>>>> job monitor, job running, JobLogId:{}", jobLogId);
|
|
|
|
logger.info(">>>>>>>>>>> job monitor, job running, JobLogId:{}", jobLogId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ReturnT.SUCCESS_CODE==log.getTriggerCode() && ReturnT.SUCCESS_CODE==log.getHandleCode()) {
|
|
|
|
if (ReturnT.SUCCESS_CODE == log.getTriggerCode() && ReturnT.SUCCESS_CODE == log.getHandleCode()) {
|
|
|
|
// job success, pass
|
|
|
|
// job success, pass
|
|
|
|
logger.info(">>>>>>>>>>> job monitor, job success, JobLogId:{}", jobLogId);
|
|
|
|
logger.info(">>>>>>>>>>> job monitor, job success, JobLogId:{}", jobLogId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReturnT.FAIL_CODE == log.getTriggerCode() || ReturnT.FAIL_CODE == log.getHandleCode()) {
|
|
|
|
if (ReturnT.FAIL_CODE == log.getTriggerCode()|| ReturnT.FAIL_CODE==log.getHandleCode()) {
|
|
|
|
|
|
|
|
// job fail,
|
|
|
|
// job fail,
|
|
|
|
sendMonitorEmail(log);
|
|
|
|
sendMonitorEmail(log);
|
|
|
|
logger.info(">>>>>>>>>>> job monitor, job fail, JobLogId:{}", jobLogId);
|
|
|
|
logger.info(">>>>>>>>>>> job monitor, job fail, JobLogId:{}", jobLogId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TimeUnit.SECONDS.sleep(10);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("job monitor error:{}", e);
|
|
|
|
logger.error("job monitor error:{}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|