Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
谢明辉
/
fanxing3
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 beb46b1c
authored
Feb 09, 2022
by
xmh
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
<feat> 添加存储配置更新功能
<feat> 下发任务5秒预读, 终止任务1秒预读
1 parent
6a45cc04
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
14 deletions
fanxing-task/src/main/java/com/viontech/fanxing/task/controller/web/TaskController.java
fanxing-task/src/main/java/com/viontech/fanxing/task/runner/TaskRunner.java
fanxing-task/src/main/java/com/viontech/fanxing/task/controller/web/TaskController.java
View file @
beb46b1
...
@@ -19,7 +19,9 @@ import com.viontech.fanxing.task.controller.base.TaskBaseController;
...
@@ -19,7 +19,9 @@ import com.viontech.fanxing.task.controller.base.TaskBaseController;
import
com.viontech.fanxing.task.model.ConfigBuilder
;
import
com.viontech.fanxing.task.model.ConfigBuilder
;
import
com.viontech.fanxing.task.runner.VaServerCheckRunner
;
import
com.viontech.fanxing.task.runner.VaServerCheckRunner
;
import
com.viontech.fanxing.task.service.OpsClientService
;
import
com.viontech.fanxing.task.service.OpsClientService
;
import
com.viontech.fanxing.task.service.TaskDataService
;
import
com.viontech.fanxing.task.utils.SceneUtils
;
import
com.viontech.fanxing.task.utils.SceneUtils
;
import
com.viontech.fanxing.task.utils.TaskUtils
;
import
com.viontech.keliu.util.JsonMessageUtil
;
import
com.viontech.keliu.util.JsonMessageUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.compress.archivers.ArchiveEntry
;
import
org.apache.commons.compress.archivers.ArchiveEntry
;
...
@@ -49,7 +51,8 @@ import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
...
@@ -49,7 +51,8 @@ import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
@Slf4j
@Slf4j
public
class
TaskController
extends
TaskBaseController
{
public
class
TaskController
extends
TaskBaseController
{
@Resource
private
TaskDataService
taskDataService
;
@Resource
@Resource
private
OpsClientService
opsClientService
;
private
OpsClientService
opsClientService
;
...
@@ -192,9 +195,7 @@ public class TaskController extends TaskBaseController {
...
@@ -192,9 +195,7 @@ public class TaskController extends TaskBaseController {
String
xml
=
config
.
getString
(
"xml"
);
String
xml
=
config
.
getString
(
"xml"
);
ConfigBuilder
configBuilder
=
new
ConfigBuilder
();
ConfigBuilder
configBuilder
=
new
ConfigBuilder
();
Channel
channel
=
opsClientService
.
getChannelByChannelUnid
(
task
.
getChannelUnid
());
Channel
channel
=
opsClientService
.
getChannelByChannelUnid
(
task
.
getChannelUnid
());
String
c
=
configBuilder
.
buildDefaultConfig
(
xml
)
String
c
=
configBuilder
.
buildDefaultConfig
(
xml
).
buildVchanInfo
(
channel
.
getName
(),
channel
.
getChannelUnid
()).
build
();
.
buildVchanInfo
(
channel
.
getName
(),
channel
.
getChannelUnid
())
.
build
();
config
.
put
(
"xml"
,
c
);
config
.
put
(
"xml"
,
c
);
}
}
TaskVo
temp
=
new
TaskVo
();
TaskVo
temp
=
new
TaskVo
();
...
@@ -232,9 +233,7 @@ public class TaskController extends TaskBaseController {
...
@@ -232,9 +233,7 @@ public class TaskController extends TaskBaseController {
}
else
{
}
else
{
return
JsonMessageUtil
.
getErrorJsonMsg
(
"解析失败"
);
return
JsonMessageUtil
.
getErrorJsonMsg
(
"解析失败"
);
}
}
JSONArray
scenes
=
Optional
.
of
(
source
).
map
(
x
->
x
.
getJSONArray
(
"mtasks"
))
JSONArray
scenes
=
Optional
.
of
(
source
).
map
(
x
->
x
.
getJSONArray
(
"mtasks"
)).
map
(
x
->
x
.
getJSONObject
(
0
)).
map
(
x
->
x
.
getJSONArray
(
"scenes"
)).
orElse
(
new
JSONArray
());
.
map
(
x
->
x
.
getJSONObject
(
0
))
.
map
(
x
->
x
.
getJSONArray
(
"scenes"
)).
orElse
(
new
JSONArray
());
for
(
int
i
=
0
;
i
<
Math
.
min
(
scenes
.
size
(),
sceneArr
.
size
());
i
++)
{
for
(
int
i
=
0
;
i
<
Math
.
min
(
scenes
.
size
(),
sceneArr
.
size
());
i
++)
{
JSONObject
sourceScene
=
scenes
.
getJSONObject
(
i
);
JSONObject
sourceScene
=
scenes
.
getJSONObject
(
i
);
...
@@ -246,9 +245,7 @@ public class TaskController extends TaskBaseController {
...
@@ -246,9 +245,7 @@ public class TaskController extends TaskBaseController {
if
(
config
!=
null
)
{
if
(
config
!=
null
)
{
String
xml
=
config
.
getString
(
"xml"
);
String
xml
=
config
.
getString
(
"xml"
);
ConfigBuilder
configBuilder
=
new
ConfigBuilder
();
ConfigBuilder
configBuilder
=
new
ConfigBuilder
();
String
c
=
configBuilder
.
buildDefaultConfig
(
xml
)
String
c
=
configBuilder
.
buildDefaultConfig
(
xml
).
buildVchanInfo
(
channel
.
getName
(),
channel
.
getChannelUnid
()).
build
();
.
buildVchanInfo
(
channel
.
getName
(),
channel
.
getChannelUnid
())
.
build
();
config
.
put
(
"xml"
,
c
);
config
.
put
(
"xml"
,
c
);
}
}
}
}
...
@@ -293,8 +290,7 @@ public class TaskController extends TaskBaseController {
...
@@ -293,8 +290,7 @@ public class TaskController extends TaskBaseController {
byte
[]
bytes
=
s
.
getBytes
(
StandardCharsets
.
UTF_8
);
byte
[]
bytes
=
s
.
getBytes
(
StandardCharsets
.
UTF_8
);
String
channelName
=
channel
==
null
?
"未知"
:
channel
.
getName
();
String
channelName
=
channel
==
null
?
"未知"
:
channel
.
getName
();
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
);
response
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM_VALUE
);
response
.
setHeader
(
"Content-Disposition"
,
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
channelName
+
"_"
+
sceneUnid
+
".json"
,
"utf8"
));
"attachment;filename="
+
URLEncoder
.
encode
(
channelName
+
"_"
+
sceneUnid
+
".json"
,
"utf8"
));
IOUtils
.
write
(
bytes
,
response
.
getOutputStream
());
IOUtils
.
write
(
bytes
,
response
.
getOutputStream
());
}
}
...
@@ -340,4 +336,30 @@ public class TaskController extends TaskBaseController {
...
@@ -340,4 +336,30 @@ public class TaskController extends TaskBaseController {
}
}
}
}
/**
* 更新存储配置
*
* @param storeConfigId
*
* @return
*/
@GetMapping
(
"/storeConfig/sync"
)
public
JsonMessageUtil
.
JsonMessage
storeConfigSync
(
@RequestParam
Long
storeConfigId
)
{
TaskExample
taskExample
=
new
TaskExample
();
taskExample
.
createCriteria
().
andStoreConfigIdEqualTo
(
storeConfigId
);
List
<
Task
>
tasks
=
taskService
.
selectByExample
(
taskExample
);
if
(
tasks
.
size
()
>
0
)
{
for
(
Task
task
:
tasks
)
{
try
{
if
(
TaskUtils
.
INSTANCE
.
canRun
(
task
))
{
taskDataService
.
updateTask
(
task
,
false
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"更新任务失败"
,
e
);
}
}
}
return
getSuccessJsonMsg
(
"存储配置同步成功"
);
}
}
}
\ No newline at end of file
\ No newline at end of file
fanxing-task/src/main/java/com/viontech/fanxing/task/runner/TaskRunner.java
View file @
beb46b1
...
@@ -57,7 +57,8 @@ public class TaskRunner {
...
@@ -57,7 +57,8 @@ public class TaskRunner {
RScoredSortedSet
<
String
>
set
=
redisService
.
getToBeExecutedTaskUnidSet
();
RScoredSortedSet
<
String
>
set
=
redisService
.
getToBeExecutedTaskUnidSet
();
RMap
<
String
,
VaServerInfo
>
vaServerMap
=
vaServerService
.
getVaServerRedisRepository
().
getVaServerInfoMap
();
RMap
<
String
,
VaServerInfo
>
vaServerMap
=
vaServerService
.
getVaServerRedisRepository
().
getVaServerInfoMap
();
Collection
<
String
>
entryCollection
=
set
.
valueRange
(
0
,
true
,
System
.
currentTimeMillis
(),
true
);
// 提前5秒预读
Collection
<
String
>
entryCollection
=
set
.
valueRange
(
0
,
true
,
System
.
currentTimeMillis
()
+
5000
,
true
);
for
(
String
taskUnid
:
entryCollection
)
{
for
(
String
taskUnid
:
entryCollection
)
{
RLock
taskLock
=
taskDataService
.
getRepository
().
getTaskLock
(
taskUnid
);
RLock
taskLock
=
taskDataService
.
getRepository
().
getTaskLock
(
taskUnid
);
try
{
try
{
...
@@ -126,7 +127,8 @@ public class TaskRunner {
...
@@ -126,7 +127,8 @@ public class TaskRunner {
try
{
try
{
RScoredSortedSet
<
String
>
set
=
redisService
.
getToBeTerminatedTaskUnidSet
();
RScoredSortedSet
<
String
>
set
=
redisService
.
getToBeTerminatedTaskUnidSet
();
RScoredSortedSet
<
String
>
toBeExecutedTaskUnidSet
=
redisService
.
getToBeExecutedTaskUnidSet
();
RScoredSortedSet
<
String
>
toBeExecutedTaskUnidSet
=
redisService
.
getToBeExecutedTaskUnidSet
();
Collection
<
String
>
entryCollection
=
set
.
valueRange
(
0
,
true
,
System
.
currentTimeMillis
(),
true
);
// 提前 1 秒预读
Collection
<
String
>
entryCollection
=
set
.
valueRange
(
0
,
true
,
System
.
currentTimeMillis
()
+
1000
,
true
);
for
(
String
taskUnid
:
entryCollection
)
{
for
(
String
taskUnid
:
entryCollection
)
{
TaskData
taskData
=
taskDataService
.
getRepository
().
getTaskDataByUnid
(
taskUnid
);
TaskData
taskData
=
taskDataService
.
getRepository
().
getTaskDataByUnid
(
taskUnid
);
...
...
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