TaskStatus.java
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.aigeo.common.enums;
import lombok.Getter;
/**
* 任务状态枚举
* 对应数据库字段:
* - ai_article_generation_tasks.status
* - ai_topic_fetch_tasks.status
* - ai_scheduled_publishing_tasks.status
* - ai_landing_page_generation_tasks.status
* - ai_website_generation_tasks.status
*
* @author AIGEO Team
* @since 1.0.0
*/
@Getter
public enum TaskStatus {
/**
* 等待处理 - 任务已创建,等待系统调度执行
*/
PENDING("pending", "等待处理"),
/**
* 正在处理 - 任务正在执行中,可能需要较长时间
*/
PROCESSING("processing", "正在处理"),
/**
* 已暂停 - 任务执行被暂停,可以恢复执行
*/
PAUSED("paused", "已暂停"),
/**
* 已完成 - 任务成功执行完成
*/
COMPLETED("completed", "已完成"),
/**
* 执行失败 - 任务执行过程中出现错误
*/
FAILED("failed", "执行失败"),
/**
* 已取消 - 用户主动取消或系统自动取消
*/
CANCELLED("cancelled", "已取消");
/**
* 数据库存储值
*/
private final String code;
/**
* 显示名称
*/
private final String displayName;
TaskStatus(String code, String displayName) {
this.code = code;
this.displayName = displayName;
}
/**
* 根据代码获取枚举
*/
public static TaskStatus fromCode(String code) {
for (TaskStatus status : values()) {
if (status.code.equals(code)) {
return status;
}
}
throw new IllegalArgumentException("未知的任务状态代码: " + code);
}
/**
* 检查是否为最终状态(不会再改变)
*/
public boolean isFinalStatus() {
return this == COMPLETED || this == FAILED || this == CANCELLED;
}
/**
* 检查是否为运行中状态
*/
public boolean isRunning() {
return this == PROCESSING;
}
/**
* 检查是否可以取消
*/
public boolean isCancellable() {
return this == PENDING || this == PROCESSING || this == PAUSED;
}
/**
* 检查是否可以暂停
*/
public boolean isPausable() {
return this == PROCESSING;
}
/**
* 检查是否可以恢复
*/
public boolean isResumable() {
return this == PAUSED;
}
}