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§
sourcefn run<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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.
sourcefn get_config(&self) -> &JobConfig
fn get_config(&self) -> &JobConfig
Exposes the configuration of the job