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
a1aadf5f
Commit
a1aadf5f
authored
Apr 26, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除废弃代码
parent
6dbfca7c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
0 additions
and
358 deletions
+0
-358
JobController.java
...dmin/src/main/java/com/byit/controller/JobController.java
+0
-1
MythJobScheduler.java
...in-core/src/main/java/com/byit/conf/MythJobScheduler.java
+0
-9
EmailScanHelper.java
...n-core/src/main/java/com/byit/thread/EmailScanHelper.java
+0
-158
FlowScanHelper.java
...in-core/src/main/java/com/byit/thread/FlowScanHelper.java
+0
-190
JobScheduleHelper.java
...core/src/main/java/com/byit/thread/JobScheduleHelper.java
+0
-0
LogScanHelper.java
...min-core/src/main/java/com/byit/thread/LogScanHelper.java
+0
-0
RunRecordingScanHelper.java
...src/main/java/com/byit/thread/RunRecordingScanHelper.java
+0
-0
No files found.
byit-myth-admin/src/main/java/com/byit/controller/JobController.java
View file @
a1aadf5f
...
...
@@ -8,7 +8,6 @@ import com.byit.model.JobTask;
import
com.byit.service.JobTaskService
;
import
com.byit.service.RunScriptService
;
import
com.byit.thread.LogCallbackThread
;
import
com.byit.thread.RunRecordingScanHelper
;
import
com.byit.util.SourceObj2TargetObjUtil
;
import
com.byit.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/conf/MythJobScheduler.java
View file @
a1aadf5f
...
...
@@ -21,15 +21,6 @@ import java.util.Map;
@Slf4j
public
class
MythJobScheduler
implements
InitializingBean
,
DisposableBean
{
/**
* private final JobScheduleHelper jobScheduleHelper
* private final EmailScanHelper emailScanHelper
* private final FlowScanHelper flowScanHelper
* private final LogScanHelper logScanHelper
* private final RunRecordingScanHelper runRecordingScanHelper
*/
private
final
ApplicationContext
applicationContext
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/EmailScanHelper.java
deleted
100644 → 0
View file @
6dbfca7c
package
com
.
byit
.
thread
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.byit.model.EmailAlarm
;
import
com.byit.model.vo.EmailAlarmVo
;
import
com.byit.service.EmailAlarmService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Component
;
import
javax.sql.DataSource
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
/**
* @program: com.byit.thread.EmailScanHelper
* @description: 对于邮箱的扫描
* @author: huangfu
* @date: 2020年1月7日10:44:01
**/
@Component
@Slf4j
@Deprecated
public
class
EmailScanHelper
{
private
final
DataSource
dataSource
;
private
final
EmailAlarmService
emailAlarmService
;
private
volatile
boolean
emailThreadIsStop
=
false
;
private
Thread
emailThread
;
public
EmailScanHelper
(
DataSource
dataSource
,
EmailAlarmService
emailAlarmService
)
{
this
.
dataSource
=
dataSource
;
this
.
emailAlarmService
=
emailAlarmService
;
}
public
void
start
(){
startScanNotSentEmailFlow
();
}
public
void
startScanNotSentEmailFlow
(){
emailThread
=
new
Thread
(()
->{
dateAligned
(
5000
);
log
.
info
(
"--------------【com.byit.thread.EmailScanHelper.startScanNotSentEmailFlow】init success---------------"
);
while
(!
emailThreadIsStop
){
//是否需要睡眠
boolean
isSleep
=
false
;
Connection
conn
=
null
;
Boolean
connAutoCommit
=
null
;
PreparedStatement
preparedStatement
=
null
;
try
{
/**
* 添加行锁
*/
conn
=
dataSource
.
getConnection
();
connAutoCommit
=
conn
.
getAutoCommit
();
conn
.
setAutoCommit
(
false
);
preparedStatement
=
conn
.
prepareStatement
(
"SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'emali_alarm_lock' FOR UPDATE "
);
preparedStatement
.
execute
();
//查询未告警的邮箱
List
<
EmailAlarm
>
emailAlarmByAlarmResults
=
emailAlarmService
.
findEmailAlarmByAlarmResult
();
if
(
CollectionUtil
.
isNotEmpty
(
emailAlarmByAlarmResults
)){
emailAlarmByAlarmResults
.
forEach
(
emailAlarm
->{
EmailAlarmVo
emailAlarmVo
=
new
EmailAlarmVo
();
BeanUtils
.
copyProperties
(
emailAlarm
,
emailAlarmVo
);
emailAlarmService
.
sendEmail
(
emailAlarmVo
);
});
}
else
{
isSleep
=
true
;
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
finally
{
//释放资源
if
(
conn
!=
null
){
try
{
conn
.
commit
();
}
catch
(
SQLException
e
)
{
if
(!
emailThreadIsStop
){
log
.
error
(
"--------------------【提交行锁出错】---------------------"
);
}
}
}
try
{
if
(
conn
!=
null
){
conn
.
setAutoCommit
(
connAutoCommit
);
}
}
catch
(
SQLException
e
)
{
if
(!
emailThreadIsStop
){
log
.
error
(
"--------------------【恢复自动提交出错】---------------------"
);
}
}
if
(
preparedStatement
!=
null
){
try
{
preparedStatement
.
close
();
}
catch
(
SQLException
e
)
{
if
(!
emailThreadIsStop
){
log
.
error
(
"--------------------【关闭执行器出错】---------------------"
);
}
}
}
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
if
(!
emailThreadIsStop
){
log
.
error
(
"--------------------【关闭链接出错】---------------------"
);
}
}
}
if
(
isSleep
){
dateAligned
(
20000
);
}
}
});
emailThread
.
setDaemon
(
true
);
emailThread
.
setName
(
"myth-job#【EmailScanHelper】#startScanNotSentEmailFlow"
);
emailThread
.
start
();
}
public
void
doStop
(){
this
.
emailThreadIsStop
=
true
;
try
{
TimeUnit
.
SECONDS
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
}
if
(
emailThread
.
getState
()
!=
Thread
.
State
.
TERMINATED
)
{
emailThread
.
interrupt
();
try
{
emailThread
.
join
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
}
}
log
.
warn
(
"---------------【日志扫描线程被注销】-----------------------"
);
}
/**
* 对齐时钟。整秒运行
*/
private
void
dateAligned
(
long
waitTime
){
try
{
TimeUnit
.
MILLISECONDS
.
sleep
(
waitTime
-
System
.
currentTimeMillis
()%
1000
);
}
catch
(
InterruptedException
e
)
{
log
.
warn
(
"----------------【线程被中断】-----------------------"
);
}
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/FlowScanHelper.java
deleted
100644 → 0
View file @
6dbfca7c
package
com
.
byit
.
thread
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.byit.job.utils.CronExpression
;
import
com.byit.model.Flow
;
import
com.byit.model.Node
;
import
com.byit.service.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
javax.sql.DataSource
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
/**
* 扫描任务流表的线程
* 目的:扫描即将要执行的任务流表 半个小时
* @author huangfu
*/
@Component
@Slf4j
@Deprecated
public
class
FlowScanHelper
{
private
final
Long
PRE_TEST_TIME
=
System
.
currentTimeMillis
()+
TimeUnit
.
HOURS
.
toMillis
(
30
);
private
final
FlowService
flowService
;
private
final
DataSource
dataSource
;
private
final
NodeService
nodeService
;
private
final
RunNodeServer
runNodeServer
;
private
Thread
flowThread
;
private
volatile
boolean
flowThreadIsStop
=
false
;
public
FlowScanHelper
(
FlowService
flowService
,
DataSource
dataSource
,
NodeService
nodeService
,
RunNodeServer
runNodeServer
)
{
this
.
flowService
=
flowService
;
this
.
dataSource
=
dataSource
;
this
.
nodeService
=
nodeService
;
this
.
runNodeServer
=
runNodeServer
;
}
public
void
start
(){
flowThreadStart
();
}
/**
* 运行扫描工作流的线程
*/
private
void
flowThreadStart
(){
flowThread
=
new
Thread
(()
->{
dateAligned
(
5000
);
log
.
info
(
"--------------【com.byit.thread.FlowScanHelper#flowThreadStart】init success---------------"
);
while
(!
flowThreadIsStop
){
Connection
conn
=
null
;
Boolean
connAutoCommit
=
null
;
PreparedStatement
preparedStatement
=
null
;
//是否需要睡眠
boolean
isSleep
=
false
;
try
{
/**
* 添加行锁
*/
conn
=
dataSource
.
getConnection
();
connAutoCommit
=
conn
.
getAutoCommit
();
conn
.
setAutoCommit
(
false
);
preparedStatement
=
conn
.
prepareStatement
(
"SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'flow_lock' FOR UPDATE "
);
preparedStatement
.
execute
();
//这个查询时有一个条件是 剩余次数不等于0也就是说 等于0的就查询不出来
List
<
Flow
>
halfAnHourFlow
=
flowService
.
findHalfAnHourFlow
(
PRE_TEST_TIME
);
if
(
CollectionUtil
.
isNotEmpty
(
halfAnHourFlow
))
{
for
(
Flow
flow
:
halfAnHourFlow
){
log
.
debug
(
"-----------------【工作流{}的执行次数大于0,放行】-------------------------"
,
flow
.
getFlowName
());
//String versionName = flow.getVersionName()
Integer
flowId
=
flow
.
getFlowId
();
//根据工作流查询工作流下所有的节点
List
<
Node
>
nodeByFlowIdAndVersionName
=
nodeService
.
findNodeByFlowIdAndVersionName
(
flowId
);
if
(
CollectionUtil
.
isNotEmpty
(
nodeByFlowIdAndVersionName
)){
//保存到运行记录表和任务表
runNodeServer
.
saveRunRec
(
flow
,
nodeByFlowIdAndVersionName
);
if
(
flow
.
getRemainingCount
()>
0
)
{
flow
.
setRemainingCount
(
flow
.
getRemainingCount
()-
1
);
}
//获取cron表达式
String
flowCron
=
flow
.
getFlowCron
();
//设置下一周期的时间
Date
nextValidTime
=
new
CronExpression
(
flowCron
).
getNextValidTimeAfter
(
new
Date
(
flow
.
getTriggerNextTime
()));
flow
.
setTriggerNextTime
(
nextValidTime
.
getTime
());
flowService
.
updateByIdSelective
(
flow
);
}
}
}
else
{
isSleep
=
true
;
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
finally
{
//释放资源
if
(
conn
!=
null
){
try
{
conn
.
commit
();
}
catch
(
SQLException
e
)
{
if
(!
flowThreadIsStop
){
log
.
error
(
"--------------------【提交行锁出错】---------------------"
);
}
}
}
try
{
if
(
conn
!=
null
){
conn
.
setAutoCommit
(
connAutoCommit
);
}
}
catch
(
SQLException
e
)
{
if
(!
flowThreadIsStop
){
log
.
error
(
"--------------------【恢复自动提交出错】---------------------"
);
}
}
if
(
preparedStatement
!=
null
){
try
{
preparedStatement
.
close
();
}
catch
(
SQLException
e
)
{
if
(!
flowThreadIsStop
){
log
.
error
(
"--------------------【关闭执行器出错】---------------------"
);
}
}
}
try
{
conn
.
close
();
}
catch
(
SQLException
e
)
{
if
(!
flowThreadIsStop
){
log
.
error
(
"--------------------【关闭链接出错】---------------------"
);
}
}
}
if
(
isSleep
){
try
{
log
.
info
(
"------------------【未扫描到要执行的工作流】-------------------"
);
TimeUnit
.
MINUTES
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
log
.
warn
(
"----------------------【扫描工作流的线程被关闭了】----------------------------"
);
}
}
}
});
flowThread
.
setDaemon
(
true
);
flowThread
.
setName
(
"myth-job#【FlowScanHelper】#flowThreadStart"
);
flowThread
.
start
();
}
public
void
doStop
(){
this
.
flowThreadIsStop
=
true
;
try
{
TimeUnit
.
SECONDS
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
}
if
(
flowThread
.
getState
()
!=
Thread
.
State
.
TERMINATED
)
{
flowThread
.
interrupt
();
try
{
flowThread
.
join
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
}
}
log
.
warn
(
"---------------【工作扫描线程被注销】-----------------------"
);
}
/**
* 对齐时钟。整秒运行
*/
private
void
dateAligned
(
long
waitTime
){
try
{
TimeUnit
.
MILLISECONDS
.
sleep
(
waitTime
-
System
.
currentTimeMillis
()%
1000
);
}
catch
(
InterruptedException
e
)
{
log
.
warn
(
"----------------【线程被中断】-----------------------"
);
}
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/JobScheduleHelper.java
deleted
100644 → 0
View file @
6dbfca7c
This diff is collapsed.
Click to expand it.
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/LogScanHelper.java
deleted
100644 → 0
View file @
6dbfca7c
This diff is collapsed.
Click to expand it.
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/RunRecordingScanHelper.java
deleted
100644 → 0
View file @
6dbfca7c
This diff is collapsed.
Click to expand it.
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