Search in sources :

Example 6 with XxlJobInfo

use of com.xxl.job.admin.core.model.XxlJobInfo in project xxl-job by xuxueli.

the class XxlJobInfoDaoTest method save_load.

@Test
public void save_load() {
    XxlJobInfo info = new XxlJobInfo();
    info.setJobGroup(1);
    info.setJobCron("jobCron");
    info.setJobDesc("desc");
    info.setAuthor("setAuthor");
    info.setAlarmEmail("setAlarmEmail");
    info.setExecutorRouteStrategy("setExecutorRouteStrategy");
    info.setExecutorHandler("setExecutorHandler");
    info.setExecutorParam("setExecutorParam");
    info.setExecutorBlockStrategy("setExecutorBlockStrategy");
    info.setExecutorFailStrategy("setExecutorFailStrategy");
    info.setGlueType("setGlueType");
    info.setGlueSource("setGlueSource");
    info.setGlueRemark("setGlueRemark");
    info.setChildJobId("1");
    int count = xxlJobInfoDao.save(info);
    XxlJobInfo info2 = xxlJobInfoDao.loadById(info.getId());
    info2.setJobCron("jobCron2");
    info2.setJobDesc("desc2");
    info2.setAuthor("setAuthor2");
    info2.setAlarmEmail("setAlarmEmail2");
    info2.setExecutorRouteStrategy("setExecutorRouteStrategy2");
    info2.setExecutorHandler("setExecutorHandler2");
    info2.setExecutorParam("setExecutorParam2");
    info2.setExecutorBlockStrategy("setExecutorBlockStrategy2");
    info2.setExecutorFailStrategy("setExecutorFailStrategy2");
    info2.setGlueType("setGlueType2");
    info2.setGlueSource("setGlueSource2");
    info2.setGlueRemark("setGlueRemark2");
    info2.setGlueUpdatetime(new Date());
    info2.setChildJobId("1");
    int item2 = xxlJobInfoDao.update(info2);
    xxlJobInfoDao.delete(info2.getId());
    List<XxlJobInfo> list2 = xxlJobInfoDao.getJobsByGroup(1);
    int ret3 = xxlJobInfoDao.findAllCount();
}
Also used : Date(java.util.Date) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo) Test(org.junit.Test)

Example 7 with XxlJobInfo

use of com.xxl.job.admin.core.model.XxlJobInfo in project xxl-job by xuxueli.

the class AdminBizImpl method callback.

private ReturnT<String> callback(HandleCallbackParam handleCallbackParam) {
    // valid log item
    XxlJobLog log = xxlJobLogDao.load(handleCallbackParam.getLogId());
    if (log == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "log item not found.");
    }
    if (log.getHandleCode() > 0) {
        // avoid repeat callback, trigger child job etc
        return new ReturnT<String>(ReturnT.FAIL_CODE, "log repeate callback.");
    }
    // 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 && StringUtils.isNotBlank(xxlJobInfo.getChildJobId())) {
            callbackMsg = "<br><br><span style=\"color:#00c0ef;\" > >>>>>>>>>>>" + I18nUtil.getString("jobconf_trigger_child_run") + "<<<<<<<<<<< </span><br>";
            String[] childJobIds = xxlJobInfo.getChildJobId().split(",");
            for (int i = 0; i < childJobIds.length; i++) {
                int childJobId = (StringUtils.isNotBlank(childJobIds[i]) && StringUtils.isNumeric(childJobIds[i])) ? Integer.valueOf(childJobIds[i]) : -1;
                if (childJobId > 0) {
                    ReturnT<String> triggerChildResult = xxlJobService.triggerJob(childJobId);
                    // 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]);
                }
            }
        }
    } else if (IJobHandler.FAIL_RETRY.getCode() == handleCallbackParam.getExecuteResult().getCode()) {
        ReturnT<String> retryTriggerResult = xxlJobService.triggerJob(log.getJobId());
        callbackMsg = "<br><br><span style=\"color:#F39C12;\" > >>>>>>>>>>>" + I18nUtil.getString("jobconf_exe_fail_retry") + "<<<<<<<<<<< </span><br>";
        callbackMsg += MessageFormat.format(I18nUtil.getString("jobconf_callback_msg1"), (retryTriggerResult.getCode() == ReturnT.SUCCESS_CODE ? I18nUtil.getString("system_success") : I18nUtil.getString("system_fail")), retryTriggerResult.getMsg());
    }
    // handle msg
    StringBuffer handleMsg = new StringBuffer();
    if (log.getHandleMsg() != null) {
        handleMsg.append(log.getHandleMsg()).append("<br>");
    }
    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;
}
Also used : ReturnT(com.xxl.job.core.biz.model.ReturnT) XxlJobLog(com.xxl.job.admin.core.model.XxlJobLog) Date(java.util.Date) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Example 8 with XxlJobInfo

use of com.xxl.job.admin.core.model.XxlJobInfo in project xxl-job by xuxueli.

the class XxlJobServiceImpl method triggerJob.

@Override
public ReturnT<String> triggerJob(int id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    if (xxlJobInfo == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id") + I18nUtil.getString("system_unvalid")));
    }
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());
    try {
        XxlJobDynamicScheduler.triggerJob(name, group);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return new ReturnT<String>(ReturnT.FAIL_CODE, e.getMessage());
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) ReturnT(com.xxl.job.core.biz.model.ReturnT) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Example 9 with XxlJobInfo

use of com.xxl.job.admin.core.model.XxlJobInfo in project xxl-job by xuxueli.

the class XxlJobServiceImpl method pause.

@Override
public ReturnT<String> pause(int id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());
    try {
        // jobStatus do not store
        boolean ret = XxlJobDynamicScheduler.pauseJob(name, group);
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Example 10 with XxlJobInfo

use of com.xxl.job.admin.core.model.XxlJobInfo in project xxl-job by xuxueli.

the class XxlJobServiceImpl method resume.

@Override
public ReturnT<String> resume(int id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());
    try {
        boolean ret = XxlJobDynamicScheduler.resumeJob(name, group);
        return ret ? ReturnT.SUCCESS : ReturnT.FAIL;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) XxlJobInfo(com.xxl.job.admin.core.model.XxlJobInfo)

Aggregations

XxlJobInfo (com.xxl.job.admin.core.model.XxlJobInfo)15 ReturnT (com.xxl.job.core.biz.model.ReturnT)7 SchedulerException (org.quartz.SchedulerException)6 Date (java.util.Date)5 XxlJobGroup (com.xxl.job.admin.core.model.XxlJobGroup)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 XxlJobLog (com.xxl.job.admin.core.model.XxlJobLog)3 XxlJobLogGlue (com.xxl.job.admin.core.model.XxlJobLogGlue)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ExecutorFailStrategyEnum (com.xxl.job.admin.core.enums.ExecutorFailStrategyEnum)1 ExecutorRouteStrategyEnum (com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum)1 ExecutorBiz (com.xxl.job.core.biz.ExecutorBiz)1 TriggerParam (com.xxl.job.core.biz.model.TriggerParam)1 ExecutorBlockStrategyEnum (com.xxl.job.core.enums.ExecutorBlockStrategyEnum)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1