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
4492cf56
Commit
4492cf56
authored
May 21, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决立即执行异常卡死状态
parent
c68f875c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
14 deletions
+41
-14
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+41
-14
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
4492cf56
...
...
@@ -20,6 +20,7 @@ import io.netty.util.Timeout;
import
io.netty.util.TimerTask
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.validation.annotation.Validated
;
import
java.util.Date
;
...
...
@@ -35,6 +36,7 @@ public class ScriptExecutorJobTask implements TimerTask {
private
static
final
String
HTTP_PRE
=
"http://"
;
private
static
final
String
HTTP_SUFFIX
=
"/myth-job-admin/job/callbackRes"
;
public
static
final
String
LINE
=
"\n"
;
private
static
final
Integer
INIT_SLEEP_TIME
=
100
;
private
JobTaskSchedule
mythJobTaskSchedule
;
...
...
@@ -90,22 +92,22 @@ public class ScriptExecutorJobTask implements TimerTask {
* @param mythJobTaskSchedule 运行的排期表
*/
private
void
runJob
(
JobTaskSchedule
mythJobTaskSchedule
)
{
RunScriptService
runScriptService
=
SpringUtil
.
getBean
(
RunScriptService
.
class
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
log
.
info
(
"--------------logid:{}----------"
,
mythJobTaskSchedule
.
getLogId
());
JobTaskRunLogWithBLOBs
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
log
.
info
(
"--------------jobTaskRunLogById:{}----------"
,
jobTaskRunLogById
);
ScriptDto
scriptDto
=
new
ScriptDto
();
scriptDto
.
setLogId
(
mythJobTaskSchedule
.
getLogId
());
scriptDto
.
setCommand
(
mythJobTaskSchedule
.
getRunCommand
());
scriptDto
.
setParam
(
mythJobTaskSchedule
.
getRunParam
());
scriptDto
.
setRunId
(
mythJobTaskSchedule
.
getRunId
());
scriptDto
.
setRemotePath
(
mythJobTaskSchedule
.
getScriptUrls
());
scriptDto
.
setCallbackUrl
(
HTTP_PRE
+
ServiceInfoUtil
.
getIpAndPort
()+
HTTP_SUFFIX
);
//二次执行的情况下 会有这个信息 //TODO 还是有问题
scriptDto
.
setLogRemotePath
(
jobTaskRunLogById
.
getLogRemotelyPath
());
DispatchResponseDto
dispatchResponseDto
=
new
DispatchResponseDto
();
try
{
RunScriptService
runScriptService
=
SpringUtil
.
getBean
(
RunScriptService
.
class
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
log
.
info
(
"--------------logid:{}----------"
,
mythJobTaskSchedule
.
getLogId
());
JobTaskRunLogWithBLOBs
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
jobTaskRunLogById
=
spinLock
(
jobTaskRunLogById
);
ScriptDto
scriptDto
=
new
ScriptDto
();
scriptDto
.
setLogId
(
mythJobTaskSchedule
.
getLogId
());
scriptDto
.
setCommand
(
mythJobTaskSchedule
.
getRunCommand
());
scriptDto
.
setParam
(
mythJobTaskSchedule
.
getRunParam
());
scriptDto
.
setRunId
(
mythJobTaskSchedule
.
getRunId
());
scriptDto
.
setRemotePath
(
mythJobTaskSchedule
.
getScriptUrls
());
scriptDto
.
setCallbackUrl
(
HTTP_PRE
+
ServiceInfoUtil
.
getIpAndPort
()+
HTTP_SUFFIX
);
//二次执行的情况下 会有这个信息
scriptDto
.
setLogRemotePath
(
jobTaskRunLogById
.
getLogRemotelyPath
());
dispatchResponseDto
=
runScriptService
.
runScript
(
scriptDto
);
}
catch
(
Exception
e
){
StringRedisTemplate
stringRedisTemplate
=
(
StringRedisTemplate
)
SpringUtil
.
getBean
(
"stringRedisTemplate"
);
...
...
@@ -121,6 +123,31 @@ public class ScriptExecutorJobTask implements TimerTask {
saveLog
(
mythJobTaskSchedule
,
dispatchResponseDto
);
}
/**
* 模拟自旋锁实现
* @param jobTaskRunLogById
* @return
* @throws InterruptedException
*/
private
JobTaskRunLogWithBLOBs
spinLock
(
JobTaskRunLogWithBLOBs
jobTaskRunLogById
)
throws
InterruptedException
{
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
int
i
=
1
;
while
(
jobTaskRunLogById
==
null
)
{
Thread
.
sleep
(
i
*
INIT_SLEEP_TIME
);
jobTaskRunLogById
=
jobTaskRunLogService
.
findJobTaskRunLogById
(
mythJobTaskSchedule
.
getLogId
());
if
(
i
>=
3
){
break
;
}
i
++;
}
if
(
jobTaskRunLogById
!=
null
){
return
jobTaskRunLogById
;
}
throw
new
RuntimeException
(
"服务器分配资源失败"
);
}
private
void
saveLog
(
JobTaskSchedule
mythJobTaskSchedule
,
DispatchResponseDto
dispatchResponseDto
){
log
.
debug
(
"-----------saveLog--保存脚本调度日志开始------------"
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
...
...
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