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
5b9da215
Commit
5b9da215
authored
Mar 25, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决脚本运行不通知异常的BUG
parent
7f690086
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
70 deletions
+75
-70
WaitingRecordServiceImpl.java
.../java/com/byit/service/impl/WaitingRecordServiceImpl.java
+1
-1
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+3
-3
ScriptExecutorServiceImpl.java
...main/java/com/byit/service/ScriptExecutorServiceImpl.java
+70
-65
AddComplexPy.java
...-demo-client/src/main/java/com/byit/job/AddComplexPy.java
+1
-1
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/impl/WaitingRecordServiceImpl.java
View file @
5b9da215
...
@@ -32,7 +32,7 @@ public class WaitingRecordServiceImpl implements WaitingRecordService {
...
@@ -32,7 +32,7 @@ public class WaitingRecordServiceImpl implements WaitingRecordService {
*/
*/
@Override
@Override
public
List
<
WaitingRecord
>
findAllByTriggerTime
(
long
triggerTime
)
{
public
List
<
WaitingRecord
>
findAllByTriggerTime
(
long
triggerTime
)
{
log
.
info
(
"------查询对应的等待工作流--------"
);
log
.
debug
(
"------查询对应的等待工作流--------"
);
return
waitingRecordMapper
.
findAllByTriggerTime
(
triggerTime
);
return
waitingRecordMapper
.
findAllByTriggerTime
(
triggerTime
);
}
}
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
5b9da215
...
@@ -29,7 +29,7 @@ import java.util.Date;
...
@@ -29,7 +29,7 @@ import java.util.Date;
public
class
ScriptExecutorJobTask
implements
TimerTask
{
public
class
ScriptExecutorJobTask
implements
TimerTask
{
private
final
String
HTTP_PRE
=
"http://"
;
private
final
String
HTTP_PRE
=
"http://"
;
private
final
String
HTTP_SUFFIX
=
"/job/callbackRes"
;
private
final
String
HTTP_SUFFIX
=
"/
myth-job-admin/
job/callbackRes"
;
private
JobTaskSchedule
mythJobTaskSchedule
;
private
JobTaskSchedule
mythJobTaskSchedule
;
...
@@ -101,16 +101,16 @@ public class ScriptExecutorJobTask implements TimerTask {
...
@@ -101,16 +101,16 @@ public class ScriptExecutorJobTask implements TimerTask {
try
{
try
{
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
}
catch
(
RpcException
rpcException
){
}
catch
(
RpcException
rpcException
){
log
.
error
(
"------执行机异常{}-----"
,
rpcException
.
getMessage
());
dispatchResponseDto
.
setMsg
(
rpcException
.
getMessage
());
dispatchResponseDto
.
setMsg
(
rpcException
.
getMessage
());
dispatchResponseDto
.
setCode
(
JobResultEnum
.
DISPATCH_FAIL
.
getRes
());
dispatchResponseDto
.
setCode
(
JobResultEnum
.
DISPATCH_FAIL
.
getRes
());
log
.
error
(
"--------------执行机不存在----------------"
);
}
}
saveLog
(
mythJobTaskSchedule
,
dispatchResponseDto
);
saveLog
(
mythJobTaskSchedule
,
dispatchResponseDto
);
}
}
private
void
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
,
DispatchResponseDto
dispatchResponseDto
){
private
void
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
,
DispatchResponseDto
dispatchResponseDto
){
log
.
info
(
"-----------saveLog--保存脚本调度日志开始------------"
);
log
.
debug
(
"-----------saveLog--保存脚本调度日志开始------------"
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
JobTaskRunLogWithBLOBs
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
JobTaskRunLogWithBLOBs
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
...
...
byit-myth-executor/myth-executor-server/src/main/java/com/byit/service/ScriptExecutorServiceImpl.java
View file @
5b9da215
...
@@ -54,73 +54,11 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
...
@@ -54,73 +54,11 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
@Override
@Override
public
DispatchResponseDto
runPythonScript
(
ScriptDto
scriptDto
)
{
public
DispatchResponseDto
runPythonScript
(
ScriptDto
scriptDto
)
{
log
.
info
(
"----------------runPythonScript start{} ------------------------"
,
scriptDto
);
DispatchResponseDto
dispatchResponseDto
;
DispatchResponseDto
dispatchResponseDto
;
try
{
try
{
RunThreadPool
.
SCRIPT_RUN_THREAD_POOL
.
execute
(()->{
RunThreadPool
.
SCRIPT_RUN_THREAD_POOL
.
execute
(()->{
log
.
info
(
"--------------runPythonScript,脚本调用开始-----------"
);
startScript
(
scriptDto
);
//创建回复对象
JobRunResultDto
jobRunResultDto
=
new
JobRunResultDto
();
jobRunResultDto
.
setStartTime
(
new
Date
());
//设定运行标识
jobRunResultDto
.
setJobRunId
(
scriptDto
.
getRunId
());
//获取回调通知URL
String
callbackUrl
=
scriptDto
.
getCallbackUrl
();
String
remotePath
=
scriptDto
.
getRemotePath
();
String
command
=
scriptDto
.
getCommand
();
String
param
=
scriptDto
.
getParam
();
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
null
;
if
(
null
!=
param
){
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
param
,
ScriptParamAndPlaceholderDto
.
class
);
}
String
scriptPath
=
byteArrayToFile
(
remotePath
,
scriptParamAndPlaceholderDto
);
log
.
info
(
"-------------脚本所在路径为:{}-------------"
,
scriptPath
);
//初始化命令信息
command
=
PlaceholderUtils
.
initCommand
(
command
,
scriptPath
);
//开始执行脚本
if
(
scriptParamAndPlaceholderDto
!=
null
){
command
=
PlaceholderUtils
.
commandReplace
(
command
,
scriptParamAndPlaceholderDto
.
getParam
());
}
List
<
String
>
cmdList
=
Arrays
.
asList
(
command
.
split
(
" "
));
MythJobProcess
mythJobProcess
=
new
MythJobProcess
(
cmdList
,
null
,
null
,
scriptDto
.
getLogId
(),
scriptDto
.
getRunId
(),
stringRedisTemplate
);
//保存日志
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
{
//不为空 则追加
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
)
{
jobRunResultDto
.
setReturnResult
(
ReturnResult
.
FAIL
);
e
.
printStackTrace
();
}
log
.
info
(
"-----------执行命令,{},{}-----------"
,
command
,
scriptPath
);
//设置结束时间
jobRunResultDto
.
setEndTime
(
new
Date
());
jobRunResultDto
.
setLogId
(
scriptDto
.
getLogId
());
//设置远程日志文件的路径
jobRunResultDto
.
setLogRemotelyPath
(
logPath
);
cn
.
hutool
.
http
.
HttpUtil
.
post
(
callbackUrl
,
JSON
.
toJSONString
(
jobRunResultDto
));
log
.
info
(
"--------------runPythonScript,脚本调用结束-----------"
);
});
});
dispatchResponseDto
=
DispatchResponseDto
.
builder
()
dispatchResponseDto
=
DispatchResponseDto
.
builder
()
...
@@ -134,10 +72,77 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
...
@@ -134,10 +72,77 @@ public class ScriptExecutorServiceImpl implements ScriptExecutorService {
.
build
();
.
build
();
}
}
dispatchResponseDto
.
setUrl
(
ServiceInfoUtil
.
getIpAndPort
());
dispatchResponseDto
.
setUrl
(
ServiceInfoUtil
.
getIpAndPort
());
log
.
info
(
"----------------runPythonScript end---------------------"
);
return
dispatchResponseDto
;
return
dispatchResponseDto
;
}
}
public
void
startScript
(
ScriptDto
scriptDto
){
log
.
info
(
"--------------runPythonScript,脚本调用开始-----------"
);
//创建回复对象
JobRunResultDto
jobRunResultDto
=
new
JobRunResultDto
();
jobRunResultDto
.
setStartTime
(
new
Date
());
//设定运行标识
jobRunResultDto
.
setJobRunId
(
scriptDto
.
getRunId
());
//获取回调通知URL
String
callbackUrl
=
scriptDto
.
getCallbackUrl
();
String
remotePath
=
scriptDto
.
getRemotePath
();
String
command
=
scriptDto
.
getCommand
();
String
param
=
scriptDto
.
getParam
();
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
null
;
if
(
null
!=
param
){
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
param
,
ScriptParamAndPlaceholderDto
.
class
);
}
String
scriptPath
=
byteArrayToFile
(
remotePath
,
scriptParamAndPlaceholderDto
);
log
.
info
(
"-------------脚本所在路径为:{}-------------"
,
scriptPath
);
//初始化命令信息
command
=
PlaceholderUtils
.
initCommand
(
command
,
scriptPath
);
//开始执行脚本
if
(
scriptParamAndPlaceholderDto
!=
null
){
command
=
PlaceholderUtils
.
commandReplace
(
command
,
scriptParamAndPlaceholderDto
.
getParam
());
}
List
<
String
>
cmdList
=
Arrays
.
asList
(
command
.
split
(
" "
));
MythJobProcess
mythJobProcess
=
new
MythJobProcess
(
cmdList
,
null
,
null
,
scriptDto
.
getLogId
(),
scriptDto
.
getRunId
(),
stringRedisTemplate
);
//保存日志
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
{
//不为空 则追加
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
)
{
jobRunResultDto
.
setReturnResult
(
ReturnResult
.
FAIL
);
e
.
printStackTrace
();
}
log
.
info
(
"-----------执行命令,{},{}-----------"
,
command
,
scriptPath
);
//设置结束时间
jobRunResultDto
.
setEndTime
(
new
Date
());
jobRunResultDto
.
setLogId
(
scriptDto
.
getLogId
());
//设置远程日志文件的路径
jobRunResultDto
.
setLogRemotelyPath
(
logPath
);
cn
.
hutool
.
http
.
HttpUtil
.
post
(
callbackUrl
,
JSON
.
toJSONString
(
jobRunResultDto
));
log
.
info
(
"--------------runPythonScript,脚本调用结束-----------"
);
}
/**
/**
* 合并两个字节数组
* 合并两个字节数组
...
...
demo-client/byit-demo-client/src/main/java/com/byit/job/AddComplexPy.java
View file @
5b9da215
...
@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
...
@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
public
class
AddComplexPy
{
public
class
AddComplexPy
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
RunNode
runNode
=
new
RunNode
();
RunNode
runNode
=
new
RunNode
();
runNode
.
setScriptUrl
(
"ddmp/M00/00/0
0/CgB4Al5wa36AaUJ7AAAAiYy1k-k980
1.py"
);
runNode
.
setScriptUrl
(
"ddmp/M00/00/0
1/CgB4Al5wa6WAfhQ9AAAAN9Xm1mU122
1.py"
);
runNode
.
setJobType
(
"PYTHON"
);
runNode
.
setJobType
(
"PYTHON"
);
runNode
.
setNodeId
(
"2"
);
runNode
.
setNodeId
(
"2"
);
runNode
.
setNodeName
(
"lijkki"
);
runNode
.
setNodeName
(
"lijkki"
);
...
...
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