Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
fac8a599
Commit
fac8a599
authored
Feb 27, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
失败重试日志追加
parent
af4456b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+6
-0
ScriptDto.java
...core-common/src/main/java/com/byit/job/dto/ScriptDto.java
+4
-0
ScriptExecutorServiceImpl.java
...main/java/com/byit/service/ScriptExecutorServiceImpl.java
+30
-3
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
fac8a599
...
...
@@ -78,6 +78,10 @@ public class ScriptExecutorJobTask implements TimerTask {
*/
private
void
runJob
(
JobTaskSchedule
mythJobTaskSchedule
)
{
RunScriptService
runScriptService
=
SpringUtil
.
getBean
(
RunScriptService
.
class
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
JobTaskRunLogWithBLOBs
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
ScriptDto
scriptDto
=
new
ScriptDto
();
scriptDto
.
setLogId
(
mythJobTaskSchedule
.
getLogId
());
scriptDto
.
setCommand
(
mythJobTaskSchedule
.
getRunCommand
());
...
...
@@ -85,6 +89,8 @@ public class ScriptExecutorJobTask implements TimerTask {
scriptDto
.
setRunId
(
mythJobTaskSchedule
.
getRunId
());
scriptDto
.
setRemotePath
(
mythJobTaskSchedule
.
getScriptUrls
());
scriptDto
.
setCallbackUrl
(
"http://127.0.0.1:8998/job/callbackRes"
);
//二次执行的情况下 会有这个信息
scriptDto
.
setLogRemotePath
(
jobTaskRunLogById
.
getLogRemotelyPath
());
DispatchResponseDto
dispatchResponseDto
=
new
DispatchResponseDto
();
try
{
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
...
...
byit-myth-core/myth-core-common/src/main/java/com/byit/job/dto/ScriptDto.java
View file @
fac8a599
...
...
@@ -34,4 +34,8 @@ public class ScriptDto implements Serializable {
* 回调URL
*/
private
String
callbackUrl
;
/**
* 已有的日志路径,不存在就为null
*/
private
String
logRemotePath
;
}
byit-myth-executor/myth-executor-server/src/main/java/com/byit/service/ScriptExecutorServiceImpl.java
View file @
fac8a599
...
...
@@ -14,6 +14,7 @@ import com.byit.pool.RunThreadPool;
import
com.byit.rpc.remoting.provider.annotation.RpcService
;
import
com.byit.utils.ServiceInfoUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.IOUtils
;
import
org.csource.common.MyException
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
@@ -66,15 +67,27 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
//开始执行脚本
List
<
String
>
cmdList
=
Arrays
.
asList
(
command
,
scriptPath
);
MythJobProcess
mythJobProcess
=
new
MythJobProcess
(
cmdList
,
null
,
null
,
scriptDto
.
getLogId
());
//保存日志
String
logData
=
mythJobProcess
.
call
();
byte
[]
logDataByte
=
stringToByteArray
(
logData
);
Map
<
String
,
String
>
fileMateData
=
new
HashMap
<
String
,
String
>(
2
);
fileMateData
.
put
(
"filename"
,
scriptDto
.
getRunId
()+
scriptDto
.
getRunId
()+
".log"
);
String
logPath
=
""
;
try
{
//上传日志文件
logPath
=
fileSystem
.
uploadFile
(
logDataByte
,
"log"
,
fileMateData
);
jobRunResultDto
.
setReturnResult
(
ReturnResult
.
SUCCESS
);
//不为空 则追加
if
(
scriptDto
.
getLogRemotePath
()
!=
null
){
byte
[]
sourceLogByte
=
fileSystem
.
downloaderFile
(
scriptDto
.
getLogRemotePath
());
byte
[]
resultLogByte
=
mergeFile
(
sourceLogByte
,
logDataByte
);
//上传日志文件
logPath
=
fileSystem
.
uploadFile
(
resultLogByte
,
"log"
,
fileMateData
);
//删除原有的日志文件
fileSystem
.
fileRemove
(
scriptDto
.
getLogRemotePath
());
}
else
{
//上传日志文件
logPath
=
fileSystem
.
uploadFile
(
logDataByte
,
"log"
,
fileMateData
);
jobRunResultDto
.
setReturnResult
(
ReturnResult
.
SUCCESS
);
}
}
catch
(
ProcessFailureException
ignored
){
jobRunResultDto
.
setReturnResult
(
ReturnResult
.
FAIL
);
}
catch
(
IOException
|
MyException
e
)
{
...
...
@@ -106,6 +119,20 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
return
dispatchResponseDto
;
}
/**
* 合并两个字节数组
* @param sourceByte
* @param targetByte
* @return
*/
private
byte
[]
mergeFile
(
byte
[]
sourceByte
,
byte
[]
targetByte
){
byte
[]
result
=
new
byte
[
sourceByte
.
length
+
targetByte
.
length
];
System
.
arraycopy
(
sourceByte
,
0
,
result
,
0
,
sourceByte
.
length
);
System
.
arraycopy
(
targetByte
,
0
,
result
,
sourceByte
.
length
,
targetByte
.
length
);
return
result
;
}
/**
* 将脚本字节转换成文件
* @return 生成文件的本地路径
...
...
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