10. xxl-job原理---回调

xxl-job: v2.0.2 原理 目录学习

  • 0. xxl-job原理
  • 1. xxl-job原理---定时任务架构
  • 2. xxl-job原理-- 调度中心
  • 3. xxl-job原理-- 执行器注册
  • 4. xxl-job原理-- 执行器注册问题
  • 5 xxl-job原理-- 执行器注册问题
  • 6. xxl-job原理-- 调度中心注册
  • 7. xxl-job原理-- 任务管理
  • 8. xxl-job原理-- 任务执行或触发
  • 9. xxl-job原理-- jobthread的作用
  • 10. xxl-job原理---回调

执行器

在执行器开始的时候,会开启一个回调线程,TriggerCallbackThread.getInstance().start();
该线程不断查找从 回调队列callBackQueue中查找回调信息,用就进行回调doCallback(callbackParamList);

admin

执行器通过回调线程,会调用admin中AdminBizImpl.callback() 方法, 然后执行。

回调源代码

AdminBizImpl.callback

private ReturnT callback(HandleCallbackParam handleCallbackParam) {
        // valid log item
        XxlJobLog log = xxlJobLogDao.load(handleCallbackParam.getLogId());
        if (log == null) {
            return new ReturnT(ReturnT.FAIL_CODE, "log item not found.");
        }
        if (log.getHandleCode() > 0) {
            return new ReturnT(ReturnT.FAIL_CODE, "log repeate callback.");     // avoid repeat callback, trigger child job etc
        }

        // trigger success, to trigger child job
        String callbackMsg = null;
        if (IJobHandler.SUCCESS.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
            XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(log.getJobId());
            if (xxlJobInfo!=null && xxlJobInfo.getChildJobId()!=null && xxlJobInfo.getChildJobId().trim().length()>0) {
                callbackMsg = "

>>>>>>>>>>>"+ I18nUtil.getString("jobconf_trigger_child_run") +"<<<<<<<<<<<
"; String[] childJobIds = xxlJobInfo.getChildJobId().split(","); for (int i = 0; i < childJobIds.length; i++) { int childJobId = (childJobIds[i]!=null && childJobIds[i].trim().length()>0 && isNumeric(childJobIds[i]))?Integer.valueOf(childJobIds[i]):-1; if (childJobId > 0) { JobTriggerPoolHelper.trigger(childJobId, TriggerTypeEnum.PARENT, -1, null, null); ReturnT triggerChildResult = ReturnT.SUCCESS; // add msg callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg1"), (i+1), childJobIds.length, childJobIds[i], (triggerChildResult.getCode()==ReturnT.SUCCESS_CODE?I18nUtil.getString("system_success"):I18nUtil.getString("system_fail")), triggerChildResult.getMsg()); } else { callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_child_msg2"), (i+1), childJobIds.length, childJobIds[i]); } } } } // handle msg StringBuffer handleMsg = new StringBuffer(); if (log.getHandleMsg()!=null) { handleMsg.append(log.getHandleMsg()).append("
"); } if (handleCallbackParam.getExecuteResult().getMsg() != null) { handleMsg.append(handleCallbackParam.getExecuteResult().getMsg()); } if (callbackMsg != null) { handleMsg.append(callbackMsg); } // success, save log log.setHandleTime(new Date()); log.setHandleCode(handleCallbackParam.getExecuteResult().getCode()); log.setHandleMsg(handleMsg.toString()); xxlJobLogDao.updateHandleInfo(log); return ReturnT.SUCCESS; }

tips: 好像,只有有子任务的任务才可以进行回调, 如果想执行一个特定的命令时无法 进行回调

PS: 若你觉得可以、还行、过得去、甚至不太差的话,可以“关注”一下,就此谢过!

你可能感兴趣的:(10. xxl-job原理---回调)