Skip to main content

Task

Trait Task 

Source
pub trait Task: Send + Sync {
    // Required method
    fn handle<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = TaskResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for defining scheduled tasks

Implement this trait on a struct to create a reusable scheduled task. Schedule configuration is done via the fluent builder API when registering.

§Example

use ferro_rs::{Task, TaskResult};
use async_trait::async_trait;

pub struct CleanupLogsTask;

impl CleanupLogsTask {
    pub fn new() -> Self {
        Self
    }
}

#[async_trait]
impl Task for CleanupLogsTask {
    async fn handle(&self) -> TaskResult {
        // Cleanup logic here
        println!("Cleaning up old log files...");
        Ok(())
    }
}

// Register in schedule.rs with fluent API:
// schedule.add(
//     schedule.task(CleanupLogsTask::new())
//         .daily()
//         .at("03:00")
//         .name("cleanup:logs")
// );

Required Methods§

Source

fn handle<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = TaskResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the task

Implementors§