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
e5e7415e
Commit
e5e7415e
authored
Jan 07, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【集成自动发送邮件】自动扫描已经完成的日志,发送邮件
parent
0c38bcbb
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
235 additions
and
114 deletions
+235
-114
MythJobScheduler.java
...in-core/src/main/java/com/byit/conf/MythJobScheduler.java
+6
-2
EmailAlarmMapper.java
...-core/src/main/java/com/byit/mapper/EmailAlarmMapper.java
+5
-0
EmailAlarm.java
...h-admin-core/src/main/java/com/byit/model/EmailAlarm.java
+0
-6
EmailAlarmVo.java
...in-core/src/main/java/com/byit/model/vo/EmailAlarmVo.java
+0
-6
EmailAlarmService.java
...ore/src/main/java/com/byit/service/EmailAlarmService.java
+6
-0
EmailAlarmServiceImpl.java
...ain/java/com/byit/service/impl/EmailAlarmServiceImpl.java
+8
-4
EmailScanHelper.java
...n-core/src/main/java/com/byit/thread/EmailScanHelper.java
+151
-0
RunRecordingScanHelper.java
...src/main/java/com/byit/thread/RunRecordingScanHelper.java
+38
-44
EmailAlarmMapper.xml
...admin-core/src/main/resources/mapper/EmailAlarmMapper.xml
+18
-15
JobUtils.java
...exector-plugin/src/main/java/com/byit/utils/JobUtils.java
+3
-1
ExploringSynchronized.java
...nt/src/main/java/com/byit/test/ExploringSynchronized.java
+0
-36
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/conf/MythJobScheduler.java
View file @
e5e7415e
package
com
.
byit
.
conf
;
package
com
.
byit
.
conf
;
import
com.byit.thread.EmailScanHelper
;
import
com.byit.thread.JobScheduleHelper
;
import
com.byit.thread.JobScheduleHelper
;
import
com.byit.thread.LogScanHelper
;
import
com.byit.thread.LogScanHelper
;
import
com.byit.thread.RunRecordingScanHelper
;
import
com.byit.thread.RunRecordingScanHelper
;
...
@@ -21,12 +22,14 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
...
@@ -21,12 +22,14 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
private
final
JobScheduleHelper
jobScheduleHelper
;
private
final
JobScheduleHelper
jobScheduleHelper
;
private
final
LogScanHelper
logScanHelper
;
private
final
LogScanHelper
logScanHelper
;
private
final
RunRecordingScanHelper
runRecordingScanHelper
;
private
final
RunRecordingScanHelper
runRecordingScanHelper
;
private
final
EmailScanHelper
emailScanHelper
;
@Autowired
@Autowired
public
MythJobScheduler
(
JobScheduleHelper
jobScheduleHelper
,
LogScanHelper
logScanHelper
,
RunRecordingScanHelper
runRecordingScanHelper
)
{
public
MythJobScheduler
(
JobScheduleHelper
jobScheduleHelper
,
LogScanHelper
logScanHelper
,
RunRecordingScanHelper
runRecordingScanHelper
,
EmailScanHelper
emailScanHelper
)
{
this
.
jobScheduleHelper
=
jobScheduleHelper
;
this
.
jobScheduleHelper
=
jobScheduleHelper
;
this
.
logScanHelper
=
logScanHelper
;
this
.
logScanHelper
=
logScanHelper
;
this
.
runRecordingScanHelper
=
runRecordingScanHelper
;
this
.
runRecordingScanHelper
=
runRecordingScanHelper
;
this
.
emailScanHelper
=
emailScanHelper
;
}
}
/**
/**
...
@@ -38,6 +41,7 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
...
@@ -38,6 +41,7 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
this
.
jobScheduleHelper
.
doStop
();
this
.
jobScheduleHelper
.
doStop
();
this
.
logScanHelper
.
doStop
();
this
.
logScanHelper
.
doStop
();
this
.
runRecordingScanHelper
.
doStop
();
this
.
runRecordingScanHelper
.
doStop
();
this
.
emailScanHelper
.
doStop
();
}
}
/**
/**
...
@@ -50,6 +54,6 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
...
@@ -50,6 +54,6 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
this
.
jobScheduleHelper
.
start
();
this
.
jobScheduleHelper
.
start
();
this
.
logScanHelper
.
start
();
this
.
logScanHelper
.
start
();
this
.
runRecordingScanHelper
.
start
();
this
.
runRecordingScanHelper
.
start
();
this
.
emailScanHelper
.
start
();
}
}
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/mapper/EmailAlarmMapper.java
View file @
e5e7415e
...
@@ -13,6 +13,11 @@ import java.util.List;
...
@@ -13,6 +13,11 @@ import java.util.List;
@Repository
@Repository
public
interface
EmailAlarmMapper
{
public
interface
EmailAlarmMapper
{
/**
/**
* 查询没有告警的邮箱
* @return
*/
List
<
EmailAlarm
>
findEmailAlarmByAlarmResult
();
/**
* 根据id查询邮件
* 根据id查询邮件
* @param id
* @param id
* @return
* @return
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/model/EmailAlarm.java
View file @
e5e7415e
...
@@ -56,12 +56,6 @@ public class EmailAlarm implements Serializable {
...
@@ -56,12 +56,6 @@ public class EmailAlarm implements Serializable {
private
String
alarmEmail
;
private
String
alarmEmail
;
/**
/**
* 当前工作流版本的告警的时机(0 不告警, 1 完成时告警, 2 失败时告警, 3 成功时告警)
*/
@ApiModelProperty
(
"当前工作流版本的告警的时机(0 不告警, 1 完成时告警, 2 失败时告警, 3 成功时告警)"
)
private
String
alarmAction
;
/**
* 告警结果(0, 未告警 1,告警成功 2,告警失败)
* 告警结果(0, 未告警 1,告警成功 2,告警失败)
*/
*/
@ApiModelProperty
(
"告警结果(0, 未告警 1,告警成功 2,告警失败)"
)
@ApiModelProperty
(
"告警结果(0, 未告警 1,告警成功 2,告警失败)"
)
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/model/vo/EmailAlarmVo.java
View file @
e5e7415e
...
@@ -71,12 +71,6 @@ public class EmailAlarmVo implements Serializable {
...
@@ -71,12 +71,6 @@ public class EmailAlarmVo implements Serializable {
private
String
alarmEmail
;
private
String
alarmEmail
;
/**
/**
* 当前工作流版本的告警的时机(0 不告警, 1 完成时告警, 2 失败时告警, 3 成功时告警)
*/
@ApiModelProperty
(
"当前工作流版本的告警的时机(0 不告警, 1 完成时告警, 2 失败时告警, 3 成功时告警)"
)
private
String
alarmAction
;
/**
* 告警结果(0, 未告警 1,告警成功 2,告警失败)
* 告警结果(0, 未告警 1,告警成功 2,告警失败)
*/
*/
@ApiModelProperty
(
"告警结果(0, 未告警 1,告警成功 2,告警失败)"
)
@ApiModelProperty
(
"告警结果(0, 未告警 1,告警成功 2,告警失败)"
)
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/EmailAlarmService.java
View file @
e5e7415e
...
@@ -14,6 +14,12 @@ import java.util.List;
...
@@ -14,6 +14,12 @@ import java.util.List;
**/
**/
public
interface
EmailAlarmService
{
public
interface
EmailAlarmService
{
/**
/**
* 查询没有告警的邮箱
* @return
*/
List
<
EmailAlarm
>
findEmailAlarmByAlarmResult
();
/**
* 根据id查询邮件
* 根据id查询邮件
* @param id
* @param id
* @return
* @return
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/impl/EmailAlarmServiceImpl.java
View file @
e5e7415e
...
@@ -39,6 +39,11 @@ public class EmailAlarmServiceImpl implements EmailAlarmService {
...
@@ -39,6 +39,11 @@ public class EmailAlarmServiceImpl implements EmailAlarmService {
}
}
@Override
@Override
public
List
<
EmailAlarm
>
findEmailAlarmByAlarmResult
()
{
return
emailAlarmMapper
.
findEmailAlarmByAlarmResult
();
}
@Override
public
EmailAlarm
findEmailAlarmById
(
Integer
id
)
{
public
EmailAlarm
findEmailAlarmById
(
Integer
id
)
{
return
emailAlarmMapper
.
findEmailAlarmById
(
id
);
return
emailAlarmMapper
.
findEmailAlarmById
(
id
);
}
}
...
@@ -64,9 +69,6 @@ public class EmailAlarmServiceImpl implements EmailAlarmService {
...
@@ -64,9 +69,6 @@ public class EmailAlarmServiceImpl implements EmailAlarmService {
@Override
@Override
@DataValidation
@DataValidation
public
void
sendEmail
(
@ParamValidation
EmailAlarmVo
record
)
{
public
void
sendEmail
(
@ParamValidation
EmailAlarmVo
record
)
{
record
.
setSendTime
(
new
Date
());
record
.
setAlarmTitle
(
"测试邮件"
);
record
.
setAlarmContent
(
"<div style='color:#F00;font-size:1000px'>测试邮件</div>"
);
try
{
try
{
//发送一个支持复杂类型的邮件
//发送一个支持复杂类型的邮件
MimeMessageHelper
messageHelper
=
new
MimeMessageHelper
(
javaMailSender
.
createMimeMessage
(),
true
);
MimeMessageHelper
messageHelper
=
new
MimeMessageHelper
(
javaMailSender
.
createMimeMessage
(),
true
);
...
@@ -97,9 +99,11 @@ public class EmailAlarmServiceImpl implements EmailAlarmService {
...
@@ -97,9 +99,11 @@ public class EmailAlarmServiceImpl implements EmailAlarmService {
throw
new
BusinessException
(
AdminEnums
.
SEND_EMAIL_FAILURE
);
throw
new
BusinessException
(
AdminEnums
.
SEND_EMAIL_FAILURE
);
}
}
EmailAlarm
emailAlarm
=
new
EmailAlarm
(
);
EmailAlarm
emailAlarm
=
new
EmailAlarm
(
);
BeanUtils
.
copyProperties
(
record
,
emailAlarm
);
BeanUtils
.
copyProperties
(
record
,
emailAlarm
);
emailAlarm
.
setSendTime
(
new
Date
());
//保存邮件
//保存邮件
sav
eEmailAlarm
(
emailAlarm
);
updat
eEmailAlarm
(
emailAlarm
);
}
}
@Override
@Override
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/EmailScanHelper.java
0 → 100644
View file @
e5e7415e
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
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
){
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
{
dateAligned
(
20000
);
}
}
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
(
"--------------------【关闭链接出错】---------------------"
);
}
}
}
}
});
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/RunRecordingScanHelper.java
View file @
e5e7415e
...
@@ -9,9 +9,6 @@ import com.byit.model.RunRecording;
...
@@ -9,9 +9,6 @@ import com.byit.model.RunRecording;
import
com.byit.service.EmailAlarmService
;
import
com.byit.service.EmailAlarmService
;
import
com.byit.service.JobTaskRunLogService
;
import
com.byit.service.JobTaskRunLogService
;
import
com.byit.service.RunRecordingService
;
import
com.byit.service.RunRecordingService
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -22,13 +19,11 @@ import java.sql.PreparedStatement;
...
@@ -22,13 +19,11 @@ import java.sql.PreparedStatement;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
/**
* 运行记录扫描线程
* 运行记录扫描线程
*
* @author huangfu
* @author huangfu
*/
*/
@Component
@Component
...
@@ -65,12 +60,12 @@ public class RunRecordingScanHelper {
...
@@ -65,12 +60,12 @@ public class RunRecordingScanHelper {
this
.
runRecordingService
=
runRecordingService
;
this
.
runRecordingService
=
runRecordingService
;
}
}
public
void
start
(){
public
void
start
()
{
System
.
out
.
println
(
"------------------------"
);
System
.
out
.
println
(
"------------------------"
);
runRecordingThread
=
new
Thread
(()
->{
runRecordingThread
=
new
Thread
(()
->
{
dateAligned
(
5000
);
dateAligned
(
5000
);
log
.
info
(
"--------------------【com.byit.thread.RunRecordingScanThread#start】init success----------------------"
);
log
.
info
(
"--------------------【com.byit.thread.RunRecordingScanThread#start】init success----------------------"
);
while
(!
runRecordingThreadStop
){
while
(!
runRecordingThreadStop
)
{
dateAligned
(
5000
);
dateAligned
(
5000
);
Connection
conn
=
null
;
Connection
conn
=
null
;
Boolean
connAutoCommit
=
null
;
Boolean
connAutoCommit
=
null
;
...
@@ -83,34 +78,34 @@ public class RunRecordingScanHelper {
...
@@ -83,34 +78,34 @@ public class RunRecordingScanHelper {
preparedStatement
.
execute
();
preparedStatement
.
execute
();
//进行操作
//进行操作
scanRunRec
();
scanRunRec
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
if
(
conn
!=
null
)
{
if
(
conn
!=
null
)
{
try
{
try
{
conn
.
commit
();
conn
.
commit
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
runRecordingThreadStop
)
{
if
(!
runRecordingThreadStop
)
{
log
.
error
(
"--------------------【提交行锁出错】---------------------"
);
log
.
error
(
"--------------------【提交行锁出错】---------------------"
);
}
}
}
}
}
}
try
{
try
{
if
(
conn
!=
null
)
{
if
(
conn
!=
null
)
{
conn
.
setAutoCommit
(
connAutoCommit
);
conn
.
setAutoCommit
(
connAutoCommit
);
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
runRecordingThreadStop
)
{
if
(!
runRecordingThreadStop
)
{
log
.
error
(
"--------------------【恢复自动提交出错】---------------------"
);
log
.
error
(
"--------------------【恢复自动提交出错】---------------------"
);
}
}
}
}
if
(
preparedStatement
!=
null
)
{
if
(
preparedStatement
!=
null
)
{
try
{
try
{
preparedStatement
.
close
();
preparedStatement
.
close
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
runRecordingThreadStop
)
{
if
(!
runRecordingThreadStop
)
{
log
.
error
(
"--------------------【关闭执行器出错】---------------------"
);
log
.
error
(
"--------------------【关闭执行器出错】---------------------"
);
}
}
}
}
...
@@ -119,7 +114,7 @@ public class RunRecordingScanHelper {
...
@@ -119,7 +114,7 @@ public class RunRecordingScanHelper {
try
{
try
{
conn
.
close
();
conn
.
close
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
runRecordingThreadStop
)
{
if
(!
runRecordingThreadStop
)
{
log
.
error
(
"--------------------【关闭链接出错】---------------------"
);
log
.
error
(
"--------------------【关闭链接出错】---------------------"
);
}
}
}
}
...
@@ -131,31 +126,31 @@ public class RunRecordingScanHelper {
...
@@ -131,31 +126,31 @@ public class RunRecordingScanHelper {
runRecordingThread
.
start
();
runRecordingThread
.
start
();
}
}
private
void
scanRunRec
(){
private
void
scanRunRec
()
{
//查询完结且未告警的工作流信息
//查询完结且未告警的工作流信息
List
<
RunRecording
>
runRecordingByEndAndNotIsAlarm
=
runRecordingService
.
findRunRecordingByEndAndNotIsAlarm
();
List
<
RunRecording
>
runRecordingByEndAndNotIsAlarm
=
runRecordingService
.
findRunRecordingByEndAndNotIsAlarm
();
List
<
EmailAlarm
>
emailAlarms
=
new
ArrayList
<>(
15
);
List
<
EmailAlarm
>
emailAlarms
=
new
ArrayList
<>(
15
);
if
(
CollectionUtil
.
isNotEmpty
(
runRecordingByEndAndNotIsAlarm
))
{
if
(
CollectionUtil
.
isNotEmpty
(
runRecordingByEndAndNotIsAlarm
))
{
runRecordingByEndAndNotIsAlarm
.
forEach
(
runRecording
->
{
runRecordingByEndAndNotIsAlarm
.
forEach
(
runRecording
->
{
//如果设置为完成时告警
//如果设置为完成时告警
switch
(
runRecording
.
getAlarmlAction
()){
switch
(
runRecording
.
getAlarmlAction
())
{
//设置为完成时告警
//设置为完成时告警
case
WHEN_DONE:
case
WHEN_DONE:
if
(
RunRecordingEnum
.
FLOW_STATUS_IS_END
.
getCode
().
equals
(
runRecording
.
getFlowStatus
()))
{
if
(
RunRecordingEnum
.
FLOW_STATUS_IS_END
.
getCode
().
equals
(
runRecording
.
getFlowStatus
()))
{
saveEmailAlarms
(
runRecording
);
saveEmailAlarms
(
runRecording
);
}
}
break
;
break
;
//失败时告警
//失败时告警
case
FAILURE_DONE:
case
FAILURE_DONE:
if
(
RunRecordingEnum
.
RUN_FLOW_FAILURE
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
())
if
(
RunRecordingEnum
.
RUN_FLOW_FAILURE
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
())
||
RunRecordingEnum
.
RUN_FLOW_RE_FAILURE
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
())){
||
RunRecordingEnum
.
RUN_FLOW_RE_FAILURE
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
()))
{
saveEmailAlarms
(
runRecording
);
saveEmailAlarms
(
runRecording
);
}
}
break
;
break
;
//成功时告警
//成功时告警
case
SUCCESS_DONE:
case
SUCCESS_DONE:
if
(
RunRecordingEnum
.
RUN_FLOW_SUCCESS
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
())
if
(
RunRecordingEnum
.
RUN_FLOW_SUCCESS
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
())
||
RunRecordingEnum
.
RUN_FLOW_RE_SUCCESS
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
())){
||
RunRecordingEnum
.
RUN_FLOW_RE_SUCCESS
.
getCode
().
equals
(
runRecording
.
getFlowRunResult
()))
{
saveEmailAlarms
(
runRecording
);
saveEmailAlarms
(
runRecording
);
}
}
break
;
break
;
...
@@ -166,13 +161,13 @@ public class RunRecordingScanHelper {
...
@@ -166,13 +161,13 @@ public class RunRecordingScanHelper {
}
}
}
}
public
void
doStop
(){
public
void
doStop
()
{
this
.
runRecordingThreadStop
=
true
;
this
.
runRecordingThreadStop
=
true
;
try
{
try
{
TimeUnit
.
SECONDS
.
sleep
(
1
);
TimeUnit
.
SECONDS
.
sleep
(
1
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
e
.
printStackTrace
();
}
}
if
(
runRecordingThread
.
getState
()
!=
Thread
.
State
.
TERMINATED
)
{
if
(
runRecordingThread
.
getState
()
!=
Thread
.
State
.
TERMINATED
)
{
runRecordingThread
.
interrupt
();
runRecordingThread
.
interrupt
();
...
@@ -180,7 +175,7 @@ public class RunRecordingScanHelper {
...
@@ -180,7 +175,7 @@ public class RunRecordingScanHelper {
try
{
try
{
runRecordingThread
.
join
();
runRecordingThread
.
join
();
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
(
);
e
.
printStackTrace
();
}
}
}
}
log
.
warn
(
"---------------【运行记录扫描日志线程被注销】-----------------------"
);
log
.
warn
(
"---------------【运行记录扫描日志线程被注销】-----------------------"
);
...
@@ -189,15 +184,15 @@ public class RunRecordingScanHelper {
...
@@ -189,15 +184,15 @@ public class RunRecordingScanHelper {
/**
/**
* 对齐时钟。整秒运行
* 对齐时钟。整秒运行
*/
*/
private
void
dateAligned
(
long
waitTime
){
private
void
dateAligned
(
long
waitTime
)
{
try
{
try
{
TimeUnit
.
MILLISECONDS
.
sleep
(
waitTime
-
System
.
currentTimeMillis
()
%
1000
);
TimeUnit
.
MILLISECONDS
.
sleep
(
waitTime
-
System
.
currentTimeMillis
()
%
1000
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
log
.
warn
(
"----------------【线程被中断】-----------------------"
);
log
.
warn
(
"----------------【线程被中断】-----------------------"
);
}
}
}
}
private
void
saveEmailAlarms
(
RunRecording
runRecording
){
private
void
saveEmailAlarms
(
RunRecording
runRecording
)
{
List
<
JobTaskRunLogWithBLOBs
>
jobTaskRunLogByFlowIdAndRunId
=
jobTaskRunLogService
.
findJobTaskRunLogWithBLOBsByFlowIdAndRunId
(
runRecording
.
getFlowId
(),
runRecording
.
getRunId
());
List
<
JobTaskRunLogWithBLOBs
>
jobTaskRunLogByFlowIdAndRunId
=
jobTaskRunLogService
.
findJobTaskRunLogWithBLOBsByFlowIdAndRunId
(
runRecording
.
getFlowId
(),
runRecording
.
getRunId
());
String
flowName
=
runRecording
.
getFlowName
();
String
flowName
=
runRecording
.
getFlowName
();
String
senContentHtml
=
runMsgHtml
(
jobTaskRunLogByFlowIdAndRunId
,
flowName
);
String
senContentHtml
=
runMsgHtml
(
jobTaskRunLogByFlowIdAndRunId
,
flowName
);
...
@@ -207,7 +202,6 @@ public class RunRecordingScanHelper {
...
@@ -207,7 +202,6 @@ public class RunRecordingScanHelper {
.
runId
(
runRecording
.
getRunId
())
.
runId
(
runRecording
.
getRunId
())
.
versionName
(
runRecording
.
getFlowVersionName
())
.
versionName
(
runRecording
.
getFlowVersionName
())
.
alarmEmail
(
runRecording
.
getAlarmEmail
())
.
alarmEmail
(
runRecording
.
getAlarmEmail
())
.
alarmAction
(
runRecording
.
getAlarmlAction
())
.
alarmContent
(
senContentHtml
)
.
alarmContent
(
senContentHtml
)
.
alarmResult
(
"0"
)
.
alarmResult
(
"0"
)
.
flowRes
(
runRecording
.
getFlowRunResult
())
.
flowRes
(
runRecording
.
getFlowRunResult
())
...
@@ -220,10 +214,10 @@ public class RunRecordingScanHelper {
...
@@ -220,10 +214,10 @@ public class RunRecordingScanHelper {
runRecordingService
.
updateRunRecordingById
(
runRecording
);
runRecordingService
.
updateRunRecordingById
(
runRecording
);
}
}
private
String
runMsgHtml
(
List
<
JobTaskRunLogWithBLOBs
>
jobTaskRunLogs
,
String
title
)
{
private
String
runMsgHtml
(
List
<
JobTaskRunLogWithBLOBs
>
jobTaskRunLogs
,
String
title
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"<table border='1' width='80%' align='center' cellspacing='0' cellpadding='6'>"
)
stringBuilder
.
append
(
"<table border='1' width='80%' align='center' cellspacing='0' cellpadding='6'>"
)
.
append
(
String
.
format
(
"<h2 style='text-align:center;color:red'>%s</h2>"
,
title
))
.
append
(
String
.
format
(
"<h2 style='text-align:center;color:red'>%s</h2>"
,
title
))
.
append
(
"<thead align='center' style='background: blue;color: #fff'>"
)
.
append
(
"<thead align='center' style='background: blue;color: #fff'>"
)
.
append
(
"<th width = '10%'>节点名称</th>"
)
.
append
(
"<th width = '10%'>节点名称</th>"
)
.
append
(
"<th width = '10%'>开始时间</th>"
)
.
append
(
"<th width = '10%'>开始时间</th>"
)
...
@@ -234,20 +228,20 @@ public class RunRecordingScanHelper {
...
@@ -234,20 +228,20 @@ public class RunRecordingScanHelper {
.
append
(
"</thead>"
)
.
append
(
"</thead>"
)
.
append
(
"<tbody>"
);
.
append
(
"<tbody>"
);
if
(
CollectionUtil
.
isNotEmpty
(
jobTaskRunLogs
))
{
if
(
CollectionUtil
.
isNotEmpty
(
jobTaskRunLogs
))
{
jobTaskRunLogs
.
forEach
(
jobTaskRunLog
->
{
jobTaskRunLogs
.
forEach
(
jobTaskRunLog
->
{
long
timeConsuming
=
TimeUnit
.
MILLISECONDS
.
toSeconds
(
jobTaskRunLog
.
getEndTime
().
getTime
()
-
jobTaskRunLog
.
getStartTime
().
getTime
());
long
timeConsuming
=
TimeUnit
.
MILLISECONDS
.
toSeconds
(
jobTaskRunLog
.
getEndTime
().
getTime
()
-
jobTaskRunLog
.
getStartTime
().
getTime
());
stringBuilder
.
append
(
"<tr align='center'>"
)
stringBuilder
.
append
(
"<tr align='center'>"
)
.
append
(
String
.
format
(
"<td>%s</td>"
,
jobTaskRunLog
.
getNodeName
()))
.
append
(
String
.
format
(
"<td>%s</td>"
,
jobTaskRunLog
.
getNodeName
()))
.
append
(
String
.
format
(
"<td>%s</td>"
,
DateUtil
.
format
(
jobTaskRunLog
.
getStartTime
(),
DATE_FORMAT
)))
.
append
(
String
.
format
(
"<td>%s</td>"
,
DateUtil
.
format
(
jobTaskRunLog
.
getStartTime
(),
DATE_FORMAT
)))
.
append
(
String
.
format
(
"<td>%s</td>"
,
DateUtil
.
format
(
jobTaskRunLog
.
getEndTime
(),
DATE_FORMAT
)))
.
append
(
String
.
format
(
"<td>%s</td>"
,
DateUtil
.
format
(
jobTaskRunLog
.
getEndTime
(),
DATE_FORMAT
)))
.
append
(
String
.
format
(
"<td>%s</td>"
,
timeConsuming
+
"分钟"
))
.
append
(
String
.
format
(
"<td>%s</td>"
,
timeConsuming
+
"分钟"
))
.
append
(
String
.
format
(
"<td>%s</td>"
,
"1"
.
equals
(
jobTaskRunLog
.
getRunCode
())
?
"成功"
.
append
(
String
.
format
(
"<td>%s</td>"
,
"1"
.
equals
(
jobTaskRunLog
.
getRunCode
())
?
"成功"
:
"3"
.
equals
(
jobTaskRunLog
.
getRunCode
())?
"补批成功"
:
"3"
.
equals
(
jobTaskRunLog
.
getRunCode
())
?
"补批成功"
:
"4"
.
equals
(
jobTaskRunLog
.
getRunCode
())?
"补批失败"
:
"失败"
))
:
"4"
.
equals
(
jobTaskRunLog
.
getRunCode
())
?
"补批失败"
:
"失败"
))
.
append
(
"<td>"
)
.
append
(
"<td>"
)
.
append
(
"<div style='display:inline-block;width:100%;word-break:break-all;height: auto;overflow: auto;text-align: left;'>"
)
.
append
(
"<div style='display:inline-block;width:100%;word-break:break-all;height: auto;overflow: auto;text-align: left;'>"
)
.
append
(
String
.
format
(
"%s"
,
jobTaskRunLog
.
getRunMsg
()))
.
append
(
String
.
format
(
"%s"
,
jobTaskRunLog
.
getRunMsg
()))
.
append
(
"</div>"
)
.
append
(
"</div>"
)
.
append
(
"</td></tr>"
);
.
append
(
"</td></tr>"
);
...
...
byit-myth-core/myth-admin-core/src/main/resources/mapper/EmailAlarmMapper.xml
View file @
e5e7415e
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
<result
column=
"run_id"
jdbcType=
"VARCHAR"
property=
"runId"
/>
<result
column=
"run_id"
jdbcType=
"VARCHAR"
property=
"runId"
/>
<result
column=
"version_name"
jdbcType=
"VARCHAR"
property=
"versionName"
/>
<result
column=
"version_name"
jdbcType=
"VARCHAR"
property=
"versionName"
/>
<result
column=
"alarm_email"
jdbcType=
"VARCHAR"
property=
"alarmEmail"
/>
<result
column=
"alarm_email"
jdbcType=
"VARCHAR"
property=
"alarmEmail"
/>
<result
column=
"alarm_action"
jdbcType=
"CHAR"
property=
"alarmAction"
/>
<result
column=
"alarm_result"
jdbcType=
"CHAR"
property=
"alarmResult"
/>
<result
column=
"alarm_result"
jdbcType=
"CHAR"
property=
"alarmResult"
/>
<result
column=
"send_time"
jdbcType=
"TIMESTAMP"
property=
"sendTime"
/>
<result
column=
"send_time"
jdbcType=
"TIMESTAMP"
property=
"sendTime"
/>
<result
column=
"alarm_title"
jdbcType=
"VARCHAR"
property=
"alarmTitle"
/>
<result
column=
"alarm_title"
jdbcType=
"VARCHAR"
property=
"alarmTitle"
/>
...
@@ -18,12 +17,23 @@
...
@@ -18,12 +17,23 @@
<result
column=
"alarm_content"
jdbcType=
"LONGVARCHAR"
property=
"alarmContent"
/>
<result
column=
"alarm_content"
jdbcType=
"LONGVARCHAR"
property=
"alarmContent"
/>
</resultMap>
</resultMap>
<sql
id=
"Base_Column_List"
>
<sql
id=
"Base_Column_List"
>
id, flow_id, flow_name, run_id, version_name, alarm_email, alarm_
action, alarm_
result,
id, flow_id, flow_name, run_id, version_name, alarm_email, alarm_result,
send_time,alarm_title,flow_res
send_time,alarm_title,flow_res
</sql>
</sql>
<sql
id=
"Blob_Column_List"
>
<sql
id=
"Blob_Column_List"
>
alarm_content
alarm_content
</sql>
</sql>
<select
id=
"findEmailAlarmByAlarmResult"
resultMap=
"ResultMapWithBLOBs"
>
select
<include
refid=
"Base_Column_List"
/>
,
<include
refid=
"Blob_Column_List"
/>
from email_alarm
where alarm_result = '0'
</select>
<select
id=
"findEmailAlarmById"
parameterType=
"java.lang.Integer"
resultMap=
"ResultMapWithBLOBs"
>
<select
id=
"findEmailAlarmById"
parameterType=
"java.lang.Integer"
resultMap=
"ResultMapWithBLOBs"
>
select
select
<include
refid=
"Base_Column_List"
/>
<include
refid=
"Base_Column_List"
/>
...
@@ -57,9 +67,6 @@
...
@@ -57,9 +67,6 @@
<if
test=
"alarmEmail != null"
>
<if
test=
"alarmEmail != null"
>
alarm_email,
alarm_email,
</if>
</if>
<if
test=
"alarmAction != null"
>
alarm_action,
</if>
<if
test=
"alarmResult != null"
>
<if
test=
"alarmResult != null"
>
alarm_result,
alarm_result,
</if>
</if>
...
@@ -95,9 +102,7 @@
...
@@ -95,9 +102,7 @@
<if
test=
"alarmEmail != null"
>
<if
test=
"alarmEmail != null"
>
#{alarmEmail,jdbcType=VARCHAR},
#{alarmEmail,jdbcType=VARCHAR},
</if>
</if>
<if
test=
"alarmAction != null"
>
#{alarmAction,jdbcType=CHAR},
</if>
<if
test=
"alarmResult != null"
>
<if
test=
"alarmResult != null"
>
#{alarmResult,jdbcType=CHAR},
#{alarmResult,jdbcType=CHAR},
</if>
</if>
...
@@ -118,7 +123,7 @@
...
@@ -118,7 +123,7 @@
<insert
id=
"saveEmailAlarms"
parameterType=
"com.byit.model.EmailAlarm"
>
<insert
id=
"saveEmailAlarms"
parameterType=
"com.byit.model.EmailAlarm"
>
insert into email_alarm (
insert into email_alarm (
id, flow_id, flow_name, run_id, version_name, alarm_email, alarm_
action, alarm_
result,
id, flow_id, flow_name, run_id, version_name, alarm_email, alarm_result,
send_time,alarm_content,alarm_title,flow_res
send_time,alarm_content,alarm_title,flow_res
) values
) values
<foreach
collection=
"emailAlarms"
item=
"emailAlarm"
separator =
","
>
<foreach
collection=
"emailAlarms"
item=
"emailAlarm"
separator =
","
>
...
@@ -126,9 +131,9 @@
...
@@ -126,9 +131,9 @@
#{emailAlarm.id,jdbcType=INTEGER},#{emailAlarm.flowId,jdbcType=INTEGER},
#{emailAlarm.id,jdbcType=INTEGER},#{emailAlarm.flowId,jdbcType=INTEGER},
#{emailAlarm.flowName,jdbcType=VARCHAR},#{emailAlarm.runId,jdbcType=VARCHAR},
#{emailAlarm.flowName,jdbcType=VARCHAR},#{emailAlarm.runId,jdbcType=VARCHAR},
#{emailAlarm.versionName,jdbcType=VARCHAR},#{emailAlarm.alarmEmail,jdbcType=VARCHAR},
#{emailAlarm.versionName,jdbcType=VARCHAR},#{emailAlarm.alarmEmail,jdbcType=VARCHAR},
#{emailAlarm.alarm
Action,jdbcType=CHAR},#{emailAlarm.alarmResult,jdbcType=CHAR
},
#{emailAlarm.alarm
Result,jdbcType=CHAR},#{emailAlarm.sendTime,jdbcType=TIMESTAMP
},
#{emailAlarm.
sendTime,jdbcType=TIMESTAMP},#{emailAlarm.alarmContent,jdbcType=LONG
VARCHAR},
#{emailAlarm.
alarmContent,jdbcType=LONGVARCHAR},#{emailAlarm.alarmTitle,jdbcType=
VARCHAR},
#{emailAlarm.
alarmTitle,jdbcType=VARCHAR},#{emailAlarm.
flowRes,jdbcType=CHAR}
#{emailAlarm.flowRes,jdbcType=CHAR}
)
)
</foreach>
</foreach>
</insert>
</insert>
...
@@ -151,9 +156,7 @@
...
@@ -151,9 +156,7 @@
<if
test=
"alarmEmail != null"
>
<if
test=
"alarmEmail != null"
>
alarm_email = #{alarmEmail,jdbcType=VARCHAR},
alarm_email = #{alarmEmail,jdbcType=VARCHAR},
</if>
</if>
<if
test=
"alarmAction != null"
>
alarm_action = #{alarmAction,jdbcType=CHAR},
</if>
<if
test=
"alarmResult != null"
>
<if
test=
"alarmResult != null"
>
alarm_result = #{alarmResult,jdbcType=CHAR},
alarm_result = #{alarmResult,jdbcType=CHAR},
</if>
</if>
...
...
byit-myth-executor/myth-exector-plugin/src/main/java/com/byit/utils/JobUtils.java
View file @
e5e7415e
...
@@ -25,7 +25,9 @@ import java.util.concurrent.ConcurrentHashMap;
...
@@ -25,7 +25,9 @@ import java.util.concurrent.ConcurrentHashMap;
public
class
JobUtils
{
public
class
JobUtils
{
private
static
final
String
REQUEST_PREFIX
=
"http://"
;
private
static
final
String
REQUEST_PREFIX
=
"http://"
;
private
static
final
String
REQUEST_ADD_JOB_RESOURCES_SUFFIX
=
"/job/addJob"
;
private
static
final
String
REQUEST_ADD_JOB_RESOURCES_SUFFIX
=
"/job/addJob"
;
//发布工作流
/**
* 发布工作流
*/
private
static
final
String
REQUEST_FLOW_PUBLISH
=
"/api/flow/publish"
;
private
static
final
String
REQUEST_FLOW_PUBLISH
=
"/api/flow/publish"
;
//创建工作空间
//创建工作空间
private
static
final
String
REQUEST_WORKSPACE_ADD
=
"/api/workspace/add"
;
private
static
final
String
REQUEST_WORKSPACE_ADD
=
"/api/workspace/add"
;
...
...
demo-client/byit-demo-client/src/main/java/com/byit/test/ExploringSynchronized.java
deleted
100644 → 0
View file @
0c38bcbb
package
com
.
byit
.
test
;
/**
* @author huangfu
*/
public
class
ExploringSynchronized
implements
Runnable
{
private
static
final
String
LOCK_MARK
=
"LOCK_MARK"
;
/**
* 共享资源(临界资源)
*/
static
int
i
=
0
;
public
void
add
(){
synchronized
(
LOCK_MARK
){
i
++;
}
}
@Override
public
void
run
()
{
for
(
int
j
=
0
;
j
<
100000
;
j
++)
{
add
();
}
}
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
Thread
t1
=
new
Thread
(
new
ExploringSynchronized
());
Thread
t2
=
new
Thread
(
new
ExploringSynchronized
());
t1
.
start
();
t2
.
start
();
//join 主线程需要等待子线程完成后在结束
t1
.
join
();
t2
.
join
();
System
.
out
.
println
(
i
);
}
}
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