pub trait TaskExecutor: Send + Sync {
// Required methods
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
job: &'life1 NewScheduledJob,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<ExecutionResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn cancel<'life0, 'life1, 'async_trait>(
&'life0 self,
job_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn name(&self) -> &str;
}Expand description
任务执行器 trait
定义任务执行的标准接口,支持不同的执行策略(主会话、隔离会话等)。
§需求映射
- Requirement 7.7: 任务执行器 trait 定义
§实现者
MainSessionExecutor: 在主会话中执行任务IsolatedSessionExecutor: 在隔离会话中执行任务
§示例
ⓘ
use aster::scheduler::executor::{TaskExecutor, ExecutionResult, ExecutionContext};
struct MyExecutor;
#[async_trait]
impl TaskExecutor for MyExecutor {
async fn execute(
&self,
job: &ScheduledJob,
ctx: &ExecutionContext,
) -> Result<ExecutionResult> {
// 执行任务逻辑
Ok(ExecutionResult::success("session-id", None, 100))
}
async fn cancel(&self, job_id: &str) -> Result<()> {
// 取消任务逻辑
Ok(())
}
}