|
@@ -1,95 +1,95 @@
|
|
|
-package com.backendsys.modules.queue.controller;
|
|
|
-
|
|
|
-import cn.hutool.core.convert.Convert;
|
|
|
-import com.backendsys.modules.common.config.security.annotations.Anonymous;
|
|
|
-import com.backendsys.modules.common.utils.Result;
|
|
|
-import com.backendsys.modules.queue.entity.Entire;
|
|
|
-import com.backendsys.modules.queue.service.TaskService;
|
|
|
-import com.backendsys.modules.sdk.comfyui.enums.TaskStatusEnums;
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
-import jakarta.annotation.PostConstruct;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.data.redis.connection.stream.MapRecord;
|
|
|
-import org.springframework.data.redis.connection.stream.PendingMessages;
|
|
|
-import org.springframework.data.redis.connection.stream.RecordId;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
-
|
|
|
-@RestController
|
|
|
-public class TaskStatusController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private TaskService taskService;
|
|
|
-
|
|
|
- @Value("${comfyui.queue-key}")
|
|
|
- private String QUEUE_KEY;
|
|
|
- @Value("${spring.application.name}")
|
|
|
- private String APPLICATION_NAME;
|
|
|
-
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- @Operation(summary = "初始化消费者组")
|
|
|
- public void initConsumerGroup() {
|
|
|
- String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
- String group_name = stream_key + ":group";
|
|
|
- taskService.initConsumerGroup(stream_key, group_name);
|
|
|
- }
|
|
|
-
|
|
|
- @Operation(summary = "添加任务")
|
|
|
- @GetMapping("/api/tasks/addTask")
|
|
|
- public Result addTask() {
|
|
|
- Map<String, Object> data = new LinkedHashMap<>();
|
|
|
- data.put("progress", 0);
|
|
|
- data.put("status", TaskStatusEnums.EXECUTION_START.getValue());
|
|
|
-
|
|
|
- // 加入队列
|
|
|
- String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
- RecordId record_id = taskService.addTask(stream_key, data);
|
|
|
- data.put("task_id", record_id.getValue());
|
|
|
-
|
|
|
- return Result.success().put("data", data);
|
|
|
- }
|
|
|
-
|
|
|
- @Anonymous
|
|
|
- @Operation(summary = "消费任务")
|
|
|
- @GetMapping("/api/tasks/consumeTask")
|
|
|
- public Result consumeTask(String task_id) {
|
|
|
- String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
- taskService.consumeTask(stream_key, task_id);
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- @Anonymous
|
|
|
- @Operation(summary = "移除任务")
|
|
|
- @GetMapping("/api/tasks/removeTask")
|
|
|
- public Result removeTask(String task_id) {
|
|
|
- String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
- taskService.removeTask(stream_key, task_id);
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- @Anonymous
|
|
|
- @Operation(summary = "获取任务列表")
|
|
|
- @GetMapping("/api/tasks/getTaskList")
|
|
|
- public Result getTaskList() {
|
|
|
- String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
- List<MapRecord<String, String, String>> task_list = taskService.getTaskList(stream_key);
|
|
|
- return Result.success().put("data", task_list);
|
|
|
- }
|
|
|
-
|
|
|
- @Anonymous
|
|
|
- @Operation(summary = "获取任务列表(未消费)")
|
|
|
- @GetMapping("/api/tasks/getTaskPaddingList")
|
|
|
- public Result getTaskPaddingList() {
|
|
|
- String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
- List<MapRecord<String, String, String>> task_list = taskService.getTaskPaddingList(stream_key);
|
|
|
- return Result.success().put("data", task_list);
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.backendsys.modules.queue.controller;
|
|
|
+//
|
|
|
+//import cn.hutool.core.convert.Convert;
|
|
|
+//import com.backendsys.modules.common.config.security.annotations.Anonymous;
|
|
|
+//import com.backendsys.modules.common.utils.Result;
|
|
|
+//import com.backendsys.modules.queue.entity.Entire;
|
|
|
+//import com.backendsys.modules.queue.service.TaskService;
|
|
|
+//import com.backendsys.modules.sdk.comfyui.enums.TaskStatusEnums;
|
|
|
+//import io.swagger.v3.oas.annotations.Operation;
|
|
|
+//import jakarta.annotation.PostConstruct;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.data.redis.connection.stream.MapRecord;
|
|
|
+//import org.springframework.data.redis.connection.stream.PendingMessages;
|
|
|
+//import org.springframework.data.redis.connection.stream.RecordId;
|
|
|
+//import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+//import org.springframework.web.bind.annotation.RestController;
|
|
|
+//
|
|
|
+//import java.util.LinkedHashMap;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Map;
|
|
|
+//import java.util.UUID;
|
|
|
+//
|
|
|
+//@RestController
|
|
|
+//public class TaskStatusController {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private TaskService taskService;
|
|
|
+//
|
|
|
+// @Value("${comfyui.queue-key}")
|
|
|
+// private String QUEUE_KEY;
|
|
|
+// @Value("${spring.application.name}")
|
|
|
+// private String APPLICATION_NAME;
|
|
|
+//
|
|
|
+//
|
|
|
+// @PostConstruct
|
|
|
+// @Operation(summary = "初始化消费者组")
|
|
|
+// public void initConsumerGroup() {
|
|
|
+// String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
+// String group_name = stream_key + ":group";
|
|
|
+// taskService.initConsumerGroup(stream_key, group_name);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Operation(summary = "添加任务")
|
|
|
+// @GetMapping("/api/tasks/addTask")
|
|
|
+// public Result addTask() {
|
|
|
+// Map<String, Object> data = new LinkedHashMap<>();
|
|
|
+// data.put("progress", 0);
|
|
|
+// data.put("status", TaskStatusEnums.EXECUTION_START.getValue());
|
|
|
+//
|
|
|
+// // 加入队列
|
|
|
+// String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
+// RecordId record_id = taskService.addTask(stream_key, data);
|
|
|
+// data.put("task_id", record_id.getValue());
|
|
|
+//
|
|
|
+// return Result.success().put("data", data);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Anonymous
|
|
|
+// @Operation(summary = "消费任务")
|
|
|
+// @GetMapping("/api/tasks/consumeTask")
|
|
|
+// public Result consumeTask(String task_id) {
|
|
|
+// String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
+// taskService.consumeTask(stream_key, task_id);
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Anonymous
|
|
|
+// @Operation(summary = "移除任务")
|
|
|
+// @GetMapping("/api/tasks/removeTask")
|
|
|
+// public Result removeTask(String task_id) {
|
|
|
+// String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
+// taskService.removeTask(stream_key, task_id);
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Anonymous
|
|
|
+// @Operation(summary = "获取任务列表")
|
|
|
+// @GetMapping("/api/tasks/getTaskList")
|
|
|
+// public Result getTaskList() {
|
|
|
+// String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
+// List<MapRecord<String, String, String>> task_list = taskService.getTaskList(stream_key);
|
|
|
+// return Result.success().put("data", task_list);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Anonymous
|
|
|
+// @Operation(summary = "获取任务列表(未消费)")
|
|
|
+// @GetMapping("/api/tasks/getTaskPaddingList")
|
|
|
+// public Result getTaskPaddingList() {
|
|
|
+// String stream_key = APPLICATION_NAME + ":" + QUEUE_KEY;
|
|
|
+// List<MapRecord<String, String, String>> task_list = taskService.getTaskPaddingList(stream_key);
|
|
|
+// return Result.success().put("data", task_list);
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|