Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
b68ca59c
提交
b68ca59c
authored
2月 11, 2025
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: 调整日志输出,注释 TestJob @Scheduled
上级
8d20c5b5
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
39 行删除
+37
-39
TestJob.java
app/src/main/java/com/yiring/app/job/TestJob.java
+33
-39
application-conf-patch.yml
app/src/main/resources/application-conf-patch.yml
+4
-0
没有找到文件。
app/src/main/java/com/yiring/app/job/TestJob.java
浏览文件 @
b68ca59c
...
...
@@ -4,60 +4,54 @@ package com.yiring.app.job;
import
com.xxl.job.core.biz.model.ReturnT
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
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.exception.UptimeException
;
import
com.yiring.common.util.XxlJobUtil
;
import
com.yiring.common.utils.Uptime
;
import
java.time.LocalDateTime
;
import
java.util.Random
;
import
java.util.concurrent.TimeUnit
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* @author Jim
*/
@SuppressWarnings
(
"unused"
)
@Slf4j
@Component
@RequiredArgsConstructor
public
class
TestJob
{
final
Retriever
retriever
;
/**
* 一个使用 Retriever + @UptimePush 双链路重试的定时任务示例
*/
@UptimePush
(
key
=
"BiCC4Jgoa5"
,
group
=
"Test"
,
name
=
"[TestScheduled] 测试任务调度"
,
retryCount
=
3
,
retryStatus
=
Uptime
.
Status
.
UP
)
@Scheduled
(
fixedDelay
=
5
,
timeUnit
=
TimeUnit
.
SECONDS
,
initialDelay
=
60
)
public
void
testScheduled
()
{
String
time
=
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
);
log
.
info
(
"TestScheduled: {}"
,
time
);
Random
random
=
new
Random
();
int
randomCount
=
random
.
nextInt
(
10
);
String
result
=
retriever
.
execute
(
ctx
->
{
if
(
ctx
.
getRetryCount
()
>
randomCount
)
{
return
"OK"
;
}
throw
new
UptimeException
(
"[TestScheduled] test err: "
+
time
);
},
Retriever:
:
defaultPolicy
);
log
.
info
(
"[TestScheduled] result: {}"
,
result
);
}
//
final Retriever retriever;
//
/
/ /
**
//
* 一个使用 Retriever + @UptimePush 双链路重试的定时任务示例
//
*/
//
@UptimePush(
//
key = "BiCC4Jgoa5",
//
group = "Test",
//
name = "[TestScheduled] 测试任务调度",
//
retryCount = 3,
//
retryStatus = Uptime.Status.UP
//
)
//
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS, initialDelay = 60)
//
public void testScheduled() {
//
String time = LocalDateTime.now().format(DateFormatter.DATE_TIME);
//
log.info("TestScheduled: {}", time);
//
//
Random random = new Random();
//
int randomCount = random.nextInt(10);
//
String result = retriever.execute(
//
ctx -> {
//
if (ctx.getRetryCount() > randomCount) {
//
return "OK";
//
}
//
//
throw new UptimeException("[TestScheduled] test err: " + time);
//
},
//
Retriever::defaultPolicy
//
);
//
//
log.info("[TestScheduled] result: {}", result);
//
}
@SuppressWarnings
(
"unused"
)
@UptimePush
(
key
=
"BiCC4Jgoa5"
,
group
=
"Test"
,
name
=
"[TestNoticeHandler] 测试任务调度"
)
...
...
app/src/main/resources/application-conf-patch.yml
浏览文件 @
b68ca59c
...
...
@@ -32,3 +32,7 @@ logging:
org.springframework.core.LocalVariableTableParameterNameDiscoverer
:
ERROR
# loki filter logger
pl.piomin.logging.filter.SpringLoggingFilter
:
WARN
# 关闭 jasypt 日志
com.ulisesbocchio
:
WARN
# 关闭 hibernate 连接池日志
org.hibernate.orm.connections.pooling
:
WARN
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论