if(chainLocal.get()==null || !chainLocal.get().getCauseJobId().equals(causeJobId)){
GroupBean gb=readOnlyGroupManager.getGlobeGroupBean();
chainLocal.set(new ChainException(causeJobId, gb));
}
final ChainException chain=chainLocal.get();
final JobBean jobBean=chain.gb.getAllSubJobBeans().get(jobId);
final ZeusUser owner=userManager.findByUid(jobBean.getJobDescriptor().getOwner());
//延迟6秒发送邮件,保证日志已经输出到数据库
new Thread(){
public void run() {
try {
Thread.sleep(6000);
StringBuffer sb=new StringBuffer();
sb.append("Job任务(").append(jobId).append(")").append(jobBean.getJobDescriptor().getName()).append("运行失败");
sb.append("<br/>");
String type="";
if(event.getTriggerType()==TriggerType.MANUAL){
type="手动触发";
}else if(event.getTriggerType()==TriggerType.MANUAL_RECOVER){
type="手动恢复";
}else if(event.getTriggerType()==TriggerType.SCHEDULE){
type="自动调度";
}
sb.append("Job任务的触发类型为:"+type).append("<br/>");
if(event.getHistory()!=null){
sb.append("失败原因:"+jobHistoryManager.findJobHistory(event.getHistory().getId()).getLog().getContent().replaceAll("\\n", "<br/>"));
String msg= "Zeus报警 JobId:"+jobId+" 任务运行失败";
if(!jobBean.getDepender().isEmpty()){
msg+=",影响范围:"+getDependencyJobs(jobBean);
}
if(!causeJobId.equalsIgnoreCase(event.getJobId())){
msg+="(根本原因:job "+causeJobId+"运行失败)";
}
mailAlarm.alarm(event.getHistory().getId(), msg, sb.toString());
}
} catch (Exception e) {
log.error("邮件发送出现异常",e);
}
};
}.start();
String msg="Job任务("+jobId+"-"+owner.getName()+"):"+jobBean.getJobDescriptor().getName()+" 运行失败";
if(!jobBean.getDepender().isEmpty()){
msg+=",影响范围:"+getDependencyJobs(jobBean);
}
if(!causeJobId.equalsIgnoreCase(event.getJobId())){
msg+="(根本原因:job "+causeJobId+"运行失败)";
}