Trait woddle::Job[][src]

pub trait Job: JobClone {
    fn run<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
;
fn get_config(&self) -> &JobConfig; }
Expand description

A trait for implementing a woddle job

Example implementation:

use std::time::Duration;
use crate::{JobConfig, Job, async_trait};

#[derive(Clone)]
struct MyJob {
    config: JobConfig,
}

#[async_trait]
impl Job for MyJob {
    async fn run(&self) {
        log::info!("running my job!");
    }

    fn get_config(&self) -> &JobConfig {
        &self.config
    }
}

fn main() {
    let job_cfg = JobConfig::new("my_job", "someSyncKey").interval(Duration::from_secs(5));
    let my_job = MyJob {
        config: job_cfg,
    };
}

Required methods

Runs the job

This is an async function, so if you plan to do long-running, blocking operations, you should spawn them on Tokio’s Blocking Threadpool.

You need the blocking feature to be active, for this to work.

Otherwise, you might block the scheduler threads, slowing down your whole application.

Exposes the configuration of the job

Implementors