pub trait TaskStorage: Send + Sync {
// Required methods
fn save_task_log<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
task_type: i16,
priority: i16,
config: &'life2 TaskConfig,
params: &'life3 SubmitTaskParams,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn save_task_queue<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
topic: &'life2 str,
priority: i16,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn update_task_status<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
status: TaskStatus,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_retry_count<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn update_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
retry_count: i64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn save_task_result<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
output: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn log_execution<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
status: TaskStatus,
error: Option<&'life2 str>,
elapsed_ms: i64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn scan_retryable_tasks<'life0, 'life1, 'async_trait>(
&'life0 self,
task_types: &'life1 [i16],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<RetryableTask>, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
任务持久化接口
业务方实现此 trait,定义任务数据的存储方式。
所有方法均返回 Result<(), String>,失败原因通过 Err(String) 传递。
Required Methods§
Sourcefn save_task_log<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
task_type: i16,
priority: i16,
config: &'life2 TaskConfig,
params: &'life3 SubmitTaskParams,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn save_task_log<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
task_type: i16,
priority: i16,
config: &'life2 TaskConfig,
params: &'life3 SubmitTaskParams,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
持久化任务日志(提交任务时调用)
接收完整的任务提交参数与配置,由实现方决定如何存储(表名、字段映射)。
Sourcefn save_task_queue<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
topic: &'life2 str,
priority: i16,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn save_task_queue<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
topic: &'life2 str,
priority: i16,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
持久化任务队列记录(提交任务时调用)
记录任务已入队,供外部查询队列状态。
Sourcefn update_task_status<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
status: TaskStatus,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update_task_status<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
status: TaskStatus,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
更新任务状态
状态变更时机:提交后 Pending → Worker 拾取 Processing → 成功 Completed / 失败 Failed / DLQ DeadLetter
Sourcefn get_retry_count<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_retry_count<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
获取当前重试次数
Sourcefn update_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
retry_count: i64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update_retry<'life0, 'life1, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
retry_count: i64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
更新重试信息
失败后递增 retry_count,同时将状态重置为 Pending 等待 RetryScanner 重新推送。
Sourcefn save_task_result<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
output: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn save_task_result<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
output: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
保存任务执行结果(成功或失败后的输出)
Sourcefn log_execution<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
status: TaskStatus,
error: Option<&'life2 str>,
elapsed_ms: i64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn log_execution<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
task_id: &'life1 str,
status: TaskStatus,
error: Option<&'life2 str>,
elapsed_ms: i64,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
记录执行日志
每次执行(含重试)都记录一条,供审计和排障。
Sourcefn scan_retryable_tasks<'life0, 'life1, 'async_trait>(
&'life0 self,
task_types: &'life1 [i16],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<RetryableTask>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn scan_retryable_tasks<'life0, 'life1, 'async_trait>(
&'life0 self,
task_types: &'life1 [i16],
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<RetryableTask>, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
扫描需要重试的任务
返回当前所有 status=Failed 且 retry_count < max_retries 的任务。 RetryScanner 定期调用此方法获取待重试列表。