Package com.taobao.zeus.schedule.mvc.event

Examples of com.taobao.zeus.schedule.mvc.event.JobFailedEvent


          }
          ScheduleInfoLog.info("jobId:" + history.getJobId()
              + " run fail ");
          history = context.getJobHistoryManager().findJobHistory(
              historyId);
          JobFailedEvent jfe = new JobFailedEvent(history.getJobId(),
              history.getTriggerType(), history, jobException);
          context.getDispatcher().forwardEvent(jfe);
        } else {
          // 运行成功,发出成功消息
          ScheduleInfoLog.info("manual jobId::" + history.getJobId()
View Full Code Here


            jobException = new ZeusJobException(jobId,
                String.format("JobId:%s run failed ", jobId));
          }
          ScheduleInfoLog.info("JobId:" + jobId
              + " run fail and dispatch the fail event");
          JobFailedEvent jfe = new JobFailedEvent(jobId, type,
              context.getJobHistoryManager().findJobHistory(
                  his.getId()), jobException);
          context.getDispatcher().forwardEvent(jfe);
        } else {
          // 运行成功,发出成功消息
View Full Code Here

  }
  @Override
  public void beforeDispatch(MvcEvent mvce) {
    try {
      if(mvce.getAppEvent() instanceof JobFailedEvent){
        final JobFailedEvent event=(JobFailedEvent) mvce.getAppEvent();
        final String jobId=event.getJobId();
        final String causeJobId=event.getJobException().getCauseJobId();
        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+"运行失败)";
        }
       
        //手机报警
        //只发送自动调度的报警  并且只在下班时间 或者周末发送
        if(event.getHistory().getTriggerType()==TriggerType.SCHEDULE){
          Calendar now=Calendar.getInstance();
          int hour=now.get(Calendar.HOUR_OF_DAY);
          int day=now.get(Calendar.DAY_OF_WEEK);
          if(day==Calendar.SATURDAY || day==Calendar.SUNDAY || hour<9 || hour>18){
            smsAlarm.alarm(event.getHistory().getId(), "宙斯报警", "宙斯"+msg,chain);
          }
        }
       
      }
    } catch (Exception e) {
View Full Code Here

      history.setJobId(jobId);
      context.getJobHistoryManager().addJobHistory(history);
      history=master.run(history);
      if(history.getStatus()==Status.FAILED){
        ZeusJobException exception=new ZeusJobException(history.getJobId(),history.getLog().getContent());
        JobFailedEvent jfe=new JobFailedEvent(jobDescriptor.getId(),event.getTriggerType(),history,exception);
        ScheduleInfoLog.info("JobId:"+jobId+" is fail,dispatch the fail event");
        //广播消息
        context.getDispatcher().forwardEvent(jfe);
      }
    }else{
View Full Code Here

        history.getLog().appendZeusException(exception);
        history=jobHistoryManager.addJobHistory(history);
        jobHistoryManager.updateJobHistoryLog(history.getId(), history.getLog().getContent());
       
       
        JobFailedEvent jfe=new JobFailedEvent(jobDescriptor.getId(),event.getTriggerType(),history,exception);
       
        ScheduleInfoLog.info("JobId:"+jobId+" is fail,dispatch the fail event");
        //广播消息
        context.getDispatcher().forwardEvent(jfe);
      }
View Full Code Here

TOP

Related Classes of com.taobao.zeus.schedule.mvc.event.JobFailedEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.