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
3622ddfb
Commit
3622ddfb
authored
Jun 13, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除过期类
parent
dc010ac7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
178 deletions
+0
-178
StatusSnapshootThreadRunHelper.java
...om/byit/thread/helper/StatusSnapshootThreadRunHelper.java
+0
-178
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/helper/StatusSnapshootThreadRunHelper.java
deleted
100644 → 0
View file @
dc010ac7
package
com
.
byit
.
thread
.
helper
;
import
com.byit.dto.plugin.StatisticData
;
import
com.byit.mapper.FlowMapper
;
import
com.byit.mapper.FlowStatusSnapshootMapper
;
import
com.byit.mapper.JobTaskRunLogMapper
;
import
com.byit.mapper.RunRecordingMapper
;
import
com.byit.model.Flow
;
import
com.byit.model.FlowStatusSnapshoot
;
import
com.byit.model.RunRecording
;
import
com.byit.thread.BaseThreadRunHelper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
javax.sql.DataSource
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
* @Description 扫描状态并保存快照的线程类
* @Author guo_m
* @Date 2020-04-02
*/
@Deprecated
@Slf4j
public
class
StatusSnapshootThreadRunHelper
extends
BaseThreadRunHelper
{
private
static
final
String
LOCK_NAME
=
"flow_status_snapshoot_lock"
;
@Resource
private
FlowMapper
flowMapper
;
@Resource
private
FlowStatusSnapshootMapper
flowStatusSnapshootMapper
;
@Resource
private
RunRecordingMapper
runRecordingMapper
;
@Resource
private
JobTaskRunLogMapper
jobTaskRunLogMapper
;
@Resource
private
DataSource
dataSource
;
@Value
(
"${myth-job.snapshoot-date}"
)
private
Integer
snapshootDate
;
private
static
final
DateTimeFormatter
DATE_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
@Override
public
Long
start
()
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
String
date
=
localDateTime
.
format
(
DATE_FORMATTER
);
String
hour
=
String
.
valueOf
(
localDateTime
.
getHour
());
log
.
info
(
"开始记录快照 day【{}】hour【{}】---"
,
date
,
hour
);
Integer
num
=
flowStatusSnapshootMapper
.
exist
(
date
,
hour
);
//判断是否存储过快照
if
(
num
!=
null
&&
num
>=
1
){
log
.
info
(
"没有工作流无需记录---"
);
return
(
60
-
LocalDateTime
.
now
().
getMinute
())
*
60
*
1000L
;
}
else
{
//获取所有剩余执行次数不为零的工作流
List
<
Flow
>
flowList
=
flowMapper
.
findAll
();
if
(
flowList
!=
null
&&
flowList
.
size
()
>
0
){
LocalDateTime
hourDateTime
=
localDateTime
.
minusMinutes
(
localDateTime
.
getMinute
())
//减去分钟
.
minusSeconds
(
localDateTime
.
getSecond
())
//减去秒
.
minusNanos
(
localDateTime
.
getNano
());
//减去纳秒
Long
hourTime
=
hourDateTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
//转换时间戳
List
<
FlowStatusSnapshoot
>
flowStatusSnapshootList
=
new
ArrayList
<>();
flowList
.
forEach
(
flow
->
{
//获取今天凌晨的时间戳
Long
time
=
LocalDate
.
now
().
atStartOfDay
(
ZoneOffset
.
ofHours
(
8
)).
toInstant
().
toEpochMilli
();
//获取今天的运行实例
List
<
RunRecording
>
runRecordingList
=
runRecordingMapper
.
findByPreTime
(
new
Date
(
time
),
flow
.
getFlowId
());
FlowStatusSnapshoot
flowStatusSnapshoot
=
new
FlowStatusSnapshoot
();
flowStatusSnapshoot
.
setDay
(
date
);
flowStatusSnapshoot
.
setFlowId
(
flow
.
getFlowId
());
flowStatusSnapshoot
.
setHour
(
hour
);
flowStatusSnapshoot
.
setFlowName
(
flow
.
getFlowName
());
flowStatusSnapshoot
.
setWorkspaceId
(
flow
.
getWorkspaceId
());
flowStatusSnapshoot
.
setSnapshootTime
(
hourTime
);
//统计运行实例的数据
//如果存在实例
if
(
null
!=
runRecordingList
&&
runRecordingList
.
size
()
>
0
){
buildUnFinish
(
runRecordingList
,
flowStatusSnapshootList
,
flowStatusSnapshoot
,
flow
);
}
else
{
//如果不存在运行实例
flowStatusSnapshoot
.
setFlowStatus
(
1
);
flowStatusSnapshoot
.
setUnstartNode
(
flow
.
getFlowNodeCount
());
flowStatusSnapshootList
.
add
(
flowStatusSnapshoot
);
}
});
if
(
null
!=
flowStatusSnapshootList
&&
flowStatusSnapshootList
.
size
()
>
0
){
flowStatusSnapshootMapper
.
saveList
(
flowStatusSnapshootList
);
}
//获取过期的时间戳
Long
outTime
=
hourDateTime
.
minusDays
(
snapshootDate
).
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
//转换时间戳;
//删除超过期限的快照
flowStatusSnapshootMapper
.
deleteOutSnapShoot
(
outTime
);
}
}
log
.
info
(
"记录快照完成---"
);
return
(
60
-
LocalTime
.
now
().
getMinute
())
*
60
*
1000L
;
}
/**
* 功能描述 当天的和未完成的工作流的快照
* @author gml
* @date 2020-05-08 10:20
* @param runRecordingList
* @param flowStatusSnapshootList
* @param flowStatusSnapshoot
* @return void
*/
private
void
buildUnFinish
(
List
<
RunRecording
>
runRecordingList
,
List
<
FlowStatusSnapshoot
>
flowStatusSnapshootList
,
FlowStatusSnapshoot
flowStatusSnapshoot
,
Flow
flow
){
//如果存在,记录快照
runRecordingList
.
forEach
(
runRecording
->
{
FlowStatusSnapshoot
hourFlowStatusSnapshoot
=
new
FlowStatusSnapshoot
();
BeanUtils
.
copyProperties
(
flowStatusSnapshoot
,
hourFlowStatusSnapshoot
);
//判断运行状态
if
(
StringUtils
.
isEmpty
(
runRecording
.
getFlowStatus
())){
//如果为空设置为未运行
hourFlowStatusSnapshoot
.
setFlowStatus
(
1
);
}
else
if
(
runRecording
.
getFlowStatus
().
equals
(
"1"
)
||
runRecording
.
getFlowStatus
().
equals
(
"2"
)
||
runRecording
.
getFlowStatus
().
equals
(
"3"
)){
hourFlowStatusSnapshoot
.
setFlowStatus
(
Integer
.
valueOf
(
runRecording
.
getFlowStatus
()));
}
else
if
(
runRecording
.
getFlowStatus
().
equals
(
"4"
)){
switch
(
runRecording
.
getFlowRunResult
()){
case
"1"
:
case
"3"
:
hourFlowStatusSnapshoot
.
setFlowStatus
(
4
);
break
;
case
"2"
:
case
"4"
:
hourFlowStatusSnapshoot
.
setFlowStatus
(
5
);
break
;
case
"5"
:
hourFlowStatusSnapshoot
.
setFlowStatus
(
6
);
break
;
default
:
hourFlowStatusSnapshoot
.
setFlowStatus
(
5
);
break
;
}
}
else
{
//如果没在判断之内,设置为未运行
hourFlowStatusSnapshoot
.
setFlowStatus
(
1
);
}
//获取运行实例下各类状态的节点数目
StatisticData
nodeStatistic
=
jobTaskRunLogMapper
.
findStatisticDataByRunIdAndFlowId
(
runRecording
.
getRunId
(),
flow
.
getFlowId
());
//判断是否存在节点的运行日志
//存在节点运行日志
if
(
nodeStatistic
!=
null
){
int
sum
=
nodeStatistic
.
getFail
()
+
nodeStatistic
.
getSuccess
()
+
nodeStatistic
.
getRunIng
()
+
nodeStatistic
.
getKill
();
if
(
flow
.
getFlowNodeCount
()
>
sum
){
hourFlowStatusSnapshoot
.
setUnstartNode
(
flow
.
getFlowNodeCount
()
-
sum
);
}
else
{
hourFlowStatusSnapshoot
.
setUnstartNode
(
0
);
}
hourFlowStatusSnapshoot
.
setRuningNode
(
nodeStatistic
.
getRunIng
());
hourFlowStatusSnapshoot
.
setSuccessNode
(
nodeStatistic
.
getSuccess
());
hourFlowStatusSnapshoot
.
setFailNode
(
nodeStatistic
.
getFail
());
hourFlowStatusSnapshoot
.
setKillNode
(
nodeStatistic
.
getKill
());
}
else
{
//不存在节点的运行日志
hourFlowStatusSnapshoot
.
setUnstartNode
(
flow
.
getFlowNodeCount
());
}
flowStatusSnapshootList
.
add
(
hourFlowStatusSnapshoot
);
});
}
@Override
public
DataSource
getDataSource
()
{
return
dataSource
;
}
@Override
public
String
getLockName
()
{
return
LOCK_NAME
;
}
}
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