Java Code Examples for com.xxl.job.core.biz.model.ReturnT#SUCCESS

The following examples show how to use com.xxl.job.core.biz.model.ReturnT#SUCCESS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexController.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "login", method = RequestMethod.POST)
@ResponseBody
@PermessionLimit(limit = false)
public ReturnT<String> loginDo(HttpServletRequest request, HttpServletResponse response, String userName, String password, String ifRemember) {
    // valid
    if (PermissionInterceptor.ifLogin(request)) {
        return ReturnT.SUCCESS;
    }

    // param
    if (StrUtil.isBlank(userName) || StrUtil.isBlank(password)) {
        return new ReturnT<String>(500, I18nUtil.getString("login_param_empty"));
    }
    boolean ifRem = (StrUtil.isNotBlank(ifRemember) && "on".equals(ifRemember)) ? true : false;

    // do login
    boolean loginRet = PermissionInterceptor.login(response, userName, password, ifRem);
    if (!loginRet) {
        return new ReturnT<String>(500, I18nUtil.getString("login_param_unvalid"));
    }
    return ReturnT.SUCCESS;
}
 
Example 2
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(Integer id) {
    XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
    String group = String.valueOf(xxlJobInfo.getJobGroup());
    String name = String.valueOf(xxlJobInfo.getId());

    try {
        // unbind quartz
        XxlJobDynamicScheduler.removeJob(name, group);

        xxlJobInfoDao.delete(id);
        xxlJobLogDao.delete(id);
        xxlJobLogGlueDao.deleteByJobId(id);
        return ReturnT.SUCCESS;
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }
}
 
Example 3
Source File: JobGroupController.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(Integer id, Integer type) {

    // valid
    int count = xxlJobInfoDao.pageListCount(0, 10, id, null, null, type);
    if (count > 0) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0"));
    }

    List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
    if (allList.size() == 1) {
        return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1"));
    }

    int ret = xxlJobGroupDao.remove(id);
    return (ret > 0) ? ReturnT.SUCCESS : ReturnT.FAIL;
}
 
Example 4
Source File: JobGroupController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/remove")
@ResponseBody
public ReturnT<String> remove(int id){

	// valid
	int count = xxlJobInfoDao.pageListCount(0, 10, id, null, null);
	if (count > 0) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_0") );
	}

	List<XxlJobGroup> allList = xxlJobGroupDao.findAll();
	if (allList.size() == 1) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_del_limit_1") );
	}

	int ret = xxlJobGroupDao.remove(id);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 5
Source File: AdminBizImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
    for (HandleCallbackParam handleCallbackParam : callbackParamList) {
        ReturnT<String> callbackResult = callback(handleCallbackParam);
        logger.info(">>>>>>>>> JobApiController.callback {}, handleCallbackParam={}, callbackResult={}",
                (callbackResult.getCode() == IJobHandler.SUCCESS.getCode() ? "success" : "fail"), handleCallbackParam, callbackResult);
    }

    return ReturnT.SUCCESS;
}
 
Example 6
Source File: AdminBizImpl.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
    for (HandleCallbackParam handleCallbackParam: callbackParamList) {
        ReturnT<String> callbackResult = callback(handleCallbackParam);
        logger.debug(">>>>>>>>> JobApiController.callback {}, handleCallbackParam={}, callbackResult={}",
                (callbackResult.getCode()==IJobHandler.SUCCESS.getCode()?"success":"fail"), handleCallbackParam, callbackResult);
    }

    return ReturnT.SUCCESS;
}
 
Example 7
Source File: JobGroupController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/update")
@ResponseBody
public ReturnT<String> update(XxlJobGroup xxlJobGroup){
	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType() == 0) {
		// 0=自动注册
		List<String> registryList = findRegistryByAppName(xxlJobGroup.getAppName());
		String addressListStr = null;
		if (registryList!=null && !registryList.isEmpty()) {
			Collections.sort(registryList);
			addressListStr = StringUtils.join(registryList, ",");
		}
		xxlJobGroup.setAddressList(addressListStr);
	} else {
		// 1=手动录入
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.update(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 8
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> start(int id) {
	XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
	String group = String.valueOf(xxlJobInfo.getJobGroup());
	String name = String.valueOf(xxlJobInfo.getId());
	String cronExpression = xxlJobInfo.getJobCron();

	try {
		boolean ret = XxlJobDynamicScheduler.addJob(name, group, cronExpression);
		return ret?ReturnT.SUCCESS:ReturnT.FAIL;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
	}
}
 
Example 9
Source File: IndexController.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "logout", method = RequestMethod.POST)
@ResponseBody
@PermessionLimit(limit = false)
public ReturnT<String> logout(HttpServletRequest request, HttpServletResponse response) {
    if (PermissionInterceptor.ifLogin(request)) {
        PermissionInterceptor.logout(request, response);
    }
    return ReturnT.SUCCESS;
}
 
Example 10
Source File: JobLogController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/clearLog")
@ResponseBody
public ReturnT<String> clearLog(int jobGroup, int jobId, int type){

	Date clearBeforeTime = null;
	int clearBeforeNum = 0;
	if (type == 1) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -1);	// 清理一个月之前日志数据
	} else if (type == 2) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -3);	// 清理三个月之前日志数据
	} else if (type == 3) {
		clearBeforeTime = DateUtils.addMonths(new Date(), -6);	// 清理六个月之前日志数据
	} else if (type == 4) {
		clearBeforeTime = DateUtils.addYears(new Date(), -1);	// 清理一年之前日志数据
	} else if (type == 5) {
		clearBeforeNum = 1000;		// 清理一千条以前日志数据
	} else if (type == 6) {
		clearBeforeNum = 10000;		// 清理一万条以前日志数据
	} else if (type == 7) {
		clearBeforeNum = 30000;		// 清理三万条以前日志数据
	} else if (type == 8) {
		clearBeforeNum = 100000;	// 清理十万条以前日志数据
	} else if (type == 9) {
		clearBeforeNum = 0;			// 清理所有日志数据
	} else {
		return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("joblog_clean_type_unvalid"));
	}

	xxlJobLogDao.clearLog(jobGroup, jobId, clearBeforeTime, clearBeforeNum);
	return ReturnT.SUCCESS;
}
 
Example 11
Source File: JobGroupController.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup){

	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType()!=0) {
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 12
Source File: JobGroupController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/save")
@ResponseBody
public ReturnT<String> save(XxlJobGroup xxlJobGroup){

	// valid
	if (xxlJobGroup.getAppName()==null || StringUtils.isBlank(xxlJobGroup.getAppName())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input")+"AppName") );
	}
	if (xxlJobGroup.getAppName().length()<4 || xxlJobGroup.getAppName().length()>64) {
		return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_appName_length") );
	}
	if (xxlJobGroup.getTitle()==null || StringUtils.isBlank(xxlJobGroup.getTitle())) {
		return new ReturnT<String>(500, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobgroup_field_title")) );
	}
	if (xxlJobGroup.getAddressType()!=0) {
		if (StringUtils.isBlank(xxlJobGroup.getAddressList())) {
			return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_addressType_limit") );
		}
		String[] addresss = xxlJobGroup.getAddressList().split(",");
		for (String item: addresss) {
			if (StringUtils.isBlank(item)) {
				return new ReturnT<String>(500, I18nUtil.getString("jobgroup_field_registryList_unvalid") );
			}
		}
	}

	int ret = xxlJobGroupDao.save(xxlJobGroup);
	return (ret>0)?ReturnT.SUCCESS:ReturnT.FAIL;
}
 
Example 13
Source File: AdminBizImpl.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> callback(List<HandleCallbackParam> callbackParamList) {
    for (HandleCallbackParam handleCallbackParam: callbackParamList) {
        ReturnT<String> callbackResult = callback(handleCallbackParam);
        logger.info(">>>>>>>>> JobApiController.callback {}, handleCallbackParam={}, callbackResult={}",
                (callbackResult.getCode()==IJobHandler.SUCCESS.getCode()?"success":"fail"), handleCallbackParam, callbackResult);
    }

    return ReturnT.SUCCESS;
}
 
Example 14
Source File: ExecutorBizImpl.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> idleBeat(int jobId) {

    // isRunningOrHasQueue
    boolean isRunningOrHasQueue = false;
    JobThread jobThread = XxlJobExecutor.loadJobThread(jobId);
    if (jobThread != null && jobThread.isRunningOrHasQueue()) {
        isRunningOrHasQueue = true;
    }

    if (isRunningOrHasQueue) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, "job thread is running or has trigger queue.");
    }
    return ReturnT.SUCCESS;
}
 
Example 15
Source File: AdminBizImpl.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
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) {
        return new ReturnT<String>(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 && 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;
}
 
Example 16
Source File: ExecutorRegistryThread.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
public void start(final String appname, final String address){

        // valid
        if (appname==null || appname.trim().length()==0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appname is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address);
                        for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.debug(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }

                    }

                    try {
                        if (!toStop) {
                            TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                        }
                    } catch (InterruptedException e) {
                        if (!toStop) {
                            logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                        }
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appname, address);
                    for (AdminBiz adminBiz: XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult!=null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            if (!toStop) {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                            }

                        }

                    }
                } catch (Exception e) {
                    if (!toStop) {
                        logger.error(e.getMessage(), e);
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.setName("xxl-job, executor ExecutorRegistryThread");
        registryThread.start();
    }
 
Example 17
Source File: XxlJobServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> update(XxlJobInfo jobInfo) {

    // valid
    if (JobTypeEnum.CRON.eq(jobInfo.getType())) {
        if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid"));
        }
    } else {
        //表单校验
        String msg = validate(jobInfo.getIntervalSeconds(), jobInfo.getRepeatCount(),
                jobInfo.getStartExecuteTime(), jobInfo.getEndExecuteTime());
        if (!StringUtils.isEmpty(msg)) {
            return new ReturnT<String>(ReturnT.FAIL_CODE, msg);
        }
    }
    if (StringUtils.isBlank(jobInfo.getJobDesc())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_jobdesc")));
    }
    if (StringUtils.isBlank(jobInfo.getAuthor())) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input") + I18nUtil.getString("jobinfo_field_author")));
    }
    if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy") + I18nUtil.getString("system_unvalid")));
    }
    if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy") + I18nUtil.getString("system_unvalid")));
    }

    // ChildJobId valid
    if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
        String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
        for (String childJobIdItem : childJobIds) {
            if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
                XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
                if (childJobInfo == null) {
                    return new ReturnT<String>(ReturnT.FAIL_CODE,
                            MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_not_found")), childJobIdItem));
                }
            } else {
                return new ReturnT<String>(ReturnT.FAIL_CODE,
                        MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId") + "({0})" + I18nUtil.getString("system_unvalid")), childJobIdItem));
            }
        }
        jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
    }

    // stage job info
    XxlJobInfo existsJobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
    if (existsJobInfo == null) {
        return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id") + I18nUtil.getString("system_not_found")));
    }
    //String old_cron = exists_jobInfo.getJobCron();

    existsJobInfo.setJobCron(jobInfo.getJobCron());
    existsJobInfo.setJobDesc(jobInfo.getJobDesc());
    existsJobInfo.setAuthor(jobInfo.getAuthor());
    existsJobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
    existsJobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
    existsJobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
    existsJobInfo.setExecutorParam(jobInfo.getExecutorParam());
    existsJobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
    existsJobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout());
    existsJobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
    existsJobInfo.setChildJobId(jobInfo.getChildJobId());
    existsJobInfo.setRepeatCount(jobInfo.getRepeatCount());
    existsJobInfo.setStartExecuteTime(jobInfo.getStartExecuteTime());
    existsJobInfo.setEndExecuteTime(jobInfo.getEndExecuteTime());
    existsJobInfo.setIntervalSeconds(jobInfo.getIntervalSeconds());
    xxlJobInfoDao.update(existsJobInfo);

    if (JobTypeEnum.TIMES.eq(jobInfo.getType())) {
        return ReturnT.SUCCESS;
    }

    // update quartz-cron if started
    String qzGroup = String.valueOf(existsJobInfo.getJobGroup());
    String qzName = String.valueOf(existsJobInfo.getId());
    try {
        XxlJobDynamicScheduler.updateJobCron(qzGroup, qzName, existsJobInfo.getJobCron());
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        return ReturnT.FAIL;
    }

    return ReturnT.SUCCESS;
}
 
Example 18
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 5、生命周期任务示例:任务初始化与销毁时,支持自定义相关逻辑;
 */
@XxlJob(value = "demoJobHandler2", init = "init", destroy = "destroy")
public ReturnT<String> demoJobHandler2(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");
    return ReturnT.SUCCESS;
}
 
Example 19
Source File: XxlJobServiceImpl.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> update(XxlJobInfo jobInfo) {

	// valid
	if (!CronExpression.isValidExpression(jobInfo.getJobCron())) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, I18nUtil.getString("jobinfo_field_cron_unvalid") );
	}
	if (StringUtils.isBlank(jobInfo.getJobDesc())) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_jobdesc")) );
	}
	if (StringUtils.isBlank(jobInfo.getAuthor())) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("system_please_input")+I18nUtil.getString("jobinfo_field_author")) );
	}
	if (ExecutorRouteStrategyEnum.match(jobInfo.getExecutorRouteStrategy(), null) == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorRouteStrategy")+I18nUtil.getString("system_unvalid")) );
	}
	if (ExecutorBlockStrategyEnum.match(jobInfo.getExecutorBlockStrategy(), null) == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_executorBlockStrategy")+I18nUtil.getString("system_unvalid")) );
	}

	// ChildJobId valid
	if (StringUtils.isNotBlank(jobInfo.getChildJobId())) {
		String[] childJobIds = StringUtils.split(jobInfo.getChildJobId(), ",");
		for (String childJobIdItem: childJobIds) {
			if (StringUtils.isNotBlank(childJobIdItem) && StringUtils.isNumeric(childJobIdItem)) {
				XxlJobInfo childJobInfo = xxlJobInfoDao.loadById(Integer.valueOf(childJobIdItem));
				if (childJobInfo==null) {
					return new ReturnT<String>(ReturnT.FAIL_CODE,
							MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_not_found")), childJobIdItem));
				}
			} else {
				return new ReturnT<String>(ReturnT.FAIL_CODE,
						MessageFormat.format((I18nUtil.getString("jobinfo_field_childJobId")+"({0})"+I18nUtil.getString("system_unvalid")), childJobIdItem));
			}
		}
		jobInfo.setChildJobId(StringUtils.join(childJobIds, ","));
	}

	// stage job info
	XxlJobInfo exists_jobInfo = xxlJobInfoDao.loadById(jobInfo.getId());
	if (exists_jobInfo == null) {
		return new ReturnT<String>(ReturnT.FAIL_CODE, (I18nUtil.getString("jobinfo_field_id")+I18nUtil.getString("system_not_found")) );
	}
	//String old_cron = exists_jobInfo.getJobCron();

	exists_jobInfo.setJobCron(jobInfo.getJobCron());
	exists_jobInfo.setJobDesc(jobInfo.getJobDesc());
	exists_jobInfo.setAuthor(jobInfo.getAuthor());
	exists_jobInfo.setAlarmEmail(jobInfo.getAlarmEmail());
	exists_jobInfo.setExecutorRouteStrategy(jobInfo.getExecutorRouteStrategy());
	exists_jobInfo.setExecutorHandler(jobInfo.getExecutorHandler());
	exists_jobInfo.setExecutorParam(jobInfo.getExecutorParam());
	exists_jobInfo.setExecutorBlockStrategy(jobInfo.getExecutorBlockStrategy());
	exists_jobInfo.setExecutorTimeout(jobInfo.getExecutorTimeout());
	exists_jobInfo.setExecutorFailRetryCount(jobInfo.getExecutorFailRetryCount());
	exists_jobInfo.setChildJobId(jobInfo.getChildJobId());
       xxlJobInfoDao.update(exists_jobInfo);


	// update quartz-cron if started
	String qz_group = String.valueOf(exists_jobInfo.getJobGroup());
	String qz_name = String.valueOf(exists_jobInfo.getId());
       try {
           XxlJobDynamicScheduler.updateJobCron(qz_group, qz_name, exists_jobInfo.getJobCron());
       } catch (SchedulerException e) {
           logger.error(e.getMessage(), e);
		return ReturnT.FAIL;
       }

	return ReturnT.SUCCESS;
}
 
Example 20
Source File: ExecutorRegistryThread.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
public void start(final String appName, final String address, final String registryLazy) {

        // valid
        if (appName == null || appName.trim().length() == 0) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
            return;
        }
        if (XxlJobExecutor.getAdminBizList() == null) {
            logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
            return;
        }

        REGISTRY_LAZY = Convert.toLong(registryLazy, 10000L);

        registryThread = new Thread(new Runnable() {
            @Override
            public void run() {

                // 首次主次延迟 REGISTRY_LAZY 毫秒, 防止尚未启动完成时,注册失败
                if (REGISTRY_LAZY > 0) {
                    try {
                        Thread.sleep(REGISTRY_LAZY);
                    } catch (InterruptedException e) {
                        logger.error(">>>>>>>>>>> xxl-job 首次注册延迟失败, appName:{}, address:{}", new Object[]{appName, address});
                    } finally {
                        REGISTRY_LAZY = 0;
                    }
                }

                // registry
                while (!toStop) {
                    try {
                        RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                        for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                            try {
                                ReturnT<String> registryResult = adminBiz.registry(registryParam);
                                if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                    registryResult = ReturnT.SUCCESS;
                                    logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                    break;
                                } else {
                                    logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                }
                            } catch (Exception e) {
                                logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                            }

                        }
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                    } catch (InterruptedException e) {
                        logger.warn(">>>>>>>>>>> xxl-job, executor registry thread interrupted, error msg:{}", e.getMessage());
                    }
                }

                // registry remove
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, address);
                    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                            if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[]{registryParam, registryResult});
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                        }

                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");

            }
        });
        registryThread.setDaemon(true);
        registryThread.start();
    }