#[derive(AutoRegisterTask)]Expand description
Automatically register a task type with the task registry.
This derive macro generates code that uses the inventory pattern to automatically
register task types at runtime. The task will be registered using the name returned
by its name() method.
This macro uses the inventory pattern to automatically register task types at runtime.
ยงExample
#[derive(Debug, Serialize, Deserialize, AutoRegisterTask)]
struct MyTask {
data: String,
}
#[async_trait]
impl Task for MyTask {
async fn execute(&self) -> Result<Vec<u8>, Box<dyn std::error::Error + Send + Sync>> {
// task implementation
use serde::Serialize;
#[derive(Serialize)]
struct Response { status: String }
let response = Response { status: "completed".to_string() };
Ok(rmp_serde::to_vec(&response)?)
}
fn name(&self) -> &str {
"my_task"
}
}