Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
32a84353
authored
Feb 21, 2019
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
任务支持更换绑定执行器,方便任务分组转移和管理;
parent
9cf966c4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
42 additions
and
42 deletions
doc/XXL-JOB官方文档.md
xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java
xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml
xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl
doc/XXL-JOB官方文档.md
View file @
32a84353
## 《分
布式任务调度平台XXL-JOB》
## 《分
布式任务调度平台XXL-JOB》
...
@@ -1423,7 +1423,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
...
@@ -1423,7 +1423,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
-
9、任务暂停、删除优化,避免quartz delete不完整导致任务脏数据;
-
9、任务暂停、删除优化,避免quartz delete不完整导致任务脏数据;
-
10、任务回调、心跳注册成功日志优化,非核心常规日志调整为debug级别,降低冗余日志输出;
-
10、任务回调、心跳注册成功日志优化,非核心常规日志调整为debug级别,降低冗余日志输出;
-
11、执行器回调日志落盘方案复用RPC序列化方案,并移除Jackson依赖;
-
11、执行器回调日志落盘方案复用RPC序列化方案,并移除Jackson依赖;
-
[
迭代中
]
任务支持更换绑定执行器
;
-
12、任务支持更换绑定执行器,方便任务分组转移和管理
;
-
[
迭代中
]
注册中心优化,实时性注册发现:心跳注册间隔10s,refresh失败则首次注册并立即更新注册信息,心跳类似;30s过期销毁;
-
[
迭代中
]
注册中心优化,实时性注册发现:心跳注册间隔10s,refresh失败则首次注册并立即更新注册信息,心跳类似;30s过期销毁;
-
[
迭代中
]
脚本任务,支持数据参数,新版本仅支持单参数不支持需要兼容;
-
[
迭代中
]
脚本任务,支持数据参数,新版本仅支持单参数不支持需要兼容;
-
[
迭代中
]
提供执行器Docker镜像;
-
[
迭代中
]
提供执行器Docker镜像;
...
...
xxl-job-admin/src/main/java/com/xxl/job/admin/core/schedule/XxlJobDynamicScheduler.java
View file @
32a84353
...
@@ -164,11 +164,10 @@ public final class XxlJobDynamicScheduler {
...
@@ -164,11 +164,10 @@ public final class XxlJobDynamicScheduler {
*/
*/
public
static
void
fillJobInfo
(
XxlJobInfo
jobInfo
)
{
public
static
void
fillJobInfo
(
XxlJobInfo
jobInfo
)
{
String
group
=
String
.
valueOf
(
jobInfo
.
getJobGroup
());
String
name
=
String
.
valueOf
(
jobInfo
.
getId
());
String
name
=
String
.
valueOf
(
jobInfo
.
getId
());
// trigger key
// trigger key
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
name
,
group
);
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
name
);
try
{
try
{
// trigger cron
// trigger cron
...
@@ -198,15 +197,14 @@ public final class XxlJobDynamicScheduler {
...
@@ -198,15 +197,14 @@ public final class XxlJobDynamicScheduler {
* add trigger + job
* add trigger + job
*
*
* @param jobName
* @param jobName
* @param jobGroup
* @param cronExpression
* @param cronExpression
* @return
* @return
* @throws SchedulerException
* @throws SchedulerException
*/
*/
public
static
boolean
addJob
(
String
jobName
,
String
jobGroup
,
String
cronExpression
)
throws
SchedulerException
{
public
static
boolean
addJob
(
String
jobName
,
String
cronExpression
)
throws
SchedulerException
{
// 1、job key
// 1、job key
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
,
jobGroup
);
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
);
JobKey
jobKey
=
new
JobKey
(
jobName
,
jobGroup
);
JobKey
jobKey
=
new
JobKey
(
jobName
);
// 2、valid
// 2、valid
if
(
scheduler
.
checkExists
(
triggerKey
))
{
if
(
scheduler
.
checkExists
(
triggerKey
))
{
...
@@ -239,16 +237,15 @@ public final class XxlJobDynamicScheduler {
...
@@ -239,16 +237,15 @@ public final class XxlJobDynamicScheduler {
* remove trigger + job
* remove trigger + job
*
*
* @param jobName
* @param jobName
* @param jobGroup
* @return
* @return
* @throws SchedulerException
* @throws SchedulerException
*/
*/
public
static
boolean
removeJob
(
String
jobName
,
String
jobGroup
)
throws
SchedulerException
{
public
static
boolean
removeJob
(
String
jobName
)
throws
SchedulerException
{
JobKey
jobKey
=
new
JobKey
(
jobName
,
jobGroup
);
JobKey
jobKey
=
new
JobKey
(
jobName
);
scheduler
.
deleteJob
(
jobKey
);
scheduler
.
deleteJob
(
jobKey
);
/*TriggerKey triggerKey = TriggerKey.triggerKey(jobName
, jobGroup
);
/*TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
if (scheduler.checkExists(triggerKey)) {
if (scheduler.checkExists(triggerKey)) {
scheduler.unscheduleJob(triggerKey); // trigger + job
scheduler.unscheduleJob(triggerKey); // trigger + job
}*/
}*/
...
@@ -261,16 +258,15 @@ public final class XxlJobDynamicScheduler {
...
@@ -261,16 +258,15 @@ public final class XxlJobDynamicScheduler {
/**
/**
* updateJobCron
* updateJobCron
*
*
* @param jobGroup
* @param jobName
* @param jobName
* @param cronExpression
* @param cronExpression
* @return
* @return
* @throws SchedulerException
* @throws SchedulerException
*/
*/
public
static
boolean
updateJobCron
(
String
job
Group
,
String
job
Name
,
String
cronExpression
)
throws
SchedulerException
{
public
static
boolean
updateJobCron
(
String
jobName
,
String
cronExpression
)
throws
SchedulerException
{
// 1、job key
// 1、job key
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
,
jobGroup
);
TriggerKey
triggerKey
=
TriggerKey
.
triggerKey
(
jobName
);
// 2、valid
// 2、valid
if
(!
scheduler
.
checkExists
(
triggerKey
))
{
if
(!
scheduler
.
checkExists
(
triggerKey
))
{
...
@@ -293,7 +289,7 @@ public final class XxlJobDynamicScheduler {
...
@@ -293,7 +289,7 @@ public final class XxlJobDynamicScheduler {
scheduler
.
rescheduleJob
(
triggerKey
,
oldTrigger
);
scheduler
.
rescheduleJob
(
triggerKey
,
oldTrigger
);
/*
/*
JobKey jobKey = new JobKey(jobName
, jobGroup
);
JobKey jobKey = new JobKey(jobName);
// old job detail
// old job detail
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
JobDetail jobDetail = scheduler.getJobDetail(jobKey);
...
@@ -304,7 +300,7 @@ public final class XxlJobDynamicScheduler {
...
@@ -304,7 +300,7 @@ public final class XxlJobDynamicScheduler {
// cover trigger of job detail
// cover trigger of job detail
scheduler.scheduleJob(jobDetail, triggerSet, true);*/
scheduler.scheduleJob(jobDetail, triggerSet, true);*/
logger
.
info
(
">>>>>>>>>>> resumeJob success, Job
Group:{}, JobName:{}"
,
jobGroup
,
jobName
);
logger
.
info
(
">>>>>>>>>>> resumeJob success, Job
Name:{}"
,
jobName
);
return
true
;
return
true
;
}
}
...
@@ -313,13 +309,12 @@ public final class XxlJobDynamicScheduler {
...
@@ -313,13 +309,12 @@ public final class XxlJobDynamicScheduler {
* pause
* pause
*
*
* @param jobName
* @param jobName
* @param jobGroup
* @return
* @return
* @throws SchedulerException
* @throws SchedulerException
*/
*/
/*public static boolean pauseJob(String jobName
, String jobGroup
) throws SchedulerException {
/*public static boolean pauseJob(String jobName) throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(jobName
, jobGroup
);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
boolean result = false;
boolean result = false;
if (scheduler.checkExists(triggerKey)) {
if (scheduler.checkExists(triggerKey)) {
...
@@ -336,13 +331,12 @@ public final class XxlJobDynamicScheduler {
...
@@ -336,13 +331,12 @@ public final class XxlJobDynamicScheduler {
* resume
* resume
*
*
* @param jobName
* @param jobName
* @param jobGroup
* @return
* @return
* @throws SchedulerException
* @throws SchedulerException
*/
*/
/*public static boolean resumeJob(String jobName
, String jobGroup
) throws SchedulerException {
/*public static boolean resumeJob(String jobName) throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(jobName
, jobGroup
);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
boolean result = false;
boolean result = false;
if (scheduler.checkExists(triggerKey)) {
if (scheduler.checkExists(triggerKey)) {
...
@@ -359,14 +353,13 @@ public final class XxlJobDynamicScheduler {
...
@@ -359,14 +353,13 @@ public final class XxlJobDynamicScheduler {
* run
* run
*
*
* @param jobName
* @param jobName
* @param jobGroup
* @return
* @return
* @throws SchedulerException
* @throws SchedulerException
*/
*/
/*public static boolean triggerJob(String jobName
, String jobGroup
) throws SchedulerException {
/*public static boolean triggerJob(String jobName) throws SchedulerException {
// TriggerKey : name + group
// TriggerKey : name + group
JobKey jobKey = new JobKey(jobName
, jobGroup
);
JobKey jobKey = new JobKey(jobName);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName
, jobGroup
);
TriggerKey triggerKey = TriggerKey.triggerKey(jobName);
boolean result = false;
boolean result = false;
if (scheduler.checkExists(triggerKey)) {
if (scheduler.checkExists(triggerKey)) {
...
...
xxl-job-admin/src/main/java/com/xxl/job/admin/dao/XxlJobLogDao.java
View file @
32a84353
...
@@ -14,7 +14,8 @@ import java.util.Map;
...
@@ -14,7 +14,8 @@ import java.util.Map;
*/
*/
@Mapper
@Mapper
public
interface
XxlJobLogDao
{
public
interface
XxlJobLogDao
{
// exist jobId not use jobGroup, not exist use jobGroup
public
List
<
XxlJobLog
>
pageList
(
@Param
(
"offset"
)
int
offset
,
public
List
<
XxlJobLog
>
pageList
(
@Param
(
"offset"
)
int
offset
,
@Param
(
"pagesize"
)
int
pagesize
,
@Param
(
"pagesize"
)
int
pagesize
,
@Param
(
"jobGroup"
)
int
jobGroup
,
@Param
(
"jobGroup"
)
int
jobGroup
,
...
...
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
View file @
32a84353
...
@@ -164,13 +164,19 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -164,13 +164,19 @@ public class XxlJobServiceImpl implements XxlJobService {
jobInfo
.
setChildJobId
(
StringUtils
.
join
(
childJobIds
,
","
));
jobInfo
.
setChildJobId
(
StringUtils
.
join
(
childJobIds
,
","
));
}
}
// group valid
XxlJobGroup
jobGroup
=
xxlJobGroupDao
.
load
(
jobInfo
.
getJobGroup
());
if
(
jobGroup
==
null
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
(
I18nUtil
.
getString
(
"jobinfo_field_jobgroup"
)+
I18nUtil
.
getString
(
"system_unvalid"
))
);
}
// stage job info
// stage job info
XxlJobInfo
exists_jobInfo
=
xxlJobInfoDao
.
loadById
(
jobInfo
.
getId
());
XxlJobInfo
exists_jobInfo
=
xxlJobInfoDao
.
loadById
(
jobInfo
.
getId
());
if
(
exists_jobInfo
==
null
)
{
if
(
exists_jobInfo
==
null
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
(
I18nUtil
.
getString
(
"jobinfo_field_id"
)+
I18nUtil
.
getString
(
"system_not_found"
))
);
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
(
I18nUtil
.
getString
(
"jobinfo_field_id"
)+
I18nUtil
.
getString
(
"system_not_found"
))
);
}
}
//String old_cron = exists_jobInfo.getJobCron();
exists_jobInfo
.
setJobGroup
(
jobInfo
.
getJobGroup
());
exists_jobInfo
.
setJobCron
(
jobInfo
.
getJobCron
());
exists_jobInfo
.
setJobCron
(
jobInfo
.
getJobCron
());
exists_jobInfo
.
setJobDesc
(
jobInfo
.
getJobDesc
());
exists_jobInfo
.
setJobDesc
(
jobInfo
.
getJobDesc
());
exists_jobInfo
.
setAuthor
(
jobInfo
.
getAuthor
());
exists_jobInfo
.
setAuthor
(
jobInfo
.
getAuthor
());
...
@@ -186,10 +192,9 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -186,10 +192,9 @@ public class XxlJobServiceImpl implements XxlJobService {
// update quartz-cron if started
// update quartz-cron if started
String
qz_group
=
String
.
valueOf
(
exists_jobInfo
.
getJobGroup
());
String
qz_name
=
String
.
valueOf
(
exists_jobInfo
.
getId
());
try
{
try
{
XxlJobDynamicScheduler
.
updateJobCron
(
qz_group
,
qz_name
,
exists_jobInfo
.
getJobCron
());
String
qz_name
=
String
.
valueOf
(
exists_jobInfo
.
getId
());
XxlJobDynamicScheduler
.
updateJobCron
(
qz_name
,
exists_jobInfo
.
getJobCron
());
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
return
ReturnT
.
FAIL
;
return
ReturnT
.
FAIL
;
...
@@ -201,12 +206,14 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -201,12 +206,14 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
@Override
public
ReturnT
<
String
>
remove
(
int
id
)
{
public
ReturnT
<
String
>
remove
(
int
id
)
{
XxlJobInfo
xxlJobInfo
=
xxlJobInfoDao
.
loadById
(
id
);
XxlJobInfo
xxlJobInfo
=
xxlJobInfoDao
.
loadById
(
id
);
String
group
=
String
.
valueOf
(
xxlJobInfo
.
getJobGroup
());
if
(
xxlJobInfo
==
null
)
{
String
name
=
String
.
valueOf
(
xxlJobInfo
.
getId
());
return
ReturnT
.
SUCCESS
;
}
String
name
=
String
.
valueOf
(
xxlJobInfo
.
getId
());
try
{
try
{
// unbind quartz
// unbind quartz
XxlJobDynamicScheduler
.
removeJob
(
name
,
group
);
XxlJobDynamicScheduler
.
removeJob
(
name
);
xxlJobInfoDao
.
delete
(
id
);
xxlJobInfoDao
.
delete
(
id
);
xxlJobLogDao
.
delete
(
id
);
xxlJobLogDao
.
delete
(
id
);
...
@@ -222,12 +229,11 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -222,12 +229,11 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
@Override
public
ReturnT
<
String
>
start
(
int
id
)
{
public
ReturnT
<
String
>
start
(
int
id
)
{
XxlJobInfo
xxlJobInfo
=
xxlJobInfoDao
.
loadById
(
id
);
XxlJobInfo
xxlJobInfo
=
xxlJobInfoDao
.
loadById
(
id
);
String
group
=
String
.
valueOf
(
xxlJobInfo
.
getJobGroup
());
String
name
=
String
.
valueOf
(
xxlJobInfo
.
getId
());
String
name
=
String
.
valueOf
(
xxlJobInfo
.
getId
());
String
cronExpression
=
xxlJobInfo
.
getJobCron
();
String
cronExpression
=
xxlJobInfo
.
getJobCron
();
try
{
try
{
boolean
ret
=
XxlJobDynamicScheduler
.
addJob
(
name
,
group
,
cronExpression
);
boolean
ret
=
XxlJobDynamicScheduler
.
addJob
(
name
,
cronExpression
);
return
ret
?
ReturnT
.
SUCCESS
:
ReturnT
.
FAIL
;
return
ret
?
ReturnT
.
SUCCESS
:
ReturnT
.
FAIL
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
...
@@ -238,12 +244,11 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -238,12 +244,11 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
@Override
public
ReturnT
<
String
>
stop
(
int
id
)
{
public
ReturnT
<
String
>
stop
(
int
id
)
{
XxlJobInfo
xxlJobInfo
=
xxlJobInfoDao
.
loadById
(
id
);
XxlJobInfo
xxlJobInfo
=
xxlJobInfoDao
.
loadById
(
id
);
String
group
=
String
.
valueOf
(
xxlJobInfo
.
getJobGroup
());
String
name
=
String
.
valueOf
(
xxlJobInfo
.
getId
());
String
name
=
String
.
valueOf
(
xxlJobInfo
.
getId
());
try
{
try
{
// bind quartz
// bind quartz
boolean
ret
=
XxlJobDynamicScheduler
.
removeJob
(
name
,
group
);
boolean
ret
=
XxlJobDynamicScheduler
.
removeJob
(
name
);
return
ret
?
ReturnT
.
SUCCESS
:
ReturnT
.
FAIL
;
return
ret
?
ReturnT
.
SUCCESS
:
ReturnT
.
FAIL
;
}
catch
(
SchedulerException
e
)
{
}
catch
(
SchedulerException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
...
...
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobInfoMapper.xml
View file @
32a84353
...
@@ -142,6 +142,7 @@
...
@@ -142,6 +142,7 @@
<update
id=
"update"
parameterType=
"com.xxl.job.admin.core.model.XxlJobInfo"
>
<update
id=
"update"
parameterType=
"com.xxl.job.admin.core.model.XxlJobInfo"
>
UPDATE XXL_JOB_QRTZ_TRIGGER_INFO
UPDATE XXL_JOB_QRTZ_TRIGGER_INFO
SET
SET
job_group = #{jobGroup},
job_cron = #{jobCron},
job_cron = #{jobCron},
job_desc = #{jobDesc},
job_desc = #{jobDesc},
update_time = NOW(),
update_time = NOW(),
...
...
xxl-job-admin/src/main/resources/mybatis-mapper/XxlJobLogMapper.xml
View file @
32a84353
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
SELECT
<include
refid=
"Base_Column_List"
/>
SELECT
<include
refid=
"Base_Column_List"
/>
FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<if
test=
"jobGroup gt 0"
>
<if
test=
"job
Id==0 and job
Group gt 0"
>
AND t.job_group = #{jobGroup}
AND t.job_group = #{jobGroup}
</if>
</if>
<if
test=
"jobId gt 0"
>
<if
test=
"jobId gt 0"
>
...
@@ -82,7 +82,7 @@
...
@@ -82,7 +82,7 @@
SELECT count(1)
SELECT count(1)
FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
FROM XXL_JOB_QRTZ_TRIGGER_LOG AS t
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<trim
prefix=
"WHERE"
prefixOverrides=
"AND | OR"
>
<if
test=
"jobGroup gt 0"
>
<if
test=
"job
Id==0 and job
Group gt 0"
>
AND t.job_group = #{jobGroup}
AND t.job_group = #{jobGroup}
</if>
</if>
<if
test=
"jobId gt 0"
>
<if
test=
"jobId gt 0"
>
...
...
xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl
View file @
32a84353
...
@@ -301,7 +301,7 @@ exit 0
...
@@ -301,7 +301,7 @@ exit 0
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"firstname"
class=
"col-sm-2 control-label"
>
${I18n.jobinfo_field_jobgroup}
<font
color=
"red"
>
*
</font></label>
<label
for=
"firstname"
class=
"col-sm-2 control-label"
>
${I18n.jobinfo_field_jobgroup}
<font
color=
"red"
>
*
</font></label>
<div
class=
"col-sm-4"
>
<div
class=
"col-sm-4"
>
<select
class=
"form-control"
name=
"jobGroup"
disabled
>
<select
class=
"form-control"
name=
"jobGroup"
>
<
#
list
JobGroupList
as
group
>
<
#
list
JobGroupList
as
group
>
<option
value=
"${group.id}"
>
${group.title}
</option>
<option
value=
"${group.id}"
>
${group.title}
</option>
</
#
list>
</
#
list>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment