Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-process-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c874c65c
authored
Sep 15, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
SopNode job
1 parent
f65ab167
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
132 additions
and
38 deletions
platform-process-api/pom.xml
platform-process/src/main/java/cn/com/glsx/Application.java
platform-process/src/main/java/cn/com/glsx/process/job/elastic/impl/SopInstExecuteJob.java
platform-process/src/main/java/cn/com/glsx/process/job/elastic/impl/SopInstLoadJob.java
platform-process/src/main/java/cn/com/glsx/process/job/elastic/impl/SopInstNodeJob.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/SopXxlJobUtil.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/HelloJobHandler.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstExecuteJobHandler.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstNodeExecuteJobHandler.java
pom.xml
platform-process-api/pom.xml
View file @
c874c65
...
@@ -22,6 +22,14 @@
...
@@ -22,6 +22,14 @@
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-feign
</artifactId>
<artifactId>
rest-admin-feign
</artifactId>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
32.1.2-jre
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
platform-process/src/main/java/cn/com/glsx/Application.java
View file @
c874c65
...
@@ -17,7 +17,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
...
@@ -17,7 +17,7 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
import
com.glsx.plat.context.EnableRestAdmin
;
import
com.glsx.plat.context.EnableRestAdmin
;
import
cn.com.glsx.process.job.xxljob.
impl.SopInstLoadJobHandler
;
import
cn.com.glsx.process.job.xxljob.
core.SopXxlJobUtil
;
/**
/**
* @author payu
* @author payu
...
@@ -41,6 +41,6 @@ public class Application implements CommandLineRunner {
...
@@ -41,6 +41,6 @@ public class Application implements CommandLineRunner {
@Override
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
public
void
run
(
String
...
args
)
throws
Exception
{
Sop
InstLoadJobHandler
.
initLoadJob
();
Sop
XxlJobUtil
.
initLoadJob
();
}
}
}
}
platform-process/src/main/java/cn/com/glsx/process/job/elastic/impl/SopInstExecuteJob.java
View file @
c874c65
...
@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext;
...
@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
cn.com.glsx.process.job.
elastic.core.
DynamicTaskService
;
import
cn.com.glsx.process.job.DynamicTaskService
;
import
cn.com.glsx.process.job.elastic.param.SopInstNodeParam
;
import
cn.com.glsx.process.job.elastic.param.SopInstNodeParam
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
...
@@ -55,14 +55,14 @@ public class SopInstExecuteJob implements SimpleJob {
...
@@ -55,14 +55,14 @@ public class SopInstExecuteJob implements SimpleJob {
if
(
StrUtil
.
isNotBlank
(
node
.
getNodeCron
()))
{
if
(
StrUtil
.
isNotBlank
(
node
.
getNodeCron
()))
{
// 按cron表达式执行
// 按cron表达式执行
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
node
.
getNodeCron
(),
new
SopInstNodeJob
(),
//
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), new SopInstNodeJob(),
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
paramJson
,
enabled
);
//
sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled);
}
else
{
}
else
{
//
//
// 立即执行: 1分钟后执行: 11 12 8 2 3 ? 2024
// 立即执行: 1分钟后执行: 11 12 8 2 3 ? 2024
String
cron
=
DateUtil
.
format
(
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
addMinutes
(
new
Date
(),
1
),
"s m H d M ? yyyy"
);
String
cron
=
DateUtil
.
format
(
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
addMinutes
(
new
Date
(),
1
),
"s m H d M ? yyyy"
);
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
cron
,
new
SopInstNodeJob
(),
//
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), cron, new SopInstNodeJob(),
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
paramJson
,
enabled
);
//
sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled);
}
}
}
}
...
...
platform-process/src/main/java/cn/com/glsx/process/job/elastic/impl/SopInstLoadJob.java
View file @
c874c65
...
@@ -6,7 +6,6 @@ import com.dangdang.ddframe.job.api.ShardingContext;
...
@@ -6,7 +6,6 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
cn.com.glsx.process.job.elastic.core.DynamicTaskService
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.service.SopService
;
import
cn.com.glsx.process.modules.service.SopService
;
...
@@ -28,15 +27,15 @@ public class SopInstLoadJob implements SimpleJob {
...
@@ -28,15 +27,15 @@ public class SopInstLoadJob implements SimpleJob {
log
.
info
(
"---------SopInstLoadJob-------------:"
+
JobParameter
);
log
.
info
(
"---------SopInstLoadJob-------------:"
+
JobParameter
);
SopService
sopService
=
SpringUtils
.
getBean
(
SopService
.
class
);
SopService
sopService
=
SpringUtils
.
getBean
(
SopService
.
class
);
DynamicTaskService
taskService
=
SpringUtils
.
getBean
(
DynamicTaskService
.
class
);
//
DynamicTaskService taskService = SpringUtils.getBean(DynamicTaskService.class);
List
<
SopInst
>
all
=
sopService
.
loadAllInst
();
List
<
SopInst
>
all
=
sopService
.
loadAllInst
();
for
(
SopInst
inst
:
all
)
{
for
(
SopInst
inst
:
all
)
{
if
(
inst
.
getInstStatus
()
==
1
)
{
if
(
inst
.
getInstStatus
()
==
1
)
{
taskService
.
create
(
jobName
(
inst
),
inst
.
getInstCron
(),
1
,
new
SopInstExecuteJob
(),
inst
.
getInstName
(),
inst
.
getInstId
());
//
taskService.create(jobName(inst), inst.getInstCron(), 1, new SopInstExecuteJob(), inst.getInstName(), inst.getInstId());
}
else
{
}
else
{
taskService
.
stopJob
(
inst
.
getInstName
());
//
taskService.stopJob(inst.getInstName());
}
}
}
}
...
...
platform-process/src/main/java/cn/com/glsx/process/job/elastic/impl/SopInstNodeJob.java
View file @
c874c65
...
@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext;
...
@@ -7,7 +7,7 @@ import com.dangdang.ddframe.job.api.ShardingContext;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
cn.com.glsx.process.job.
elastic.core.
DynamicTaskService
;
import
cn.com.glsx.process.job.DynamicTaskService
;
import
cn.com.glsx.process.job.elastic.param.SopInstNodeParam
;
import
cn.com.glsx.process.job.elastic.param.SopInstNodeParam
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
...
@@ -67,8 +67,8 @@ public class SopInstNodeJob implements SimpleJob {
...
@@ -67,8 +67,8 @@ public class SopInstNodeJob implements SimpleJob {
DynamicTaskService
taskService
=
SpringUtils
.
getBean
(
DynamicTaskService
.
class
);
DynamicTaskService
taskService
=
SpringUtils
.
getBean
(
DynamicTaskService
.
class
);
// 按cron表达式执行
// 按cron表达式执行
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
node
.
getNodeCron
(),
new
SopInstNodeJob
(),
//
taskService.create(SopInstLoadJob.jobName(sop.getInst(), node), node.getNodeCron(), new SopInstNodeJob(),
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
paramJson
,
enabled
);
//
sop.getInst().getInstName() + "-" + node.getNodeName(), paramJson, enabled);
}
}
...
...
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/SopXxlJobUtil.java
View file @
c874c65
package
cn
.
com
.
glsx
.
process
.
job
.
xxljob
.
core
;
package
cn
.
com
.
glsx
.
process
.
job
.
xxljob
.
core
;
import
java.util.Date
;
import
java.util.Set
;
import
cn.com.glsx.process.job.elastic.param.SopInstNodeParam
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Slf4j
...
@@ -12,15 +20,17 @@ public class SopXxlJobUtil {
...
@@ -12,15 +20,17 @@ public class SopXxlJobUtil {
public
static
final
String
SOP_EXECUTE_JOB_ID
=
"sopInstExecuteJobHandler"
;
public
static
final
String
SOP_EXECUTE_JOB_ID
=
"sopInstExecuteJobHandler"
;
public
static
final
String
SOP_NODE_EXECUTE_JOB_ID
=
"sopNodeExecuteJobHandler"
;
public
static
void
pauseSop
(
SopStruct
sop
)
{
public
static
void
pauseSop
(
SopStruct
sop
)
{
String
jobBusId
=
SopStruct
.
jobBusId
(
sop
.
getInst
());
String
jobBusId
=
jobBusId
(
sop
.
getInst
());
String
pause
=
XxlJobUtil
.
pause
(
jobBusId
);
String
pause
=
XxlJobUtil
.
pause
(
jobBusId
);
log
.
info
(
"【{}】Sop任务停止:{}"
,
jobBusId
,
pause
);
log
.
info
(
"【{}】Sop任务停止:{}"
,
jobBusId
,
pause
);
if
(
sop
!=
null
)
{
if
(
sop
!=
null
)
{
// 遍历node,停止任务
// 遍历node,停止任务
for
(
SopInstNode
node
:
sop
.
getInstNodeMap
().
values
())
{
for
(
SopInstNode
node
:
sop
.
getInstNodeMap
().
values
())
{
jobBusId
=
SopStruct
.
jobBusId
(
sop
.
getInst
(),
node
);
jobBusId
=
jobBusId
(
sop
.
getInst
(),
node
);
pause
=
XxlJobUtil
.
pause
(
jobBusId
);
pause
=
XxlJobUtil
.
pause
(
jobBusId
);
log
.
info
(
"【{}】Sop节点任务停止:{}"
,
jobBusId
,
pause
);
log
.
info
(
"【{}】Sop节点任务停止:{}"
,
jobBusId
,
pause
);
}
}
...
@@ -51,7 +61,7 @@ public class SopXxlJobUtil {
...
@@ -51,7 +61,7 @@ public class SopXxlJobUtil {
}
}
public
static
void
initSopJob
(
SopInst
inst
)
{
public
static
void
initSopJob
(
SopInst
inst
)
{
String
jobBusId
=
SopStruct
.
jobBusId
(
inst
);
String
jobBusId
=
jobBusId
(
inst
);
XxlJobInfo
job
=
XxlJobUtil
.
findByBusKey
(
jobBusId
);
XxlJobInfo
job
=
XxlJobUtil
.
findByBusKey
(
jobBusId
);
if
(
job
!=
null
)
{
if
(
job
!=
null
)
{
XxlJobUtil
.
remove
(
jobBusId
);
XxlJobUtil
.
remove
(
jobBusId
);
...
@@ -70,4 +80,61 @@ public class SopXxlJobUtil {
...
@@ -70,4 +80,61 @@ public class SopXxlJobUtil {
log
.
info
(
"【{}】Sop任务启动:{}"
,
inst
.
getInstId
(),
add
);
log
.
info
(
"【{}】Sop任务启动:{}"
,
inst
.
getInstId
(),
add
);
}
}
public
static
void
initSopNodesJob
(
SopStruct
sop
)
{
if
(
sop
==
null
)
{
return
;
}
if
(
sop
.
getInst
().
getInstStatus
()
==
0
)
{
pauseSop
(
sop
);
return
;
}
for
(
SopInstNode
node
:
sop
.
getInstNodeMap
().
values
())
{
initSopNodeJob
(
sop
,
node
);
}
}
public
static
void
initSopNodeJob
(
SopStruct
sop
,
SopInstNode
node
)
{
String
jobBusId
=
jobBusId
(
sop
.
getInst
(),
node
);
XxlJobInfo
job
=
XxlJobUtil
.
findByBusKey
(
jobBusId
);
if
(
job
!=
null
)
{
XxlJobUtil
.
remove
(
jobBusId
);
}
// 15 2/3 * * * ?
String
cron
=
DateUtil
.
format
(
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
addMinutes
(
new
Date
(),
1
),
"s m H d M ?"
);
if
(
StrUtil
.
isNotBlank
(
node
.
getNodeCron
()))
{
cron
=
node
.
getNodeCron
();
}
// 前置节点,后置节点
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
linkPair
=
sop
.
getInstLinkMap
().
get
(
node
.
getNodeId
());
boolean
enabled
=
linkPair
==
null
||
linkPair
.
getKey
().
isEmpty
();
SopInstNodeParam
params
=
new
SopInstNodeParam
();
params
.
setInstNodeId
(
node
.
getInstNodeId
());
params
.
setPreIds
(
linkPair
.
getKey
());
String
paramJson
=
JSONUtil
.
toJsonStr
(
params
);
// 重建job
job
=
new
XxlJobInfo
();
job
.
setExecutorParam
(
sop
.
getInst
().
getInstId
());
// TODO
job
.
setJobDesc
(
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
());
job
.
setAuthor
(
"admin"
);
job
.
setScheduleConf
(
cron
);
job
.
setExecutorHandler
(
SopXxlJobUtil
.
SOP_NODE_EXECUTE_JOB_ID
);
job
.
setBusKey
(
jobBusId
);
job
.
setTriggerStatus
(
1
);
String
add
=
XxlJobUtil
.
add
(
job
);
log
.
info
(
"【{}】Sop节点任务启动:{}"
,
jobBusId
,
add
);
}
public
static
String
jobBusId
(
SopInst
inst
)
{
return
inst
.
getInstId
();
}
public
static
String
jobBusId
(
SopInst
inst
,
SopInstNode
node
)
{
return
inst
.
getInstId
()
+
"-"
+
node
.
getNodeId
();
}
}
}
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/HelloJobHandler.java
deleted
100644 → 0
View file @
f65ab16
package
cn
.
com
.
glsx
.
process
.
job
.
xxljob
.
impl
;
import
org.springframework.stereotype.Component
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
lombok.extern.slf4j.Slf4j
;
@Component
@Slf4j
public
class
HelloJobHandler
{
@XxlJob
(
"demoJobHandler"
)
public
void
demoJobHandler
(
String
param
)
throws
Exception
{
log
.
info
(
"XXL-JOB, Hello World."
);
}
}
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstExecuteJobHandler.java
View file @
c874c65
...
@@ -29,7 +29,7 @@ public class SopInstExecuteJobHandler {
...
@@ -29,7 +29,7 @@ public class SopInstExecuteJobHandler {
SopStruct
sop
=
sopService
.
loadSop
(
instId
);
SopStruct
sop
=
sopService
.
loadSop
(
instId
);
// 创建所有节点任务
// 创建所有节点任务
initSopNode
Job
(
sop
);
SopXxlJobUtil
.
initSopNodes
Job
(
sop
);
}
}
}
}
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstNodeExecuteJobHandler.java
0 → 100644
View file @
c874c65
package
cn
.
com
.
glsx
.
process
.
job
.
xxljob
.
impl
;
import
javax.annotation.Resource
;
import
org.springframework.stereotype.Component
;
import
com.xxl.job.core.context.XxlJobHelper
;
import
com.xxl.job.core.handler.annotation.XxlJob
;
import
cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.service.SopService
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Component
public
class
SopInstNodeExecuteJobHandler
{
@Resource
private
SopService
sopService
;
@XxlJob
(
SopXxlJobUtil
.
SOP_NODE_EXECUTE_JOB_ID
)
public
void
handler
(
String
param
)
throws
Exception
{
param
=
XxlJobHelper
.
getJobParam
();
log
.
info
(
"【执行Sop节点】{}"
,
param
);
String
instId
=
param
;
SopStruct
sop
=
sopService
.
loadSop
(
instId
);
// 创建所有节点任务
// SopXxlJobUtil.initSopNodeJob(sop);
}
}
pom.xml
View file @
c874c65
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<parent>
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-framework
</artifactId>
<artifactId>
rest-admin-framework
</artifactId>
...
@@ -48,8 +50,10 @@
...
@@ -48,8 +50,10 @@
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
<modules>
<modules>
<module>
platform-process
</module>
<module>
platform-process
</module>
<module>
platform-process-api
</module>
<module>
platform-process-api
</module>
</modules>
</modules>
</project>
</project>
Write
Preview
Markdown
is supported
Attach a file
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 post a comment