Commit beb46b1c by xmh

<feat> 添加存储配置更新功能

<feat> 下发任务5秒预读, 终止任务1秒预读
1 parent 6a45cc04
...@@ -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
...@@ -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);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!