-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: task for running in backend (#629)
* feat: display task page in console. * feat: 给插件暴露提交任务和返回任务的内部接口 * docs: update CHANGELOG.MD
- Loading branch information
ChiveHao
committed
Jul 19, 2024
1 parent
474178b
commit 465f404
Showing
11 changed files
with
126 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
- 默认主题的js问题修复 | ||
- 默认主题的条目详情页添加URL选择的剧集参数 | ||
- 默认主题的条目详情页播放逻辑 | ||
- 后台任务相关接口优化 | ||
|
||
## 依赖 | ||
|
||
|
10 changes: 10 additions & 0 deletions
10
api/src/main/java/run/ikaros/api/core/task/TaskOperate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package run.ikaros.api.core.task; | ||
|
||
import reactor.core.publisher.Mono; | ||
import run.ikaros.api.plugin.AllowPluginOperate; | ||
|
||
public interface TaskOperate extends AllowPluginOperate { | ||
Mono<Void> submit(String name, Runnable runnable); | ||
|
||
Mono<Void> cancel(String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
server/src/main/java/run/ikaros/server/core/task/PluginTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package run.ikaros.server.core.task; | ||
|
||
import run.ikaros.server.store.entity.TaskEntity; | ||
import run.ikaros.server.store.repository.TaskRepository; | ||
|
||
public class PluginTask extends Task { | ||
public PluginTask(TaskEntity entity, | ||
TaskRepository repository) { | ||
super(entity, repository); | ||
} | ||
|
||
@Override | ||
protected String getTaskEntityName() { | ||
return this.getClass().getName() + "-"; | ||
} | ||
|
||
@Override | ||
protected void doRun() throws Exception { | ||
|
||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
server/src/main/java/run/ikaros/server/core/task/TaskOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package run.ikaros.server.core.task; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.Assert; | ||
import reactor.core.publisher.Mono; | ||
import run.ikaros.api.core.task.TaskOperate; | ||
import run.ikaros.server.store.entity.TaskEntity; | ||
import run.ikaros.server.store.repository.TaskRepository; | ||
|
||
@Slf4j | ||
@Component | ||
public class TaskOperator implements TaskOperate { | ||
private final TaskService taskService; | ||
private final TaskRepository taskRepository; | ||
|
||
public TaskOperator(TaskService taskService, | ||
TaskRepository taskRepository) { | ||
this.taskService = taskService; | ||
this.taskRepository = taskRepository; | ||
} | ||
|
||
@Override | ||
public Mono<Void> submit(String name, Runnable runnable) { | ||
Assert.hasText(name, "name must not be empty"); | ||
Assert.notNull(runnable, "runnable must not be null"); | ||
|
||
TaskEntity taskEntity = new TaskEntity(); | ||
taskEntity.setName(name); | ||
taskService.setDefaultFieldValue(taskEntity); | ||
|
||
PluginTask pluginTask = new PluginTask(taskEntity, taskRepository) { | ||
@Override | ||
protected String getTaskEntityName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
protected void doRun() throws Exception { | ||
runnable.run(); | ||
} | ||
}; | ||
|
||
return taskService.submit(pluginTask); | ||
} | ||
|
||
@Override | ||
public Mono<Void> cancel(String name) { | ||
Assert.hasText(name, "name must not be empty"); | ||
return taskService.cancel(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters