[][src]Trait woddle::Job

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

A trait for implementing a woddle job

Example implementation:

This example is not tested
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

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

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.

pub fn get_config(&self) -> &JobConfig[src]

Exposes the configuration of the job

Loading content...

Implementors

Loading content...