Skip to main content

Task

Trait Task 

Source
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 (ParamsResult via 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§

Source

type Params: Serialize + DeserializeOwned + Send + Sync + 'static

The input parameters type (must be serializable).

Source

type Result: Serialize + DeserializeOwned + Send + Sync + 'static

The return type (must be serializable).

Required Methods§

Source

fn task_id(&self) -> &TaskId

Unique identifier for this task.

Source

fn config(&self) -> &TaskConfig

Per-task configuration.

Source

fn run(&self, params: Self::Params) -> RustvelloResult<Self::Result>

Execute the task with the given parameters.

Implementors§