pub trait Task:
Send
+ Sync
+ 'static {
type Params: Serialize + DeserializeOwned + Send + Sync + 'static;
type Result: Serialize + DeserializeOwned + Send + Sync + 'static;
// Required methods
fn task_id(&self) -> &TaskId;
fn config(&self) -> &TaskConfig;
fn run(&self, params: Self::Params) -> RustvelloResult<Self::Result>;
}Expand description
A distributable task with typed parameters and results.
This is the Rust equivalent of pynenc’s Task class. Each task
definition implements this trait, providing:
- A unique identity (
TaskId) - Configuration (retries, concurrency, etc.)
- Typed execution (
Params→Resultvia serde)
Tasks are typically created via the #[rustvello::task] proc-macro, but
can also be implemented manually for testing or advanced use cases.
§Example (manual implementation)
use rustvello_core::task::Task;
use rustvello_proto::config::TaskConfig;
use rustvello_proto::identifiers::TaskId;
use rustvello_core::error::RustvelloResult;
struct AddTask {
task_id: TaskId,
config: TaskConfig,
}
impl Task for AddTask {
type Params = (i32, i32);
type Result = i32;
fn task_id(&self) -> &TaskId {
&self.task_id
}
fn config(&self) -> &TaskConfig {
&self.config
}
fn run(&self, params: Self::Params) -> RustvelloResult<Self::Result> {
Ok(params.0 + params.1)
}
}Required Associated Types§
Required Methods§
Sourcefn config(&self) -> &TaskConfig
fn config(&self) -> &TaskConfig
Per-task configuration.
Sourcefn run(&self, params: Self::Params) -> RustvelloResult<Self::Result>
fn run(&self, params: Self::Params) -> RustvelloResult<Self::Result>
Execute the task with the given parameters.