提交 b68ca59c 作者: 方治民

chore: 调整日志输出,注释 TestJob @Scheduled

上级 8d20c5b5
...@@ -4,60 +4,54 @@ package com.yiring.app.job; ...@@ -4,60 +4,54 @@ package com.yiring.app.job;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import com.yiring.common.annotation.UptimePush; import com.yiring.common.annotation.UptimePush;
import com.yiring.common.constant.DateFormatter;
import com.yiring.common.core.Retriever;
import com.yiring.common.core.UptimeNotice; import com.yiring.common.core.UptimeNotice;
import com.yiring.common.exception.UptimeException;
import com.yiring.common.util.XxlJobUtil; import com.yiring.common.util.XxlJobUtil;
import com.yiring.common.utils.Uptime;
import java.time.LocalDateTime;
import java.util.Random; import java.util.Random;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* @author Jim * @author Jim
*/ */
@SuppressWarnings("unused")
@Slf4j @Slf4j
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class TestJob { public class TestJob {
final Retriever retriever; // final Retriever retriever;
//
/** // /**
* 一个使用 Retriever + @UptimePush 双链路重试的定时任务示例 // * 一个使用 Retriever + @UptimePush 双链路重试的定时任务示例
*/ // */
@UptimePush( // @UptimePush(
key = "BiCC4Jgoa5", // key = "BiCC4Jgoa5",
group = "Test", // group = "Test",
name = "[TestScheduled] 测试任务调度", // name = "[TestScheduled] 测试任务调度",
retryCount = 3, // retryCount = 3,
retryStatus = Uptime.Status.UP // retryStatus = Uptime.Status.UP
) // )
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS, initialDelay = 60) // @Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS, initialDelay = 60)
public void testScheduled() { // public void testScheduled() {
String time = LocalDateTime.now().format(DateFormatter.DATE_TIME); // String time = LocalDateTime.now().format(DateFormatter.DATE_TIME);
log.info("TestScheduled: {}", time); // log.info("TestScheduled: {}", time);
//
Random random = new Random(); // Random random = new Random();
int randomCount = random.nextInt(10); // int randomCount = random.nextInt(10);
String result = retriever.execute( // String result = retriever.execute(
ctx -> { // ctx -> {
if (ctx.getRetryCount() > randomCount) { // if (ctx.getRetryCount() > randomCount) {
return "OK"; // return "OK";
} // }
//
throw new UptimeException("[TestScheduled] test err: " + time); // throw new UptimeException("[TestScheduled] test err: " + time);
}, // },
Retriever::defaultPolicy // Retriever::defaultPolicy
); // );
//
log.info("[TestScheduled] result: {}", result); // log.info("[TestScheduled] result: {}", result);
} // }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@UptimePush(key = "BiCC4Jgoa5", group = "Test", name = "[TestNoticeHandler] 测试任务调度") @UptimePush(key = "BiCC4Jgoa5", group = "Test", name = "[TestNoticeHandler] 测试任务调度")
......
...@@ -32,3 +32,7 @@ logging: ...@@ -32,3 +32,7 @@ logging:
org.springframework.core.LocalVariableTableParameterNameDiscoverer: ERROR org.springframework.core.LocalVariableTableParameterNameDiscoverer: ERROR
# loki filter logger # loki filter logger
pl.piomin.logging.filter.SpringLoggingFilter: WARN pl.piomin.logging.filter.SpringLoggingFilter: WARN
# 关闭 jasypt 日志
com.ulisesbocchio: WARN
# 关闭 hibernate 连接池日志
org.hibernate.orm.connections.pooling: WARN
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论