#[task_handler]Expand description
标记 TaskHandler 实现,编译期自动注册到 TASK_HANDLERS 分布式切片
配合 HandlerRegistry::from_discovered() 在运行时批量注册。
§参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
task_type | i16 | 必填 | 任务类型标识,唯一 |
topic | &str | “task_{task_type}” | Kafka topic |
priority | Normal/High/Low/Critical | Normal | 优先级 |
timeout_seconds | u64 | 300 | 超时秒数 |
max_retries | u32 | 3 | 最大重试次数 |
description | &str | “” | 任务描述 |
dead_letter_topic | Option<&str> | None | 死信队列 topic |
§示例
ⓘ
#[task_handler(task_type = 1, topic = "export", timeout_seconds = 60)]
struct ExportHandler;
#[async_trait]
impl TaskHandler for ExportHandler {
fn task_type(&self) -> i16 { 1 }
async fn execute(&self, payload: Value) -> Result<Value, String> {
Ok(json!({"file": "https://..."}))
}
}