Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
promotion-service
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
promotion
promotion-service
Commits
0d0b4c57
提交
0d0b4c57
authored
5月 21, 2024
作者:
李秋林
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加xxl_job配置
上级
c7c6a68c
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
154 行增加
和
0 行删除
+154
-0
pom.xml
pom.xml
+8
-0
XxlJobConfig.java
.../com/wangxiaolu/promotion/config/thread/XxlJobConfig.java
+79
-0
XxlJobHandler.java
...ava/com/wangxiaolu/promotion/timedtask/XxlJobHandler.java
+38
-0
application-dev.yml
src/main/resources/application-dev.yml
+14
-0
application-live.yml
src/main/resources/application-live.yml
+15
-0
没有找到文件。
pom.xml
浏览文件 @
0d0b4c57
...
@@ -184,6 +184,14 @@
...
@@ -184,6 +184,14 @@
<version>
4.0.1
</version>
<version>
4.0.1
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.xuxueli/xxl-job-core -->
<dependency>
<groupId>
com.xuxueli
</groupId>
<artifactId>
xxl-job-core
</artifactId>
<version>
2.4.0
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/wangxiaolu/promotion/config/thread/XxlJobConfig.java
0 → 100644
浏览文件 @
0d0b4c57
package
com
.
wangxiaolu
.
promotion
.
config
.
thread
;
import
com.xxl.job.core.executor.impl.XxlJobSpringExecutor
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* xxl-job config
*
* @author xuxueli 2017-04-28
*/
@Configuration
public
class
XxlJobConfig
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
XxlJobConfig
.
class
);
@Value
(
"${xxl.job.admin.addresses}"
)
private
String
adminAddresses
;
@Value
(
"${xxl.job.accessToken}"
)
private
String
accessToken
;
@Value
(
"${xxl.job.executor.appname}"
)
private
String
appname
;
@Value
(
"${xxl.job.executor.address}"
)
private
String
address
;
@Value
(
"${xxl.job.executor.ip}"
)
private
String
ip
;
@Value
(
"${xxl.job.executor.port}"
)
private
int
port
;
@Value
(
"${xxl.job.executor.logpath}"
)
private
String
logPath
;
@Value
(
"${xxl.job.executor.logretentiondays}"
)
private
int
logRetentionDays
;
@Bean
public
XxlJobSpringExecutor
xxlJobExecutor
()
{
logger
.
info
(
">>>>>>>>>>> xxl-job config init."
);
XxlJobSpringExecutor
xxlJobSpringExecutor
=
new
XxlJobSpringExecutor
();
xxlJobSpringExecutor
.
setAdminAddresses
(
adminAddresses
);
xxlJobSpringExecutor
.
setAppname
(
appname
);
xxlJobSpringExecutor
.
setAddress
(
address
);
xxlJobSpringExecutor
.
setIp
(
ip
);
xxlJobSpringExecutor
.
setPort
(
port
);
xxlJobSpringExecutor
.
setAccessToken
(
accessToken
);
xxlJobSpringExecutor
.
setLogPath
(
logPath
);
xxlJobSpringExecutor
.
setLogRetentionDays
(
logRetentionDays
);
return
xxlJobSpringExecutor
;
}
/**
* 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
*
* 1、引入依赖:
* <dependency>
* <groupId>org.springframework.cloud</groupId>
* <artifactId>spring-cloud-commons</artifactId>
* <version>${version}</version>
* </dependency>
*
* 2、配置文件,或者容器启动变量
* spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
*
* 3、获取IP
* String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
*/
}
\ No newline at end of file
src/main/java/com/wangxiaolu/promotion/timedtask/XxlJobHandler.java
0 → 100644
浏览文件 @
0d0b4c57
package
com
.
wangxiaolu
.
promotion
.
timedtask
;
import
com.xxl.job.core.context.XxlJobHelper
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
/**
* XxlJob开发示例(Bean模式)
*
* 开发步骤:
* 1、任务开发:在Spring Bean实例中,开发Job方法;
* 2、注解配置:为Job方法添加注解 "@XxlJob(value="自定义jobhandler名称", init = "JobHandler初始化方法", destroy = "JobHandler销毁方法")",注解value值对应的是调度中心新建任务的JobHandler属性的值。
* 3、执行日志:需要通过 "XxlJobHelper.log" 打印执行日志;
* 4、任务结果:默认任务结果为 "成功" 状态,不需要主动设置;如有诉求,比如设置任务结果为失败,可以通过 "XxlJobHelper.handleFail/handleSuccess" 自主设置任务结果;
*
* @author xuxueli 2019-12-11 21:52:51
*/
@Component
@Slf4j
public
class
XxlJobHandler
{
/**
* 1、简单任务示例(Bean模式)
*/
@XxlJob
(
"demoJobHandler"
)
public
void
demoJobHandler
()
throws
Exception
{
log
.
info
(
"XXL-JOB, Hello World."
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
XxlJobHelper
.
log
(
"test beat at:"
+
i
);
}
log
.
info
(
"xxl job task end"
);
}
}
src/main/resources/application-dev.yml
浏览文件 @
0d0b4c57
...
@@ -59,3 +59,17 @@ qince:
...
@@ -59,3 +59,17 @@ qince:
mybatis-plus
:
mybatis-plus
:
configuration
:
configuration
:
log-impl
:
org.apache.ibatis.logging.slf4j.Slf4jImpl
log-impl
:
org.apache.ibatis.logging.slf4j.Slf4jImpl
# xxl-job配置
xxl
:
job
:
accessToken
:
default_token
admin
:
addresses
:
http://42.193.103.153:9001/xxl-job-admin
executor
:
appname
:
promotion-dev
port
:
9999
logretentiondays
:
30
address
:
ip
:
logpath
:
/var/logs/xxl_job
# 执行器日志路径
src/main/resources/application-live.yml
浏览文件 @
0d0b4c57
...
@@ -59,3 +59,17 @@ qince:
...
@@ -59,3 +59,17 @@ qince:
mybatis-plus
:
mybatis-plus
:
configuration
:
configuration
:
log-impl
:
org.apache.ibatis.logging.slf4j.Slf4jImpl
log-impl
:
org.apache.ibatis.logging.slf4j.Slf4jImpl
# xxl-job配置
xxl
:
job
:
accessToken
:
default_token
admin
:
addresses
:
http://42.193.103.153:9001/xxl-job-admin
executor
:
appname
:
promotion-live
port
:
9998
logretentiondays
:
30
address
:
ip
:
logpath
:
/var/logs/xxl_job
# 执行器日志路径
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论