Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
93521943
提交
93521943
authored
5月 13, 2024
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 优化 UptimePushAspect 在 XxlJob 调度时对于正常返回值的消息和状态处理,补充 XxlJob 调度示例
上级
ca111cef
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
23 行增加
和
8 行删除
+23
-8
TestJob.java
app/src/main/java/com/yiring/app/job/TestJob.java
+17
-2
UptimePush.java
...rc/main/java/com/yiring/common/annotation/UptimePush.java
+2
-2
UptimePushAspect.java
.../main/java/com/yiring/common/aspect/UptimePushAspect.java
+4
-4
没有找到文件。
app/src/main/java/com/yiring/app/job/TestJob.java
浏览文件 @
93521943
/* (C) 2024 YiRing, Inc. */
package
com
.
yiring
.
app
.
job
;
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.Uptime
;
import
java.time.LocalDateTime
;
...
...
@@ -32,12 +34,12 @@ public class TestJob {
@UptimePush
(
key
=
"BiCC4Jgoa5"
,
group
=
"Test"
,
name
=
"测试任务调度"
,
name
=
"
[TestScheduled]
测试任务调度"
,
retryCount
=
3
,
retryStatus
=
Uptime
.
Status
.
UP
)
@Scheduled
(
fixedDelay
=
5
,
timeUnit
=
TimeUnit
.
SECONDS
)
public
void
test
()
{
public
void
test
Scheduled
()
{
String
time
=
LocalDateTime
.
now
().
format
(
DateFormatter
.
DATE_TIME
);
log
.
info
(
"TestJobHandler: {}"
,
time
);
...
...
@@ -56,4 +58,17 @@ public class TestJob {
log
.
info
(
"[Test] result: {}"
,
result
);
}
@SuppressWarnings
(
"unused"
)
@UptimePush
(
key
=
"BiCC4Jgoa5"
,
group
=
"Test"
,
name
=
"[TestNoticeHandler] 测试任务调度"
)
@XxlJob
(
"TestNoticeHandler"
)
public
UptimeNotice
testNoticeHandler
()
{
Random
random
=
new
Random
();
int
randomCount
=
random
.
nextInt
(
10
);
if
(
randomCount
<
5
)
{
throw
new
UptimeException
(
"TestNoticeHandler test err"
);
}
return
UptimeNotice
.
ok
(
"测试任务调度成功"
);
}
}
basic-common/core/src/main/java/com/yiring/common/annotation/UptimePush.java
浏览文件 @
93521943
...
...
@@ -32,12 +32,12 @@ public @interface UptimePush {
String
name
()
default
""
;
/**
* 分组名
名
称
* 分组名称
*/
String
group
()
default
""
;
/**
* 重试次数
* 重试次数
, 默认为 0 不重试
*/
int
retryCount
()
default
0
;
...
...
basic-common/core/src/main/java/com/yiring/common/aspect/UptimePushAspect.java
浏览文件 @
93521943
...
...
@@ -41,6 +41,8 @@ public class UptimePushAspect {
int
retryCount
=
annotation
.
retryCount
();
// 获取当前的重试次数
Integer
currentRetryCount
=
redis
.
get
(
redisKey
,
Integer
.
class
);
// 默认状态 UP
Uptime
.
Status
status
=
Uptime
.
Status
.
UP
;
Object
result
=
null
;
String
err
=
null
;
...
...
@@ -51,7 +53,7 @@ public class UptimePushAspect {
// 针对有返回值的 Job 判断是否为 UptimeNotice 类实例
if
(
result
instanceof
UptimeNotice
value
)
{
result
=
value
.
getMsg
();
throw
new
UptimeException
(
value
.
getMsg
()
);
status
=
value
.
getStatus
(
);
}
// 开始重复计数
...
...
@@ -64,9 +66,6 @@ public class UptimePushAspect {
throw
e
;
}
}
finally
{
// 获取重试时的状态标记
Uptime
.
Status
status
=
Uptime
.
Status
.
UP
;
// 构建消息内容集合
List
<
String
>
texts
=
new
ArrayList
<>();
if
(
StrUtil
.
isNotBlank
(
annotation
.
group
()))
{
...
...
@@ -86,6 +85,7 @@ public class UptimePushAspect {
// 判断是否有异常消息
if
(
StrUtil
.
isNotBlank
(
err
))
{
// 有异常时默认状态为 DOWN
status
=
Uptime
.
Status
.
DOWN
;
if
(
retryCount
>
0
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论