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
9325afea
authored
Dec 22, 2017
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复Log路径生成异常问题;
新增JobKey处理工具;
parent
2f2ed563
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
13 deletions
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JobKeyUtil.java
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JobKeyUtil.java
View file @
9325afea
package
com
.
xxl
.
job
.
admin
.
core
.
util
;
package
com
.
xxl
.
job
.
admin
.
core
.
util
;
import
com.xxl.job.admin.core.model.XxlJobInfo
;
import
com.xxl.job.admin.core.model.XxlJobInfo
;
import
org.apache.commons.lang.StringUtils
;
/**
/**
* job key util
* job key util
...
@@ -20,4 +21,24 @@ public class JobKeyUtil {
...
@@ -20,4 +21,24 @@ public class JobKeyUtil {
.
concat
(
"_"
).
concat
(
String
.
valueOf
(
xxlJobInfo
.
getId
()));
.
concat
(
"_"
).
concat
(
String
.
valueOf
(
xxlJobInfo
.
getId
()));
}
}
/**
* parse jobId from JobKey
*
* @param jobKey
* @return
*/
public
static
int
parseJobId
(
String
jobKey
){
if
(
jobKey
!=
null
&&
jobKey
.
trim
().
length
()>
0
)
{
String
[]
jobKeyArr
=
jobKey
.
split
(
"_"
);
if
(
jobKeyArr
.
length
==
2
)
{
String
jobIdStr
=
jobKeyArr
[
1
];
if
(
StringUtils
.
isNotBlank
(
jobIdStr
)
&&
StringUtils
.
isNumeric
(
jobIdStr
))
{
int
jobId
=
Integer
.
valueOf
(
jobIdStr
);
return
jobId
;
}
}
}
return
-
1
;
}
}
}
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/AdminBizImpl.java
View file @
9325afea
...
@@ -5,6 +5,7 @@ import com.xxl.job.admin.core.model.XxlJobInfo;
...
@@ -5,6 +5,7 @@ import com.xxl.job.admin.core.model.XxlJobInfo;
import
com.xxl.job.admin.core.model.XxlJobLog
;
import
com.xxl.job.admin.core.model.XxlJobLog
;
import
com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler
;
import
com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler
;
import
com.xxl.job.admin.core.trigger.XxlJobTrigger
;
import
com.xxl.job.admin.core.trigger.XxlJobTrigger
;
import
com.xxl.job.admin.core.util.JobKeyUtil
;
import
com.xxl.job.admin.dao.XxlJobInfoDao
;
import
com.xxl.job.admin.dao.XxlJobInfoDao
;
import
com.xxl.job.admin.dao.XxlJobLogDao
;
import
com.xxl.job.admin.dao.XxlJobLogDao
;
import
com.xxl.job.admin.dao.XxlJobRegistryDao
;
import
com.xxl.job.admin.dao.XxlJobRegistryDao
;
...
@@ -72,9 +73,9 @@ public class AdminBizImpl implements AdminBiz {
...
@@ -72,9 +73,9 @@ public class AdminBizImpl implements AdminBiz {
String
[]
childJobKeys
=
xxlJobInfo
.
getChildJobKey
().
split
(
","
);
String
[]
childJobKeys
=
xxlJobInfo
.
getChildJobKey
().
split
(
","
);
for
(
int
i
=
0
;
i
<
childJobKeys
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
childJobKeys
.
length
;
i
++)
{
String
[]
jobKeyArr
=
childJobKeys
[
i
].
split
(
"_"
);
int
childJobId
=
JobKeyUtil
.
parseJobId
(
childJobKeys
[
i
]
);
if
(
jobKeyArr
!=
null
&&
jobKeyArr
.
length
==
2
)
{
if
(
childJobId
>
0
)
{
ReturnT
<
String
>
triggerChildResult
=
xxlJobService
.
triggerJob
(
Integer
.
valueOf
(
jobKeyArr
[
1
])
);
ReturnT
<
String
>
triggerChildResult
=
xxlJobService
.
triggerJob
(
childJobId
);
// add msg
// add msg
callbackMsg
+=
MessageFormat
.
format
(
"{0}/{1} [JobKey={2}], 触发{3}, 触发备注: {4} <br>"
,
callbackMsg
+=
MessageFormat
.
format
(
"{0}/{1} [JobKey={2}], 触发{3}, 触发备注: {4} <br>"
,
...
...
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
View file @
9325afea
...
@@ -5,6 +5,7 @@ import com.xxl.job.admin.core.model.XxlJobGroup;
...
@@ -5,6 +5,7 @@ import com.xxl.job.admin.core.model.XxlJobGroup;
import
com.xxl.job.admin.core.model.XxlJobInfo
;
import
com.xxl.job.admin.core.model.XxlJobInfo
;
import
com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum
;
import
com.xxl.job.admin.core.route.ExecutorRouteStrategyEnum
;
import
com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler
;
import
com.xxl.job.admin.core.schedule.XxlJobDynamicScheduler
;
import
com.xxl.job.admin.core.util.JobKeyUtil
;
import
com.xxl.job.admin.dao.XxlJobGroupDao
;
import
com.xxl.job.admin.dao.XxlJobGroupDao
;
import
com.xxl.job.admin.dao.XxlJobInfoDao
;
import
com.xxl.job.admin.dao.XxlJobInfoDao
;
import
com.xxl.job.admin.dao.XxlJobLogDao
;
import
com.xxl.job.admin.dao.XxlJobLogDao
;
...
@@ -107,11 +108,11 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -107,11 +108,11 @@ public class XxlJobServiceImpl implements XxlJobService {
if
(
StringUtils
.
isNotBlank
(
jobInfo
.
getChildJobKey
()))
{
if
(
StringUtils
.
isNotBlank
(
jobInfo
.
getChildJobKey
()))
{
String
[]
childJobKeys
=
jobInfo
.
getChildJobKey
().
split
(
","
);
String
[]
childJobKeys
=
jobInfo
.
getChildJobKey
().
split
(
","
);
for
(
String
childJobKeyItem:
childJobKeys
)
{
for
(
String
childJobKeyItem:
childJobKeys
)
{
String
[]
childJobKeyArr
=
childJobKeyItem
.
split
(
"_"
);
int
childJobId
=
JobKeyUtil
.
parseJobId
(
childJobKeyItem
);
if
(
childJob
KeyArr
.
length
!=
2
)
{
if
(
childJob
Id
<=
0
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})格式错误"
,
childJobKeyItem
));
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})格式错误"
,
childJobKeyItem
));
}
}
XxlJobInfo
childJobInfo
=
xxlJobInfoDao
.
loadById
(
Integer
.
valueOf
(
childJobKeyArr
[
1
])
);
XxlJobInfo
childJobInfo
=
xxlJobInfoDao
.
loadById
(
childJobId
);
if
(
childJobInfo
==
null
)
{
if
(
childJobInfo
==
null
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})无效"
,
childJobKeyItem
));
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})无效"
,
childJobKeyItem
));
}
}
...
@@ -170,11 +171,11 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -170,11 +171,11 @@ public class XxlJobServiceImpl implements XxlJobService {
if
(
StringUtils
.
isNotBlank
(
jobInfo
.
getChildJobKey
()))
{
if
(
StringUtils
.
isNotBlank
(
jobInfo
.
getChildJobKey
()))
{
String
[]
childJobKeys
=
jobInfo
.
getChildJobKey
().
split
(
","
);
String
[]
childJobKeys
=
jobInfo
.
getChildJobKey
().
split
(
","
);
for
(
String
childJobKeyItem:
childJobKeys
)
{
for
(
String
childJobKeyItem:
childJobKeys
)
{
String
[]
childJobKeyArr
=
childJobKeyItem
.
split
(
"_"
);
int
childJobId
=
JobKeyUtil
.
parseJobId
(
childJobKeyItem
);
if
(
childJob
KeyArr
.
length
!=
2
)
{
if
(
childJob
Id
<=
0
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})格式错误"
,
childJobKeyItem
));
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})格式错误"
,
childJobKeyItem
));
}
}
XxlJobInfo
childJobInfo
=
xxlJobInfoDao
.
loadById
(
Integer
.
valueOf
(
childJobKeyArr
[
1
])
);
XxlJobInfo
childJobInfo
=
xxlJobInfoDao
.
loadById
(
childJobId
);
if
(
childJobInfo
==
null
)
{
if
(
childJobInfo
==
null
)
{
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})无效"
,
childJobKeyItem
));
return
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
MessageFormat
.
format
(
"子任务Key({0})无效"
,
childJobKeyItem
));
}
}
...
...
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
View file @
9325afea
...
@@ -53,11 +53,16 @@ public class XxlJobFileAppender {
...
@@ -53,11 +53,16 @@ public class XxlJobFileAppender {
* @return
* @return
*/
*/
public
static
String
makeLogFileName
(
Date
triggerDate
,
int
logId
)
{
public
static
String
makeLogFileName
(
Date
triggerDate
,
int
logId
)
{
// filePath/yyyy-MM-dd/9999.log
// filePath/yyyy-MM-dd
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
// avoid concurrent problem, can not be static
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
// avoid concurrent problem, can not be static
String
logFileName
=
getLogPath
()
File
logFilePath
=
new
File
(
getLogPath
(),
sdf
.
format
(
triggerDate
));
.
concat
(
"/"
)
if
(!
logFilePath
.
exists
())
{
.
concat
(
sdf
.
format
(
triggerDate
))
logFilePath
.
mkdir
();
}
// filePath/yyyy-MM-dd/9999.log
String
logFileName
=
logFilePath
.
getPath
()
.
concat
(
"/"
)
.
concat
(
"/"
)
.
concat
(
String
.
valueOf
(
logId
))
.
concat
(
String
.
valueOf
(
logId
))
.
concat
(
".log"
);
.
concat
(
".log"
);
...
...
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