线程池直接拉大
This commit is contained in:
parent
519f9969ec
commit
e9890a3856
19
src/main/java/com/ycwl/basic/config/SchedulerConfig.java
Normal file
19
src/main/java/com/ycwl/basic/config/SchedulerConfig.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package com.ycwl.basic.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableScheduling
|
||||||
|
public class SchedulerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ThreadPoolTaskScheduler taskScheduler() {
|
||||||
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||||
|
scheduler.setPoolSize(256);
|
||||||
|
scheduler.setThreadNamePrefix("Scheduler-");
|
||||||
|
return scheduler;
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@IgnoreToken
|
@IgnoreToken
|
||||||
@RestController
|
@RestController
|
||||||
@Api(tags = "渲染端对接接口")
|
@Api(tags = "渲染端对接接口")
|
||||||
@ -42,7 +44,9 @@ public class TaskTaskController {
|
|||||||
|
|
||||||
@PostMapping("/{taskId}/uploadUrl")
|
@PostMapping("/{taskId}/uploadUrl")
|
||||||
public ApiResponse<String> getUploadUrl(@PathVariable Long taskId, @RequestBody WorkerAuthReqVo req) {
|
public ApiResponse<String> getUploadUrl(@PathVariable Long taskId, @RequestBody WorkerAuthReqVo req) {
|
||||||
return ApiResponse.success(taskService.getUploadUrl(taskId, req));
|
String urlForUpload = taskService.getUploadUrl(taskId, req);
|
||||||
|
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
|
||||||
|
return ApiResponse.success(urlForUpload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/{taskId}/start")
|
@PostMapping("/{taskId}/start")
|
||||||
|
@ -57,7 +57,9 @@ public class VptController {
|
|||||||
adapter = StorageFactory.use("video");
|
adapter = StorageFactory.use("video");
|
||||||
}
|
}
|
||||||
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
||||||
return adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
|
String urlForUpload = adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
|
||||||
|
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
|
||||||
|
return urlForUpload;
|
||||||
}
|
}
|
||||||
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
||||||
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
||||||
|
@ -59,7 +59,9 @@ public class WvpController {
|
|||||||
adapter = StorageFactory.use("video");
|
adapter = StorageFactory.use("video");
|
||||||
}
|
}
|
||||||
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
String filename = StorageUtil.joinPath(StorageConstant.VIDEO_PIECE_PATH, taskId.toString() + ".mp4");
|
||||||
return adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
|
String urlForUpload = adapter.getUrlForUpload(new Date(System.currentTimeMillis() + 1000 * 60 * 60), "video/mp4", filename);
|
||||||
|
urlForUpload = urlForUpload.replace("-internal.aliyuncs.com", ".aliyuncs.com");
|
||||||
|
return urlForUpload;
|
||||||
}
|
}
|
||||||
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
@PostMapping("/scenic/{scenicId}/{taskId}/success")
|
||||||
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
public ApiResponse<String> success(@PathVariable("scenicId") Long scenicId, @PathVariable("taskId") Long taskId, @RequestBody FileObject fileObject) {
|
||||||
|
@ -15,6 +15,7 @@ import java.util.Collections;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -28,7 +29,7 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
|
|||||||
public Date endTime;
|
public Date endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Task> taskList = Collections.synchronizedList(new ArrayList<>());
|
private static List<Task> taskList = new CopyOnWriteArrayList<>();
|
||||||
private static ConcurrentHashMap<Long, FileObject> fileListMap = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<Long, FileObject> fileListMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private VptPassiveStorageConfig config;
|
private VptPassiveStorageConfig config;
|
||||||
@ -37,10 +38,6 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
|
|||||||
loadConfig(configJson);
|
loadConfig(configJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUrlForTask(Long taskId) {
|
|
||||||
return StorageUtil.joinPath("video-source", taskId.toString() + ".mp4");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onReceiveResult(Long taskId, FileObject fileObject) {
|
public static void onReceiveResult(Long taskId, FileObject fileObject) {
|
||||||
if (fileObject == null) {
|
if (fileObject == null) {
|
||||||
log.info("任务{}获取视频失败!", taskId);
|
log.info("任务{}获取视频失败!", taskId);
|
||||||
@ -81,6 +78,7 @@ public class VptPassiveStorageOperator extends ADeviceStorageOperator {
|
|||||||
task.startTime = startDate;
|
task.startTime = startDate;
|
||||||
task.endTime = endDate;
|
task.endTime = endDate;
|
||||||
taskList.add(task);
|
taskList.add(task);
|
||||||
|
log.info("任务{}获取视频开始!共{}", task.taskId, taskList.size());
|
||||||
Date taskStartTime = new Date();
|
Date taskStartTime = new Date();
|
||||||
while (true) {
|
while (true) {
|
||||||
if (new Date().getTime() - taskStartTime.getTime() > 80000L) {
|
if (new Date().getTime() - taskStartTime.getTime() > 80000L) {
|
||||||
|
@ -13,6 +13,7 @@ import java.util.Collections;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -26,7 +27,7 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
|
|||||||
public Date endTime;
|
public Date endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Task> taskList = Collections.synchronizedList(new ArrayList<>());
|
private static List<Task> taskList = new CopyOnWriteArrayList<>();
|
||||||
private static ConcurrentHashMap<Long, FileObject> fileListMap = new ConcurrentHashMap<>();
|
private static ConcurrentHashMap<Long, FileObject> fileListMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private WvpPassiveStorageConfig config;
|
private WvpPassiveStorageConfig config;
|
||||||
@ -35,10 +36,6 @@ public class WvpPassiveStorageOperator extends ADeviceStorageOperator {
|
|||||||
loadConfig(configJson);
|
loadConfig(configJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getUrlForTask(Long taskId) {
|
|
||||||
return StorageUtil.joinPath("video-source", taskId.toString() + ".mp4");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onReceiveResult(Long taskId, FileObject fileObject) {
|
public static void onReceiveResult(Long taskId, FileObject fileObject) {
|
||||||
if (fileObject == null) {
|
if (fileObject == null) {
|
||||||
log.info("任务{}获取视频失败!", taskId);
|
log.info("任务{}获取视频失败!", taskId);
|
||||||
|
@ -35,7 +35,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -78,19 +78,29 @@ public class VideoPieceGetter {
|
|||||||
String outputFile;
|
String outputFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinkedBlockingQueue<Task> queue = new LinkedBlockingQueue<>();
|
public static ConcurrentLinkedQueue<Task> queue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
public static void addTask(Task task) {
|
public static void addTask(Task task) {
|
||||||
queue.add(task);
|
queue.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedRate = 2000L)
|
@Scheduled(fixedRate = 200L)
|
||||||
public void doTask() {
|
public void doTask() {
|
||||||
Task task = queue.poll();
|
Task task = queue.poll();
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("poll task: {}", task);
|
log.info("poll task: {}/{}", task, queue.size());
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
runTask(task);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("run task error", e);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runTask(Task task) {
|
||||||
List<String> templatePlaceholder;
|
List<String> templatePlaceholder;
|
||||||
if (null != task.getTemplateId()) {
|
if (null != task.getTemplateId()) {
|
||||||
templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
|
templatePlaceholder = templateRepository.getTemplatePlaceholder(task.getTemplateId());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user