Trait woddle::Job

source ·
pub trait Job: JobClone {
    // Required methods
    fn run<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: '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§

source

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

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.

source

fn get_config(&self) -> &JobConfig

Exposes the configuration of the job

Trait Implementations§

source§

impl Clone for Box<dyn Job>

source§

fn clone(&self) -> Box<dyn Job>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§