Java Code Examples for com.xxl.job.core.util.ShardingUtil#getShardingVo()

The following examples show how to use com.xxl.job.core.util.ShardingUtil#getShardingVo() . 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: ShardingJobHandler.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
	XxlJobLogger.log("分片参数:当前分片序号 = {0}, 总分片数 = {1}", shardingVO.getIndex(), shardingVO.getTotal());

	// 业务逻辑
	for (int i = 0; i < shardingVO.getTotal(); i++) {
		if (i == shardingVO.getIndex()) {
			XxlJobLogger.log("第 {0} 片, 命中分片开始处理", i);
		} else {
			XxlJobLogger.log("第 {0} 片, 忽略", i);
		}
	}

	return SUCCESS;
}
 
Example 2
Source File: ShardingJobHandler.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
	XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardingVO.getIndex(), shardingVO.getTotal());

	// 业务逻辑
	for (int i = 0; i < shardingVO.getTotal(); i++) {
		if (i == shardingVO.getIndex()) {
			XxlJobLogger.log("第 {} 片, 命中分片开始处理", i);
		} else {
			XxlJobLogger.log("第 {} 片, 忽略", i);
		}
	}

	return SUCCESS;
}
 
Example 3
Source File: ScriptJobHandler.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType["+ glueType +"] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat("/")
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    ScriptUtil.markScriptFile(scriptFileName, gluesource);

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:"+ scriptFileName +" -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);
    ReturnT<String> result = (exitValue==0)?IJobHandler.SUCCESS:new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value("+exitValue+") is failed");
    return result;
}
 
Example 4
Source File: ScriptJobHandler.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType["+ glueType +"] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:"+ scriptFileName +" -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value("+exitValue+") is failed");
    }

}
 
Example 5
Source File: ScriptJobHandler.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType[" + glueType + "] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:" + scriptFileName + " -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value(" + exitValue + ") is failed");
    }

}
 
Example 6
Source File: ScriptJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType[" + glueType + "] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:" + scriptFileName + " -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value(" + exitValue + ") is failed");
    }

}