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
9f699d8b
Commit
9f699d8b
authored
Oct 16, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加jobUtil错误重试,增加立即运行节点强制超时判断
parent
e7b9a292
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
12 deletions
+70
-12
JobTaskRunLogMapper.java
...re/src/main/java/com/byit/mapper/JobTaskRunLogMapper.java
+1
-1
JobTaskRunLogService.java
.../src/main/java/com/byit/service/JobTaskRunLogService.java
+1
-1
JobTaskRunLogServiceImpl.java
.../java/com/byit/service/impl/JobTaskRunLogServiceImpl.java
+1
-1
UnfinishedNodeMonitoringRunHelper.java
...byit/thread/helper/UnfinishedNodeMonitoringRunHelper.java
+22
-4
JobTaskRunLogMapper.xml
...in-core/src/main/resources/mapper/JobTaskRunLogMapper.xml
+6
-2
JobUtils.java
...xecutor-plugin/src/main/java/com/byit/utils/JobUtils.java
+39
-3
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/mapper/JobTaskRunLogMapper.java
View file @
9f699d8b
...
@@ -19,7 +19,7 @@ public interface JobTaskRunLogMapper {
...
@@ -19,7 +19,7 @@ public interface JobTaskRunLogMapper {
* 查询立即运行节点未完成的
* 查询立即运行节点未完成的
* @return 所有运行中的
* @return 所有运行中的
*/
*/
List
<
JobTaskRunLog
>
findTempRunNodeList
();
List
<
JobTaskRunLog
WithBLOBs
>
findTempRunNodeList
();
List
<
JobTaskRunLogWithBLOBs
>
findAllByType
(
@Param
(
"type"
)
Integer
type
,
@Param
(
"jobName"
)
String
jobName
);
List
<
JobTaskRunLogWithBLOBs
>
findAllByType
(
@Param
(
"type"
)
Integer
type
,
@Param
(
"jobName"
)
String
jobName
);
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/JobTaskRunLogService.java
View file @
9f699d8b
...
@@ -18,7 +18,7 @@ public interface JobTaskRunLogService {
...
@@ -18,7 +18,7 @@ public interface JobTaskRunLogService {
* 查询立即运行节点未完成的
* 查询立即运行节点未完成的
* @return 所有运行中的
* @return 所有运行中的
*/
*/
List
<
JobTaskRunLog
>
findTempRunNodeList
();
List
<
JobTaskRunLog
WithBLOBs
>
findTempRunNodeList
();
List
<
JobTaskRunLogWithBLOBs
>
findAllByType
(
Integer
type
,
String
jobName
);
List
<
JobTaskRunLogWithBLOBs
>
findAllByType
(
Integer
type
,
String
jobName
);
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/impl/JobTaskRunLogServiceImpl.java
View file @
9f699d8b
...
@@ -41,7 +41,7 @@ public class JobTaskRunLogServiceImpl implements JobTaskRunLogService {
...
@@ -41,7 +41,7 @@ public class JobTaskRunLogServiceImpl implements JobTaskRunLogService {
}
}
@Override
@Override
public
List
<
JobTaskRunLog
>
findTempRunNodeList
()
{
public
List
<
JobTaskRunLog
WithBLOBs
>
findTempRunNodeList
()
{
return
jobTaskRunLogMapper
.
findTempRunNodeList
();
return
jobTaskRunLogMapper
.
findTempRunNodeList
();
}
}
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/helper/UnfinishedNodeMonitoringRunHelper.java
View file @
9f699d8b
...
@@ -3,7 +3,9 @@ package com.byit.thread.helper;
...
@@ -3,7 +3,9 @@ package com.byit.thread.helper;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.dto.plugin.RunLog
;
import
com.byit.enums.task.RunResultEnum
;
import
com.byit.model.JobTaskRunLog
;
import
com.byit.model.JobTaskRunLog
;
import
com.byit.model.JobTaskRunLogWithBLOBs
;
import
com.byit.service.JobTaskRunLogService
;
import
com.byit.service.JobTaskRunLogService
;
import
com.byit.thread.BaseThreadRunHelper
;
import
com.byit.thread.BaseThreadRunHelper
;
import
com.byit.util.IDGenerationStrategy
;
import
com.byit.util.IDGenerationStrategy
;
...
@@ -12,10 +14,12 @@ import org.springframework.data.redis.core.StringRedisTemplate;
...
@@ -12,10 +14,12 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
static
com
.
alibaba
.
fastjson
.
serializer
.
SerializerFeature
.
WriteClassName
;
import
static
com
.
alibaba
.
fastjson
.
serializer
.
SerializerFeature
.
WriteClassName
;
/**
/**
* 立即运行节点执行监控 24小内的节点信息 24小时内未执行完的数据全部置为失败,删除redis的心跳信息
* @author huangfu
* @author huangfu
*/
*/
@Slf4j
@Slf4j
...
@@ -26,6 +30,10 @@ public class UnfinishedNodeMonitoringRunHelper extends BaseThreadRunHelper {
...
@@ -26,6 +30,10 @@ public class UnfinishedNodeMonitoringRunHelper extends BaseThreadRunHelper {
*/
*/
private
static
final
String
PENG
=
"PENG"
;
private
static
final
String
PENG
=
"PENG"
;
/**
/**
* 默认一天
*/
private
static
final
Long
OVERTIME_TIME
=
TimeUnit
.
DAYS
.
toMillis
(
1
);
/**
* 心跳前缀
* 心跳前缀
*/
*/
private
final
StringRedisTemplate
stringRedisTemplate
;
private
final
StringRedisTemplate
stringRedisTemplate
;
...
@@ -38,13 +46,23 @@ public class UnfinishedNodeMonitoringRunHelper extends BaseThreadRunHelper {
...
@@ -38,13 +46,23 @@ public class UnfinishedNodeMonitoringRunHelper extends BaseThreadRunHelper {
@Override
@Override
public
Long
start
()
{
public
Long
start
()
{
List
<
JobTaskRunLog
>
tempRunNodeList
=
jobTaskRunLogService
.
findTempRunNodeList
();
List
<
JobTaskRunLog
WithBLOBs
>
tempRunNodeList
=
jobTaskRunLogService
.
findTempRunNodeList
();
if
(
CollectionUtil
.
isNotEmpty
(
tempRunNodeList
))
{
if
(
CollectionUtil
.
isNotEmpty
(
tempRunNodeList
))
{
tempRunNodeList
.
forEach
(
nodeLog
->
{
tempRunNodeList
.
forEach
(
nodeLog
->
{
log
.
debug
(
"-----节点{}未执行完毕-----"
,
nodeLog
);
String
keyGenerationStrategy
=
IDGenerationStrategy
.
keyGenerationStrategy
(
nodeLog
.
getLogId
());
String
keyGenerationStrategy
=
IDGenerationStrategy
.
keyGenerationStrategy
(
nodeLog
.
getLogId
());
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
false
).
runLog
(
PENG
).
build
();
if
(
System
.
currentTimeMillis
()
-
nodeLog
.
getTriggerTime
().
getTime
()
>
OVERTIME_TIME
){
stringRedisTemplate
.
opsForList
().
rightPush
(
keyGenerationStrategy
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
log
.
warn
(
"-----节点{},执行时间超时,强制失败,删除心跳节点-----"
,
nodeLog
);
nodeLog
.
setRunCode
(
RunResultEnum
.
RUN_ERROR
.
getCode
());
nodeLog
.
setRunMsg
(
"节点执行超时,强制失败!"
);
stringRedisTemplate
.
delete
(
keyGenerationStrategy
);
jobTaskRunLogService
.
updateJobTaskRunLog
(
nodeLog
);
}
else
{
log
.
debug
(
"-----节点{}未执行完毕-----"
,
nodeLog
);
RunLog
runLog
=
RunLog
.
builder
().
isEnd
(
false
).
runLog
(
PENG
).
build
();
stringRedisTemplate
.
opsForList
().
rightPush
(
keyGenerationStrategy
,
JSON
.
toJSONString
(
runLog
,
WriteClassName
));
}
});
});
}
}
return
5000L
;
return
5000L
;
...
...
byit-myth-core/myth-admin-core/src/main/resources/mapper/JobTaskRunLogMapper.xml
View file @
9f699d8b
...
@@ -49,8 +49,12 @@
...
@@ -49,8 +49,12 @@
run_msg, trigger_msg
run_msg, trigger_msg
</sql>
</sql>
<select
id=
"findTempRunNodeList"
resultMap=
"BaseResultMap"
>
<select
id=
"findTempRunNodeList"
resultMap=
"ResultMapWithBLOBs"
>
select
<include
refid=
"Base_Column_List"
/>
from job_task_run_log where schedule_type = 4 and run_code = '0'
select
<include
refid=
"Base_Column_List"
/>
,
<include
refid=
"Blob_Column_List"
/>
from job_task_run_log where schedule_type = 4 and run_code = '0'
</select>
</select>
<!--根据runId 和 上级节点的集合 查询所有的上级节点-->
<!--根据runId 和 上级节点的集合 查询所有的上级节点-->
...
...
byit-myth-executor/myth-executor-plugin/src/main/java/com/byit/utils/JobUtils.java
View file @
9f699d8b
...
@@ -8,6 +8,7 @@ import com.byit.dto.plugin.*;
...
@@ -8,6 +8,7 @@ import com.byit.dto.plugin.*;
import
com.byit.dto.specials.SpecialJobParam
;
import
com.byit.dto.specials.SpecialJobParam
;
import
com.byit.dto.web.ResponseResult
;
import
com.byit.dto.web.ResponseResult
;
import
com.byit.executor.handler.interfaces.IJobHandler
;
import
com.byit.executor.handler.interfaces.IJobHandler
;
import
com.byit.rpc.util.RPCLogUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -29,6 +30,10 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
...
@@ -29,6 +30,10 @@ import static com.alibaba.fastjson.serializer.SerializerFeature.WriteClassName;
public
class
JobUtils
{
public
class
JobUtils
{
private
static
String
REQUEST_URL
;
private
static
String
REQUEST_URL
;
/**
/**
* 错误重试次数
*/
private
static
Integer
DEFAULT_RETRY_COUNT
=
3
;
/**
* 存储token
* 存储token
*/
*/
private
static
final
ThreadLocal
<
String
>
TOKEN_THREADLOCAL
=
new
ThreadLocal
<
String
>();
private
static
final
ThreadLocal
<
String
>
TOKEN_THREADLOCAL
=
new
ThreadLocal
<
String
>();
...
@@ -217,13 +222,44 @@ public class JobUtils {
...
@@ -217,13 +222,44 @@ public class JobUtils {
if
(
StringUtils
.
isBlank
(
token
))
{
if
(
StringUtils
.
isBlank
(
token
))
{
throw
new
RuntimeException
(
"请求的token尚未设置!"
);
throw
new
RuntimeException
(
"请求的token尚未设置!"
);
}
}
HttpRequest
httpRequest
=
HttpRequest
.
post
(
REQUEST_URL
+
requestUrl
);
httpRequest
.
header
(
"token"
,
token
);
String
response
=
requestPostServer
(
requestUrl
,
body
,
token
,
DEFAULT_RETRY_COUNT
,
0
);
String
response
=
httpRequest
.
body
(
body
).
execute
().
body
();
return
response
;
return
response
;
}
}
/**
/**
* 重试
* @param requestUrl 请求的url
* @param body 数据包
* @param retryTotalCount 总共的重试次数
* @param thisRetryCount 当前的重试次数
* @return
*/
private
static
String
requestPostServer
(
String
requestUrl
,
String
body
,
String
token
,
int
retryTotalCount
,
int
thisRetryCount
)
{
log
.
info
(
"------当前的请求的地址为:{}-------"
,
requestUrl
);
try
{
HttpRequest
httpRequest
=
HttpRequest
.
post
(
REQUEST_URL
+
requestUrl
);
httpRequest
.
header
(
"token"
,
token
);
String
response
=
httpRequest
.
body
(
body
).
execute
().
body
();
log
.
info
(
"------{}http通道建立成功,重试了{}次------"
,
requestUrl
,
thisRetryCount
-
1
);
return
response
;
}
catch
(
Exception
e
)
{
//当前重试次数 小于等于总共的重试次数时
if
(
thisRetryCount
<=
retryTotalCount
){
log
.
error
(
"{},http通道建立时出现异常,异常信息为:{},开始第{}次重试!"
,
requestUrl
,
RPCLogUtil
.
getMessage
(
e
),
thisRetryCount
);
try
{
Thread
.
sleep
(
1000
*
thisRetryCount
);
}
catch
(
InterruptedException
interruptedException
)
{
interruptedException
.
printStackTrace
();
}
requestPostServer
(
requestUrl
,
body
,
token
,
retryTotalCount
,++
thisRetryCount
);
}
log
.
error
(
"----与主机【{}】建立通道,总共【{}】次,全部失败"
,
retryTotalCount
,
retryTotalCount
);
}
return
null
;
}
/**
* 特殊的补批接口
* 特殊的补批接口
*
*
* @return
* @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