com.xxl.job.core.log.XxlJobLogger Java Examples

The following examples show how to use com.xxl.job.core.log.XxlJobLogger. 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 xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
	int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

	XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

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

	return SUCCESS;
}
 
Example #3
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 2、分片广播任务
 */
@XxlJob("shardingJobHandler")
public ReturnT<String> shardingJobHandler(String param) throws Exception {

    // 分片参数
    int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
    int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

    XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

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

    return ReturnT.SUCCESS;
}
 
Example #4
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 2、分片广播任务
 */
@XxlJob("shardingJobHandler")
public ReturnT<String> shardingJobHandler(String param) throws Exception {

    // 分片参数
    int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
    int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

    XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

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

    return ReturnT.SUCCESS;
}
 
Example #5
Source File: ShardingJobHandler.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
	int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

	XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

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

	return SUCCESS;
}
 
Example #6
Source File: ShardingJobHandler.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
	int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

	XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

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

	return SUCCESS;
}
 
Example #7
Source File: ShardingJobHandler.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

	// 分片参数
	int shardIndex = XxlJobContext.getXxlJobContext().getShardIndex();
	int shardTotal = XxlJobContext.getXxlJobContext().getShardTotal();

	XxlJobLogger.log("分片参数:当前分片序号 = {}, 总分片数 = {}", shardIndex, shardTotal);

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

	return SUCCESS;
}
 
Example #8
Source File: RestTenantJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {
    XxlJobLogger.log("执行参数--->param={} ", param);

    List<Tenant> list = tenantService.list(Wraps.<Tenant>lbQ().eq(Tenant::getCode, param).ne(Tenant::getCode, DEF_TENANT));

    List<String> tenantCodeList = list.parallelStream().map(Tenant::getCode).collect(Collectors.toList());

    //删除租户库
    if (!tenantCodeList.isEmpty()) {
        tenantService.remove(Wraps.<Tenant>lbQ().in(Tenant::getCode, tenantCodeList));
        tenantCodeList.forEach((tenant) -> initDbMapper.dropDatabase(database + StrUtil.UNDERLINE + tenant));
    }

    //删除全局用户
    globalUserService.remove(Wraps.<GlobalUser>lbQ().notIn(GlobalUser::getTenantCode, DEF_TENANT, ADMIN_TENANT));
    return SUCCESS;
}
 
Example #9
Source File: GlobalTenantJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {
    //记录日志的方法推荐使用这个:XxlJobLogger.log ,因为这个记录的日志,可以在zuihou-jobs-server管理后台查看
    XxlJobLogger.log("执行结果--->param={} ", param);

    LbqWrapper<Tenant> wrapper = Wraps.<Tenant>lbQ()
            .eq(Tenant::getStatus, TenantStatusEnum.NORMAL);

    List<Tenant> list = tenantService.list(wrapper);

    list.forEach((tenant) -> {
        executeBiz(tenant, param);
    });

    return SUCCESS;
}
 
Example #10
Source File: RestTenantJobHandler.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {
    XxlJobLogger.log("执行参数--->param={} ", param);

    List<Tenant> list = tenantService.list(Wraps.<Tenant>lbQ().eq(Tenant::getCode, param).ne(Tenant::getCode, DEF_TENANT));

    List<String> tenantCodeList = list.parallelStream().map(Tenant::getCode).collect(Collectors.toList());

    //删除租户库
    if (!tenantCodeList.isEmpty()) {
        tenantService.remove(Wraps.<Tenant>lbQ().in(Tenant::getCode, tenantCodeList));
        tenantCodeList.forEach((tenant) -> initDbMapper.dropDatabase(database + StrUtil.UNDERLINE + tenant));
    }

    //删除全局用户
    globalUserService.remove(Wraps.<GlobalUser>lbQ().notIn(GlobalUser::getTenantCode, DEF_TENANT, ADMIN_TENANT));
    return SUCCESS;
}
 
Example #11
Source File: GlobalTenantJobHandler.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {
    //记录日志的方法推荐使用这个:XxlJobLogger.log ,因为这个记录的日志,可以在zuihou-jobs-server管理后台查看
    XxlJobLogger.log("执行结果--->param={} ", param);

    LbqWrapper<Tenant> wrapper = Wraps.<Tenant>lbQ()
            .eq(Tenant::getStatus, TenantStatusEnum.NORMAL);

    List<Tenant> list = tenantService.list(wrapper);

    list.forEach((tenant) -> {
        executeBiz(tenant, param);
    });

    return SUCCESS;
}
 
Example #12
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 #13
Source File: TriggerCallbackThread.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent){
    for (HandleCallbackParam callbackParam: callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobFileAppender.contextHolder.set(logFileName);
        XxlJobLogger.log(logContent);
    }
}
 
Example #14
Source File: DemoJobHandler.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 {
	logger.info("获取参数===》"+param);
	XxlJobLogger.log("获取参数==》"+param);
	XxlJobLogger.log("XXL-JOB, Hello World.");

	for (int i = 0; i < 5; i++) {
		XxlJobLogger.log("beat at:" + i);
		TimeUnit.SECONDS.sleep(2);
	}
	return SUCCESS;
}
 
Example #15
Source File: DemoJobHandler.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
	XxlJobLogger.log("XXL-JOB, Hello World.");

	for (int i = 0; i < 5; i++) {
		XxlJobLogger.log("beat at:" + i);
		TimeUnit.SECONDS.sleep(2);
	}
	return SUCCESS;
}
 
Example #16
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 #17
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 1、简单任务示例(Bean模式)
 */
@XxlJob("demoJobHandler")
public ReturnT<String> demoJobHandler(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");

    for (int i = 0; i < 5; i++) {
        XxlJobLogger.log("beat at:" + i);
        TimeUnit.SECONDS.sleep(2);
    }
    return ReturnT.SUCCESS;
}
 
Example #18
Source File: SampleXxlJob.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 1、简单任务示例(Bean模式)
 */
@XxlJob("demoJobHandler")
public ReturnT<String> demoJobHandler(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");

    for (int i = 0; i < 5; i++) {
        XxlJobLogger.log("beat at:" + i);
        TimeUnit.SECONDS.sleep(2);
    }
    return ReturnT.SUCCESS;
}
 
Example #19
Source File: FrostmourneJobHandler.java    From frostmourne with MIT License 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
    try {
        TypeReference<Map<String, Object>> typeRef = new TypeReference<Map<String, Object>>() {
        };
        Map<String, Object> paramMap = JacksonObjectMapper.getCommonObjectMapper().readValue(param, typeRef);
        Long alarmId = new Long(paramMap.get("alarmId").toString());
        alarmService.run("system", alarmId, false);
        XxlJobLogger.log("frostmourne, job begin.");
        return SUCCESS;
    } catch (Exception ex) {
        LOGGER.error("error when execute, param: " + param, ex);
        return FAIL;
    }
}
 
Example #20
Source File: DemoJobHandler.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
	XxlJobLogger.log("XXL-JOB, Hello World.");

	for (int i = 0; i < 5; i++) {
		XxlJobLogger.log("beat at:" + i);
		TimeUnit.SECONDS.sleep(2);
	}
	return SUCCESS;
}
 
Example #21
Source File: DemoJobHandler.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
	XxlJobLogger.log("XXL-JOB, Hello World.");

	for (int i = 0; i < 5; i++) {
		XxlJobLogger.log("beat at:" + i);
		TimeUnit.SECONDS.sleep(2);
	}
	return SUCCESS;
}
 
Example #22
Source File: DemoJobHandler.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
	XxlJobLogger.log("XXL-JOB, Hello World.");

	for (int i = 0; i < 5; i++) {
		XxlJobLogger.log("beat at:" + i);
		TimeUnit.SECONDS.sleep(2);
	}
	return SUCCESS;
}
 
Example #23
Source File: TriggerCallbackThread.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent){
    for (HandleCallbackParam callbackParam: callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobContext.setXxlJobContext(new XxlJobContext(
                -1,
                logFileName,
                -1,
                -1));
        XxlJobLogger.log(logContent);
    }
}
 
Example #24
Source File: DemoTask.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * execute handler, invoked when executor receives a scheduling request
 *
 * @param param 定时任务参数
 * @return 执行状态
 * @throws Exception 任务异常
 */
@Override
public ReturnT<String> execute(String param) throws Exception {
    // 可以动态获取传递过来的参数,根据参数不同,当前调度的任务不同
    log.info("【param】= {}", param);
    XxlJobLogger.log("demo task run at : {}", DateUtil.now());
    return RandomUtil.randomInt(1, 11) % 2 == 0 ? SUCCESS : FAIL;
}
 
Example #25
Source File: RestBase0000JobHandler.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {
    XxlJobLogger.log("执行参数--->param={} ", param);

    initSystemContext.reset(DEF_TENANT);

    return SUCCESS;
}
 
Example #26
Source File: DemoJobHandler.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {
    XxlJobLogger.log("XXL-JOB, Hello World.");
    for (int i = 0; i < 5; i++) {
        XxlJobLogger.log("beat at:" + i);
        TimeUnit.SECONDS.sleep(2);
    }
    return SUCCESS;
}
 
Example #27
Source File: SmsSendJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {
    XxlJobLogger.log("执行参数--->param={} ", param);
    JSONObject map = JSONObject.parseObject(param);
    BaseContextHandler.setTenant(map.getString(BaseContextConstants.JWT_KEY_TENANT));

    smsContext.smsSend(map.getLong("id"));
    return SUCCESS;
}
 
Example #28
Source File: UserTokenRestJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> executeBiz(Tenant tenant, String param) {

    BaseContextHandler.setTenant(tenant.getCode());
    LbqWrapper<UserToken> wrapper = Wraps.<UserToken>lbQ().le(UserToken::getExpireTime, LocalDateTime.now());
    boolean remove = userTokenService.remove(wrapper);

    XxlJobLogger.log("执行结果:{} ", remove);
    log.info("执行结果:{} ", remove);
    return SUCCESS;
}
 
Example #29
Source File: TriggerCallbackThread.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent) {
    for (HandleCallbackParam callbackParam : callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobFileAppender.contextHolder.set(logFileName);
        XxlJobLogger.log(logContent);
    }
}
 
Example #30
Source File: TriggerCallbackThread.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent) {
    for (HandleCallbackParam callbackParam : callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobFileAppender.contextHolder.set(logFileName);
        XxlJobLogger.log(logContent);
    }
}